summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2020-02-16 11:59:33 -0500
committerJiayi Zhao <jeff.no.zhao@gmail.com>2020-02-16 12:01:23 -0500
commitd788f8d740be85bb014ddfa005156723f0a31e99 (patch)
tree1cd74c86358b70f78dffe25da5e0bfe4bd9b1abf
parent726a7a424f7ddec97478490a0f3a25005dde45ac (diff)
rework rendering system to use tui-rs widgets
- move files around - delete some old ncurses code - integrate tui-rs styles and colors
-rw-r--r--Cargo.toml1
-rw-r--r--src/commands/change_directory.rs3
-rw-r--r--src/commands/command_line.rs2
-rw-r--r--src/commands/mod.rs2
-rw-r--r--src/commands/open_file.rs5
-rw-r--r--src/commands/reload_dir.rs13
-rw-r--r--src/commands/set_mode.rs2
-rw-r--r--src/fs/entry.rs20
-rw-r--r--src/run.rs59
-rw-r--r--src/ui/mod.rs1
-rw-r--r--src/ui/tui_backend.rs63
-rw-r--r--src/ui/widgets/mod.rs3
-rw-r--r--src/ui/widgets/tui_dirlist.rs124
-rw-r--r--src/util/load_child.rs (renamed from src/commands/load_child.rs)1
-rw-r--r--src/util/menu.rs17
-rw-r--r--src/util/mod.rs1
-rw-r--r--src/window/mod.rs2
-rw-r--r--src/window/view.rs83
18 files changed, 207 insertions, 195 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 8cfa432..8c4addf 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -20,7 +20,6 @@ rustyline = "^4"
serde = "^1"
serde_derive = "^1"
structopt = "^0"
-text_io = "^0"
termion = "*"
toml = "^0"
tui = "^0"
diff --git a/src/commands/change_directory.rs b/src/commands/change_directory.rs
index cd761c9..5f30c36 100644
--- a/src/commands/change_directory.rs
+++ b/src/commands/change_directory.rs
@@ -1,10 +1,11 @@
use std::path;
-use crate::commands::{JoshutoCommand, JoshutoRunnable, LoadChild};
+use crate::commands::{JoshutoCommand, JoshutoRunnable};
use crate::context::JoshutoContext;
use crate::error::JoshutoResult;
use crate::history::DirectoryHistory;
use crate::ui::TuiBackend;
+use crate::util::load_child::LoadChild;
#[derive(Clone, Debug)]
pub struct ChangeDirectory {
diff --git a/src/commands/command_line.rs b/src/commands/command_line.rs
index ff3c694..1ca2c14 100644
--- a/src/commands/command_line.rs
+++ b/src/commands/command_line.rs
@@ -1,8 +1,8 @@
use crate::commands::{self, JoshutoCommand, JoshutoRunnable};
use crate::context::JoshutoContext;
use crate::error::JoshutoResult;
-use crate::util::textfield::TextField;
use crate::ui::TuiBackend;
+use crate::util::textfield::TextField;
#[derive(Clone, Debug)]
pub struct CommandLine {
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index 0c395e6..724b5ad 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -4,7 +4,6 @@ mod command_line;
mod cursor_move;
mod delete_files;
mod file_ops;
-mod load_child;
mod new_directory;
mod open_file;
mod parent_directory;
@@ -27,7 +26,6 @@ pub use self::cursor_move::{
};
pub use self::delete_files::DeleteFiles;
pub use self::file_ops::{CopyFiles, CutFiles, PasteFiles};
-pub use self::load_child::LoadChild;
pub use self::new_directory::NewDirectory;
pub use self::open_file::OpenFile; //, OpenFileWith};
pub use self::parent_directory::ParentDirectory;
diff --git a/src/commands/open_file.rs b/src/commands/open_file.rs
index b1b46d1..501eb67 100644
--- a/src/commands/open_file.rs
+++ b/src/commands/open_file.rs
@@ -1,12 +1,13 @@
use std::path::{Path, PathBuf};
-use crate::commands::{ChangeDirectory, JoshutoCommand, JoshutoRunnable, LoadChild};
+use crate::commands::{ChangeDirectory, JoshutoCommand, JoshutoRunnable};
use crate::config::mimetype::JoshutoMimetypeEntry;
use crate::context::JoshutoContext;
use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult};
use crate::history::DirectoryHistory;
-use crate::util::textfield::TextField;
use crate::ui::TuiBackend;
+use crate::util::load_child::LoadChild;
+use crate::util::textfield::TextField;
use crate::MIMETYPE_T;
diff --git a/src/commands/reload_dir.rs b/src/commands/reload_dir.rs
index d1d6f5f..20d415b 100644
--- a/src/commands/reload_dir.rs
+++ b/src/commands/reload_dir.rs
@@ -22,19 +22,6 @@ impl ReloadDirList {
let sort_option = &context.config_t.sort_option;
curr_tab.curr_list.reload_contents(sort_option)?;
- if let Some(parent) = curr_tab.curr_list.file_path().parent() {
- match curr_tab.history.entry(parent.to_path_buf().clone()) {
- Entry::Occupied(mut entry) => {
- let dirlist = entry.get_mut();
- dirlist.reload_contents(sort_option)?;
- }
- Entry::Vacant(entry) => {
- let mut s = JoshutoDirList::new(parent.to_path_buf().clone(), &sort_option)?;
- s.sort(sort_option.compare_func());
- entry.insert(s);
- }
- }
- }
Ok(())
}
}
diff --git a/src/commands/set_mode.rs b/src/commands/set_mode.rs
index a84cc80..6a5896f 100644
--- a/src/commands/set_mode.rs
+++ b/src/commands/set_mode.rs
@@ -2,9 +2,9 @@ use crate::commands::{CursorMoveDown, JoshutoCommand, JoshutoRunnable};
use crate::context::JoshutoContext;
use crate::error::JoshutoResult;
use crate::fs::JoshutoDirEntry;
-use crate::util::textfield::TextField;
use crate::ui::TuiBackend;
use crate::unix;
+use crate::util::textfield::TextField;
#[derive(Clone, Debug)]
pub struct SetMode;
diff --git a/src/fs/entry.rs b/src/fs/entry.rs
index 4cf3ead..36788cf 100644
--- a/src/fs/entry.rs
+++ b/src/fs/entry.rs
@@ -1,5 +1,8 @@
use std::{fs, path};
+use tui::style::{Color, Style};
+use tui::widgets::Text;
+
use crate::fs::JoshutoMetadata;
#[derive(Clone, Debug)]
@@ -60,6 +63,23 @@ impl JoshutoDirEntry {
pub fn set_selected(&mut self, selected: bool) {
self.selected = selected;
}
+
+ pub fn get_fg_color(&self) -> Color {
+ let metadata = &self.metadata;
+ let filetype = metadata.file_type;
+
+ if filetype.is_dir() {
+ Color::LightBlue
+ } else if filetype.is_symlink() {
+ Color::Cyan
+ } else {
+ Color::White
+ }
+ }
+
+ pub fn get_bg_color(&self) -> Color {
+ Color::Reset
+ }
}
impl std::fmt::Display for JoshutoDirEntry {
diff --git a/src/run.rs b/src/run.rs
index 4ccb492..54656a2 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -9,13 +9,11 @@ use crate::tab::JoshutoTab;
use crate::ui;
use crate::util::event::{Event, Events};
use crate::util::menu::OptionMenu;
-use crate::window::JoshutoPanel;
-use crate::window::JoshutoView;
fn recurse_get_keycommand<'a>(
events: &Events,
keymap: &'a JoshutoCommandMapping,
- backend: &'a mut ui::TuiBackend
+ backend: &'a mut ui::TuiBackend,
) -> Option<&'a dyn JoshutoCommand> {
let event = {
let mut menu = OptionMenu::new(backend, events);
@@ -27,10 +25,7 @@ fn recurse_get_keycommand<'a>(
.map(|(k, v)| format!(" {:?}\t{}", k, v))
.collect();
display_vec.sort();
- let display_str: Vec<&str> = display_vec
- .iter()
- .map(|v| v.as_str())
- .collect();
+ let display_str: Vec<&str> = display_vec.iter().map(|v| v.as_str()).collect();
let result = menu.get_option(&display_str);
eprintln!("{:?}", result);
@@ -42,7 +37,9 @@ fn recurse_get_keycommand<'a>(
Ok(Event::Input(input)) => match input {
Key::Esc => None,
key @ Key::Char(_) => match keymap.get(&key) {
- Some(CommandKeybind::CompositeKeybind(m)) => recurse_get_keycommand(events, &m, backend),
+ Some(CommandKeybind::CompositeKeybind(m)) => {
+ recurse_get_keycommand(events, &m, backend)
+ }
Some(CommandKeybind::SimpleKeybind(s)) => Some(s.as_ref()),
_ => None,
},
@@ -57,7 +54,6 @@ pub fn run(config_t: JoshutoConfig, keymap_t: JoshutoCommandMapping) {
let mut backend: ui::TuiBackend = ui::TuiBackend::new().unwrap();
let mut context = JoshutoContext::new(config_t);
- let mut view = JoshutoView::new(context.config_t.column_ratio);
match std::env::current_dir() {
Ok(curr_path) => match JoshutoTab::new(curr_path, &context.config_t.sort_option) {
Ok(s) => context.push_tab(s),
@@ -105,13 +101,13 @@ pub fn run(config_t: JoshutoConfig, keymap_t: JoshutoCommandMapping) {
Ok(event) => {
match event {
Event::IOWorkerProgress(p) => {
- ui::wprint_err(&view.bot_win, &format!("bytes copied {}", p));
+ eprintln!("{}", &format!("bytes copied {}", p));
}
Event::IOWorkerResult => {
match io_handle {
Some(handle) => {
handle.join();
- ui::wprint_err(&view.bot_win, "io_worker done");
+ eprintln!("io_worker done");
}
None => {}
}
@@ -123,7 +119,7 @@ pub fn run(config_t: JoshutoConfig, keymap_t: JoshutoCommandMapping) {
}
Some(CommandKeybind::SimpleKeybind(command)) => {
if let Err(e) = command.execute(&mut context, &mut backend) {
- ui::wprint_err(&view.bot_win, e.cause());
+ eprintln!("{}", e.cause());
}
}
Some(CommandKeybind::CompositeKeybind(m)) => {
@@ -131,7 +127,6 @@ pub fn run(config_t: JoshutoConfig, keymap_t: JoshutoCommandMapping) {
let mut map: &JoshutoCommandMapping = &m;
loop {
- eprintln!("run loop");
let event2 = {
let mut menu = OptionMenu::new(&mut backend, &context.events);
@@ -141,44 +136,34 @@ pub fn run(config_t: JoshutoConfig, keymap_t: JoshutoCommandMapping) {
.map(|(k, v)| format!(" {:?}\t{}", k, v))
.collect();
display_vec.sort();
- let display_str: Vec<&str> = display_vec
- .iter()
- .map(|v| v.as_str())
- .collect();
+ let display_str: Vec<&str> =
+ display_vec.iter().map(|v| v.as_str()).collect();
let result = menu.get_option(&display_str);
- eprintln!("{:?}", result);
-
result
};
match event2 {
- Some(key) => {
- match key {
- Key::Esc => {
+ None => break,
+ Some(key) => match key {
+ Key::Char(_) => match map.get(&key) {
+ Some(CommandKeybind::CompositeKeybind(m)) => map = &m,
+ Some(CommandKeybind::SimpleKeybind(s)) => {
+ cmd = Some(s.as_ref());
break;
}
- Key::Char(_) => match map.get(&key) {
- Some(CommandKeybind::CompositeKeybind(m)) => map = &m,
- Some(CommandKeybind::SimpleKeybind(s)) => {
- cmd = Some(s.as_ref());
- break;
- }
- None => break,
- },
- _ => {},
- }
- }
- _ => {}
+ None => break,
+ },
+ _ => {}
+ },
}
}
- eprintln!("cmd: {:#?}", cmd);
if let Some(command) = cmd {
if let Err(e) = command.execute(&mut context, &mut backend) {
- ui::wprint_err(&view.bot_win, e.cause());
+ eprintln!("{}", e.cause());
}
}
}
- }
+ },
}
backend.render(&context);
}
diff --git a/src/ui/mod.rs b/src/ui/mod.rs
index 574bc46..e250d20 100644
--- a/src/ui/mod.rs
+++ b/src/ui/mod.rs
@@ -1,5 +1,6 @@
mod ncurses_backend;
mod tui_backend;
+pub mod widgets;
pub use ncurses_backend::*;
pub use tui_backend::*;
diff --git a/src/ui/tui_backend.rs b/src/ui/tui_backend.rs
index d59c619..b5afced 100644
--- a/src/ui/tui_backend.rs
+++ b/src/ui/tui_backend.rs
@@ -1,3 +1,6 @@
+use std::io::{self, Write};
+
+use termion::clear;
use termion::cursor::Goto;
use termion::event::Key;
use termion::input::TermRead;
@@ -9,6 +12,7 @@ use tui::style::{Color, Style};
use tui::widgets::{Block, Borders, List, Paragraph, SelectableList, Text, Widget};
use unicode_width::UnicodeWidthStr;
+use super::widgets::TuiDirList;
use crate::context::JoshutoContext;
// use crate::fs::JoshutoDirList;
@@ -22,6 +26,7 @@ impl TuiBackend {
let stdout = AlternateScreen::from(stdout);
let backend = TermionBackend::new(stdout);
let mut terminal = tui::Terminal::new(backend)?;
+ terminal.hide_cursor()?;
Ok(Self { terminal })
}
@@ -32,8 +37,13 @@ impl TuiBackend {
let parent_list = curr_tab.parent_list_ref();
let child_list = curr_tab.child_list_ref();
- self.terminal.draw(|mut f| {
- let f_size = f.size();
+ let f_size = {
+ let frame = self.terminal.get_frame();
+ frame.size()
+ };
+
+ self.terminal.draw(|mut frame| {
+ let f_size = frame.size();
let constraints = match child_list {
Some(_) => [
@@ -49,56 +59,21 @@ impl TuiBackend {
};
let layout_rect = Layout::default()
.direction(Direction::Horizontal)
+ .margin(1)
.constraints(constraints.as_ref())
.split(f_size);
if let Some(curr_list) = parent_list.as_ref() {
- let list_name = "parent_list";
- let list_style = Style::default().fg(tui::style::Color::LightBlue);
- let selected_style = Style::default()
- .fg(tui::style::Color::LightBlue)
- .modifier(tui::style::Modifier::REVERSED);
-
- SelectableList::default()
- .block(Block::default().borders(Borders::ALL).title(list_name))
- .items(&curr_list.contents)
- .style(list_style)
- .highlight_style(selected_style)
- .select(curr_list.index)
- .render(&mut f, layout_rect[0]);
- }
+ TuiDirList::new(&curr_list).render(&mut frame, layout_rect[0]);
+ };
if let Some(curr_list) = curr_list.as_ref() {
- let list_name = "curr_list";
- let list_style = Style::default().fg(tui::style::Color::LightBlue);
- let selected_style = Style::default()
- .fg(tui::style::Color::LightBlue)
- .modifier(tui::style::Modifier::REVERSED);
-
- SelectableList::default()
- .block(Block::default().borders(Borders::ALL).title(list_name))
- .items(&curr_list.contents)
- .style(list_style)
- .highlight_style(selected_style)
- .select(curr_list.index)
- .render(&mut f, layout_rect[1]);
- }
+ TuiDirList::new(&curr_list).render(&mut frame, layout_rect[1]);
+ };
if let Some(curr_list) = child_list.as_ref() {
- let list_name = "child_list";
- let list_style = Style::default().fg(tui::style::Color::LightBlue);
- let selected_style = Style::default()
- .fg(tui::style::Color::LightBlue)
- .modifier(tui::style::Modifier::REVERSED);
-
- SelectableList::default()
- .block(Block::default().borders(Borders::ALL).title(list_name))
- .items(&curr_list.contents)
- .style(list_style)
- .highlight_style(selected_style)
- .select(curr_list.index)
- .render(&mut f, layout_rect[2]);
- }
+ TuiDirList::new(&curr_list).render(&mut frame, layout_rect[2]);
+ };
});
}
}
diff --git a/src/ui/widgets/mod.rs b/src/ui/widgets/mod.rs
new file mode 100644
index 0000000..9ace2b7
--- /dev/null
+++ b/src/ui/widgets/mod.rs
@@ -0,0 +1,3 @@
+pub mod tui_dirlist;
+
+pub use self::tui_dirlist::TuiDirList;
diff --git a/src/ui/widgets/tui_dirlist.rs b/src/ui/widgets/tui_dirlist.rs
new file mode 100644
index 0000000..e2ba9a6
--- /dev/null
+++ b/src/ui/widgets/tui_dirlist.rs
@@ -0,0 +1,124 @@
+use std::io::{self, Write};
+
+use tui::buffer::Buffer;
+use tui::layout::Rect;
+use tui::style::{Modifier, Style};
+use tui::widgets::{Block, Text, Widget};
+
+use crate::fs::JoshutoDirList;
+/*
+pub struct TermionWindow<'a> {
+ rect: Rect,
+ dirlist: &'a JoshutoDirList,
+}
+
+impl<'a> TermionWindow<'a> {
+ pub fn new(rect: &Rect, dirlist: &'a JoshutoDirList) -> Self {
+ Self {
+ rect: rect.clone(),
+ dirlist
+ }
+ }
+
+ pub fn update_rect(&mut self, rect: &Rect) {
+ self.rect = rect.clone();
+ }
+
+ pub fn clear<W: Write>(&self, terminal: &mut W) {
+ for i in 1..self.rect.height + 1 {
+ write!(terminal, "{}{}", Goto(self.rect.width, i as u16), clear::BeforeCursor);
+ }
+ }
+
+ pub fn draw<W: Write>(&self, terminal: &mut W) {
+ if self.rect.height < 4 {
+ return;
+ }
+ let dir_len = self.dirlist.contents.len();
+ if dir_len == 0 {
+ write!(terminal, "{}EMPTY", Goto(self.rect.x, self.rect.y));
+ return;
+ }
+
+ let curr_index = self.dirlist.index.unwrap();
+
+ let height = self.rect.height as usize;
+
+ for (i, entry) in self.dirlist.contents.iter().enumerate() {
+ let goto_i = i + 1;
+ if goto_i > height {
+ break;
+ }
+ let fg = entry.get_fg_color();
+ let bg = entry.get_bg_color();
+ let file_ansi_text = entry.as_ansi_text();
+
+ if i == curr_index {
+ write!(terminal, "{}{}{}{}{}",
+ Goto(self.rect.x, goto_i as u16),
+ style::Invert,
+ bg.bg_str(),
+ fg.fg_str(),
+ file_ansi_text);
+ } else {
+ write!(terminal, "{}{}{}{}{}",
+ Goto(self.rect.x, goto_i as u16),
+ style::Reset,
+ bg.bg_str(),
+ fg.fg_str(),
+ file_ansi_text);
+ }
+ }
+ }
+}
+*/
+pub struct TuiDirList<'a> {
+ dirlist: &'a JoshutoDirList,
+}
+
+impl<'a> TuiDirList<'a> {
+ pub fn new(dirlist: &'a JoshutoDirList) -> Self {
+ Self { dirlist }
+ }
+}
+
+impl<'a> Widget for TuiDirList<'a> {
+ fn draw(&mut self, area: Rect, buf: &mut Buffer) {
+ if area.width < 1 || area.height < 1 {
+ return;
+ }
+
+ if area.width < 4 {
+ return;
+ }
+
+ let x = area.left();
+ let y = area.top();
+
+ let dir_len = self.dirlist.contents.len();
+ if dir_len == 0 {
+ buf.set_stringn(x, y, "empty", area.width as usize, Style::default());
+ return;
+ }
+
+ let curr_index = self.dirlist.index.unwrap();
+ for (i, entry) in self
+ .dirlist
+ .contents
+ .iter()
+ .enumerate()
+ .take(area.height as usize)
+ {
+ let fg = entry.get_fg_color();
+ let bg = entry.get_bg_color();
+ let name = entry.file_name();
+
+ let mut style = Style::default().fg(fg).bg(bg);
+
+ if i == curr_index {
+ style = style.modifier(Modifier::REVERSED);
+ }
+ buf.set_stringn(x, y + i as u16, name, area.width as usize, style);
+ }
+ }
+}
diff --git a/src/commands/load_child.rs b/src/util/load_child.rs
index 693e339..cb32090 100644
--- a/src/commands/load_child.rs
+++ b/src/util/load_child.rs
@@ -1,7 +1,6 @@
use std::path::PathBuf;
use crate::context::JoshutoContext;
-use crate::error::JoshutoResult;
use crate::history::DirectoryHistory;
use crate::ui::TuiBackend;
diff --git a/src/util/menu.rs b/src/util/menu.rs
index a1be30a..67cb19d 100644
--- a/src/util/menu.rs
+++ b/src/util/menu.rs
@@ -19,12 +19,11 @@ use crate::util::event::{Event, Events};
pub struct OptionMenu<'a> {
backend: &'a mut TuiBackend,
- events: &'a Events
+ events: &'a Events,
}
impl<'a> OptionMenu<'a> {
- pub fn new(backend: &'a mut TuiBackend,
- events: &'a Events) -> Self {
+ pub fn new(backend: &'a mut TuiBackend, events: &'a Events) -> Self {
Self { backend, events }
}
@@ -46,13 +45,17 @@ impl<'a> OptionMenu<'a> {
write!(termion_terminal, "{}", Goto(1, txt_y));
for (i, option) in options.iter().enumerate() {
- write!(termion_terminal, "{}{}{}",
- option, Goto(1, txt_y + i as u16), clear::AfterCursor);
+ write!(
+ termion_terminal,
+ "{}{}{}",
+ option,
+ Goto(1, txt_y + i as u16),
+ clear::AfterCursor
+ );
}
io::stdout().flush().ok();
loop {
- eprintln!("menu loop");
let event = events.next();
if let Ok(event) = event {
match event {
@@ -60,7 +63,7 @@ impl<'a> OptionMenu<'a> {
Key::Esc => return None,
key => return Some(key),
},
- _ => {},
+ _ => {}
}
}
}
diff --git a/src/util/mod.rs b/src/util/mod.rs
index 492c42f..34b8eb4 100644
--- a/src/util/mod.rs
+++ b/src/util/mod.rs
@@ -1,4 +1,5 @@
pub mod event;
pub mod key_mapping;
+pub mod load_child;
pub mod menu;
pub mod textfield;
diff --git a/src/window/mod.rs b/src/window/mod.rs
index dcffe17..d969a83 100644
--- a/src/window/mod.rs
+++ b/src/window/mod.rs
@@ -1,7 +1,5 @@
pub mod page_state;
pub mod panel;
-pub mod view;
pub use self::page_state::JoshutoPageState;
pub use self::panel::JoshutoPanel;
-pub use self::view::JoshutoView;
diff --git a/src/window/view.rs b/src/window/view.rs
deleted file mode 100644
index 947837c..0000000
--- a/src/window/view.rs
+++ /dev/null
@@ -1,83 +0,0 @@
-use crate::ui;
-use crate::window::JoshutoPanel;
-
-#[derive(Debug)]
-pub struct JoshutoView {
- pub top_win: JoshutoPanel,
- pub tab_win: JoshutoPanel,
- pub left_win: JoshutoPanel,
- pub mid_win: JoshutoPanel,
- pub right_win: JoshutoPanel,
- pub bot_win: JoshutoPanel,
- pub win_ratio: (usize, usize, usize),
- pub collapsed: bool,
-}
-
-impl JoshutoView {
- pub fn new(win_ratio: (usize, usize, usize)) -> Self {
- let sum_ratio: usize = win_ratio.0 + win_ratio.1 + win_ratio.2;
-
- let (term_rows, term_cols) = ui::getmaxyx();
- let term_divide: f64 = term_cols as f64 / sum_ratio as f64;
-
- /* window for tabs */
- let win_rows = 1;
- let win_cols = 10;
- let win_coord: (usize, usize) = (0, term_cols as usize - win_cols as usize);
- let tab_win = JoshutoPanel::new(win_rows, win_cols, win_coord);
-
- /* rows, cols */
- let win_rows = 1;
- let win_cols = term_cols - tab_win.cols;
- let win_coord: (usize, usize) = (0, 0);
- let top_win = JoshutoPanel::new(win_rows, win_cols, win_coord);
-
- let offset: i32 = 0;
-
- let win_rows = term_rows - 2;
- let win_cols = (term_divide * win_ratio.0 as f64) as i32 - 1;
- let win_coord: (usize, usize) = (1, offset as usize);
- let left_win = JoshutoPanel::new(win_rows, win_cols, win_coord);
-
- let offset = offset + win_cols + 1;
-
- let win_rows = term_rows - 2;
- let win_cols = (term_divide * win_ratio.1 as f64) as i32 - 1;
- let win_coord: (usize, usize) = (1, offset as usize);
- let mid_win = JoshutoPanel::new(win_rows, win_cols, win_coord);
-
- let offset = offset + win_cols + 1;
-
- let win_rows = term_rows - 2;
- let win_cols = term_cols - offset;
- let win_coord: (usize, usize) = (1, offset as usize);
- let right_win = JoshutoPanel::new(win_rows, win_cols, win_coord);
-
- let win_rows = 1;
- let win_cols = term_cols;
- let win_coord: (usize, usize) = (term_rows as usize - 1, 0);
- let bot_win = JoshutoPanel::new(win_rows, win_cols, win_coord);
-
- JoshutoView {
- top_win,
- tab_win,
- left_win,
- mid_win,
- right_win,
- bot_win,
- win_ratio,
- collapsed: false,
- }
- }
-
- pub fn resize_views(&mut self) {
- let new_view = Self::new(self.win_ratio);
-
- self.top_win = new_view.top_win;
- self.bot_win = new_view.bot_win;
- self.tab_win = new_view.tab_win;
- self.left_win = new_view.left_win;
- self.mid_win = new_view.mid_win;
- self.right_win = new_view.right_win;
- }
-}