diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2020-02-22 12:59:13 -0500 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2020-02-22 13:32:02 -0500 |
commit | 03594099dafb4cda04e50f087df61cf76e2034d0 (patch) | |
tree | 724d31c9b1d31d122d1862141fdc9391891821e4 /src | |
parent | b3ed647b033c079a614e7a9ff5bb88da14dd99b4 (diff) |
move the majority of rendering into its own widget: TuiView
- textfield is now a widget as well
- reduced code duplication with TuiView
- add backtab support
- add a message queue for notifications
Diffstat (limited to 'src')
-rw-r--r-- | src/commands/change_directory.rs | 2 | ||||
-rw-r--r-- | src/commands/command_line.rs | 6 | ||||
-rw-r--r-- | src/commands/cursor_move.rs | 16 | ||||
-rw-r--r-- | src/commands/delete_files.rs | 64 | ||||
-rw-r--r-- | src/commands/open_file.rs | 2 | ||||
-rw-r--r-- | src/commands/reload_dir.rs | 6 | ||||
-rw-r--r-- | src/commands/set_mode.rs | 2 | ||||
-rw-r--r-- | src/commands/show_hidden.rs | 2 | ||||
-rw-r--r-- | src/context.rs | 6 | ||||
-rw-r--r-- | src/fs/dirlist.rs | 13 | ||||
-rw-r--r-- | src/run.rs | 60 | ||||
-rw-r--r-- | src/tab.rs | 5 | ||||
-rw-r--r-- | src/ui/tui_backend.rs | 79 | ||||
-rw-r--r-- | src/ui/widgets/mod.rs | 6 | ||||
-rw-r--r-- | src/ui/widgets/tui_dirlist.rs | 36 | ||||
-rw-r--r-- | src/ui/widgets/tui_dirlist_detailed.rs | 48 | ||||
-rw-r--r-- | src/ui/widgets/tui_footer.rs | 10 | ||||
-rw-r--r-- | src/ui/widgets/tui_menu.rs | 146 | ||||
-rw-r--r-- | src/ui/widgets/tui_textfield.rs | 86 | ||||
-rw-r--r-- | src/ui/widgets/tui_topbar.rs | 4 | ||||
-rw-r--r-- | src/ui/widgets/tui_view.rs | 74 | ||||
-rw-r--r-- | src/util/key_mapping.rs | 1 | ||||
-rw-r--r-- | src/util/mod.rs | 1 | ||||
-rw-r--r-- | src/util/textfield.rs | 114 |
24 files changed, 377 insertions, 412 deletions
diff --git a/src/commands/change_directory.rs b/src/commands/change_directory.rs index 1897b90..ac97d59 100644 --- a/src/commands/change_directory.rs +++ b/src/commands/change_directory.rs @@ -53,7 +53,7 @@ impl std::fmt::Display for ChangeDirectory { } impl JoshutoRunnable for ChangeDirectory { - fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> { + fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> { Self::change_directories(&self.path, context)?; LoadChild::load_child(context)?; diff --git a/src/commands/command_line.rs b/src/commands/command_line.rs index 5795e5d..a00f442 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::ui::widgets::TuiTextField; use crate::ui::TuiBackend; -use crate::util::textfield::TextField; #[derive(Clone, Debug)] pub struct CommandLine { @@ -23,8 +23,8 @@ impl CommandLine { context: &mut JoshutoContext, backend: &mut TuiBackend, ) -> JoshutoResult<()> { - let mut textfield = TextField::new(backend, &context.events); - let user_input: Option<String> = textfield.readline(); + // let mut textfield = TuiTextField::new(backend, &context.events); + let user_input: Option<String> = None; // textfield.readline(); if let Some(s) = user_input { let trimmed = s.trim_start(); diff --git a/src/commands/cursor_move.rs b/src/commands/cursor_move.rs index 03d9908..36ba233 100644 --- a/src/commands/cursor_move.rs +++ b/src/commands/cursor_move.rs @@ -218,13 +218,9 @@ impl std::fmt::Display for CursorMoveHome { impl JoshutoRunnable for CursorMoveHome { fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> { - let movement: Option<usize> = match context - .curr_tab_ref() - .curr_list_ref() { + let movement: Option<usize> = match context.curr_tab_ref().curr_list_ref() { Some(curr_list) => { - let len = curr_list - .contents - .len(); + let len = curr_list.contents.len(); if len == 0 { None } else { @@ -263,13 +259,9 @@ impl std::fmt::Display for CursorMoveEnd { impl JoshutoRunnable for CursorMoveEnd { fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> { - let movement: Option<usize> = match context - .curr_tab_ref() - .curr_list_ref() { + let movement: Option<usize> = match context.curr_tab_ref().curr_list_ref() { Some(curr_list) => { - let len = curr_list - .contents - .len(); + let len = curr_list.contents.len(); if len == 0 { None } else { diff --git a/src/commands/delete_files.rs b/src/commands/delete_files.rs index f1ce09d..2219283 100644 --- a/src/commands/delete_files.rs +++ b/src/commands/delete_files.rs @@ -1,6 +1,10 @@ use std::fs; +use std::io::{self, Write}; use std::path; +use termion::clear; +use termion::cursor::Goto; + use crate::commands::{JoshutoCommand, JoshutoRunnable, ReloadDirList}; use crate::context::JoshutoContext; use crate::error::JoshutoResult; @@ -45,6 +49,21 @@ impl DeleteFiles { )); } + let frame = backend.terminal.get_frame(); + let f_size = frame.size(); + + let termion_terminal = backend.terminal.backend_mut(); + + write!( + termion_terminal, + "{}Delete {} files? (y/N){}", + Goto(1, f_size.height), + paths.len(), + clear::AfterCursor + ); + + io::stdout().flush().ok(); + let mut ch = termion::event::Key::Char('n'); while let Ok(evt) = context.events.next() { match evt { @@ -52,19 +71,7 @@ impl DeleteFiles { if key == termion::event::Key::Char('y') || key == termion::event::Key::Char('\n') { - if paths.len() > 1 { - while let Ok(evt) = context.events.next() { - match evt { - Event::Input(key) => { - ch = key; - break; - } - _ => {} - } - } - } else { - ch = termion::event::Key::Char('y'); - } + ch = termion::event::Key::Char('y'); } break; } @@ -73,9 +80,40 @@ impl DeleteFiles { } if ch == termion::event::Key::Char('y') { + if paths.len() > 1 { + write!( + termion_terminal, + "{}Are you sure? (Y/n){}", + Goto(1, f_size.height), + clear::AfterCursor + ); + + io::stdout().flush().ok(); + + while let Ok(evt) = context.events.next() { + match evt { + Event::Input(key) => { + ch = key; + break; + } + _ => {} + } + } + } else { + ch = termion::event::Key::Char('y'); + } + } + + if ch == termion::event::Key::Char('y') { Self::remove_files(&paths)?; ReloadDirList::reload(context.curr_tab_index, context)?; } + write!( + termion_terminal, + "{}{}", + Goto(1, f_size.height), + clear::AfterCursor + ); Ok(()) } } diff --git a/src/commands/open_file.rs b/src/commands/open_file.rs index 4f29432..f41ee7e 100644 --- a/src/commands/open_file.rs +++ b/src/commands/open_file.rs @@ -5,9 +5,9 @@ use crate::config::mimetype::JoshutoMimetypeEntry; use crate::context::JoshutoContext; use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult}; use crate::history::DirectoryHistory; +use crate::ui::widgets::TuiTextField; 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 eef3a3f..88cfc46 100644 --- a/src/commands/reload_dir.rs +++ b/src/commands/reload_dir.rs @@ -20,15 +20,15 @@ impl ReloadDirList { match curr_tab.curr_list_mut() { Some(curr_list) => curr_list.reload_contents(sort_option)?, - None => {}, + None => {} } match curr_tab.parent_list_mut() { Some(curr_list) => curr_list.reload_contents(sort_option)?, - None => {}, + None => {} } match curr_tab.child_list_mut() { Some(curr_list) => curr_list.reload_contents(sort_option)?, - None => {}, + None => {} } Ok(()) diff --git a/src/commands/set_mode.rs b/src/commands/set_mode.rs index 07f6d37..8a974e9 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::ui::widgets::TuiTextField; use crate::ui::TuiBackend; use crate::unix; -use crate::util::textfield::TextField; #[derive(Clone, Debug)] pub struct SetMode; diff --git a/src/commands/show_hidden.rs b/src/commands/show_hidden.rs index 63ac4bf..0a22c53 100644 --- a/src/commands/show_hidden.rs +++ b/src/commands/show_hidden.rs @@ -22,7 +22,7 @@ impl ToggleHiddenFiles { tab.history.depreciate_all_entries(); match tab.curr_list_mut() { Some(s) => s.depreciate(), - None => {}, + None => {} } } } diff --git a/src/context.rs b/src/context.rs index 37b9604..c0651d9 100644 --- a/src/context.rs +++ b/src/context.rs @@ -6,6 +6,8 @@ use crate::io::IOWorkerThread; use crate::tab::JoshutoTab; use crate::util::event::Events; +pub const MESSAGE_VISIBLE_DURATION: usize = 2; + pub struct JoshutoContext { pub exit: bool, pub curr_tab_index: usize, @@ -13,6 +15,8 @@ pub struct JoshutoContext { pub worker_queue: VecDeque<IOWorkerThread>, pub trx: (mpsc::SyncSender<u64>, mpsc::Receiver<u64>), + pub message_queue: VecDeque<String>, + pub message_elapse: usize, pub events: Events, pub config_t: config::JoshutoConfig, @@ -26,6 +30,8 @@ impl JoshutoContext { tabs: Vec::new(), worker_queue: VecDeque::with_capacity(10), trx: mpsc::sync_channel::<u64>(1), + message_queue: VecDeque::with_capacity(4), + message_elapse: MESSAGE_VISIBLE_DURATION, events: Events::new(), config_t, diff --git a/src/fs/dirlist.rs b/src/fs/dirlist.rs index 22a9f68..09c752c 100644 --- a/src/fs/dirlist.rs +++ b/src/fs/dirlist.rs @@ -70,13 +70,12 @@ impl JoshutoDirList { None } else { match self.get_curr_ref() { - Some(entry) => { - contents - .iter() - .enumerate() - .find(|(i, e)| e.file_name() == entry.file_name()) - .and_then(|(i, e)| Some(i)).or(Some(0)) - } + Some(entry) => contents + .iter() + .enumerate() + .find(|(i, e)| e.file_name() == entry.file_name()) + .and_then(|(i, e)| Some(i)) + .or(Some(0)), None => Some(0), } } @@ -1,37 +1,32 @@ use std::thread; -use termion::event::Key; - -use crate::commands::{CommandKeybind, CursorMoveUp, JoshutoCommand, JoshutoRunnable}; +use crate::commands::{CommandKeybind, CursorMoveUp, JoshutoRunnable}; use crate::config::{JoshutoCommandMapping, JoshutoConfig}; use crate::context::JoshutoContext; use crate::tab::JoshutoTab; use crate::ui; -use crate::util::event::{Event, Events}; -use crate::ui::widgets::TuiCommandMenu; +use crate::ui::widgets::{TuiCommandMenu, TuiView}; +use crate::util::event::Event; -pub fn run(config_t: JoshutoConfig, keymap_t: JoshutoCommandMapping) { - let mut backend: ui::TuiBackend = ui::TuiBackend::new().unwrap(); +pub fn run(config_t: JoshutoConfig, keymap_t: JoshutoCommandMapping) -> std::io::Result<()> { + let mut backend: ui::TuiBackend = ui::TuiBackend::new()?; let mut context = JoshutoContext::new(config_t); - match std::env::current_dir() { - Ok(curr_path) => match JoshutoTab::new(curr_path, &context.config_t.sort_option) { - Ok(s) => context.push_tab(s), - Err(e) => { - eprintln!("{}", e); - return; - } - }, - Err(e) => { - eprintln!("{}", e); - return; - } - } + let curr_path = std::env::current_dir()?; + { + // Initialize an initial tab + let tab = JoshutoTab::new(curr_path, &context.config_t.sort_option)?; + context.push_tab(tab); + + // move the cursor by 0 just to trigger a preview of child let tmp = CursorMoveUp::new(0); tmp.execute(&mut context, &mut backend); + + // render our view + let mut view = TuiView::new(&context); + backend.render(&mut view); } - backend.render(&context); let mut io_handle = None; while !context.exit { @@ -61,13 +56,17 @@ pub fn run(config_t: JoshutoConfig, keymap_t: JoshutoCommandMapping) { Ok(event) => { match event { Event::IOWorkerProgress(p) => { - eprintln!("{}", &format!("bytes copied {}", p)); + context + .message_queue + .push_back(format!("bytes copied {}", p)); } Event::IOWorkerResult => { match io_handle { Some(handle) => { handle.join(); - eprintln!("io_worker done"); + context + .message_queue + .push_back("io_worker done".to_string()); } None => {} } @@ -75,11 +74,13 @@ pub fn run(config_t: JoshutoConfig, keymap_t: JoshutoCommandMapping) { } Event::Input(key) => match keymap_t.get(&key) { None => { - eprintln!("Unknown keycode: {:?}", key); + context + .message_queue + .push_back(format!("Unknown keycode: {:?}", key)); } Some(CommandKeybind::SimpleKeybind(command)) => { if let Err(e) = command.execute(&mut context, &mut backend) { - eprintln!("{}", e.cause()); + context.message_queue.push_back(e.to_string()); } } Some(CommandKeybind::CompositeKeybind(m)) => { @@ -92,18 +93,21 @@ pub fn run(config_t: JoshutoConfig, keymap_t: JoshutoCommandMapping) { if let Some(command) = cmd { if let Err(e) = command.execute(&mut context, &mut backend) { - eprintln!("{}", e.cause()); + context.message_queue.push_back(e.to_string()); } } } }, } - backend.render(&context); + let mut view = TuiView::new(&context); + backend.render(&mut view); } Err(e) => { - eprintln!("{:?}", e); + context.message_queue.push_back(e.to_string()); break; } } } + eprintln!("{:#?}", context.message_queue); + Ok(()) } @@ -14,10 +14,7 @@ impl JoshutoTab { let mut history = JoshutoHistory::new(); history.populate_to_root(&curr_path, sort_option)?; - let tab = JoshutoTab { - curr_path, - history, - }; + let tab = JoshutoTab { curr_path, history }; Ok(tab) } diff --git a/src/ui/tui_backend.rs b/src/ui/tui_backend.rs index 4c64497..446d1c0 100644 --- a/src/ui/tui_backend.rs +++ b/src/ui/tui_backend.rs @@ -1,22 +1,12 @@ -use std::io::Write; - -use tui::buffer::Buffer; use termion::raw::{IntoRawMode, RawTerminal}; use termion::screen::AlternateScreen; use tui::backend::TermionBackend; -use tui::layout::{Constraint, Direction, Layout, Rect}; use tui::widgets::Widget; -use unicode_width::UnicodeWidthStr; - -use super::widgets::{TuiDirList, TuiDirListDetailed, TuiFooter, TuiTopBar}; -use crate::context::JoshutoContext; pub struct TuiBackend { pub terminal: tui::Terminal<TermionBackend<AlternateScreen<RawTerminal<std::io::Stdout>>>>, } -use super::{DEFAULT_LAYOUT, NO_PREVIEW_LAYOUT}; - impl TuiBackend { pub fn new() -> std::io::Result<Self> { let stdout = std::io::stdout().into_raw_mode()?; @@ -27,70 +17,13 @@ impl TuiBackend { Ok(Self { terminal }) } - pub fn render(&mut self, context: &JoshutoContext) { - let curr_tab = context.curr_tab_ref(); - - let curr_list = curr_tab.curr_list_ref(); - let parent_list = curr_tab.parent_list_ref(); - let child_list = curr_tab.child_list_ref(); - - let f_size = { - let frame = self.terminal.get_frame(); - frame.size() - }; - + pub fn render<W>(&mut self, widget: &mut W) + where + W: Widget, + { self.terminal.draw(|mut frame| { - let f_size = frame.size(); - - { - let top_rect = Rect { - x: 0, - y: 0, - width: f_size.width, - height: 1, - }; - - TuiTopBar::new(curr_tab.curr_path.as_path()) - .render(&mut frame, top_rect); - } - - let constraints = match child_list { - Some(_) => DEFAULT_LAYOUT, - None => NO_PREVIEW_LAYOUT, - }; - 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() { - TuiDirList::new(&curr_list).render(&mut frame, layout_rect[0]); - }; - - if let Some(curr_list) = curr_list.as_ref() { - TuiDirListDetailed::new(&curr_list).render(&mut frame, layout_rect[1]); - if let Some(entry) = curr_list.get_curr_ref() { - let top_rect = Rect { - x: 0, - y: f_size.height - 1, - width: f_size.width, - height: 1, - }; - TuiFooter::new(entry) - .render(&mut frame, top_rect); - } - }; - - if let Some(curr_list) = child_list.as_ref() { - TuiDirList::new(&curr_list).render(&mut frame, layout_rect[2]); - }; + let rect = frame.size(); + widget.render(&mut frame, rect); }); } } - -impl Widget for TuiBackend { - fn draw(&mut self, area: Rect, buf: &mut Buffer) { - - } -} diff --git a/src/ui/widgets/mod.rs b/src/ui/widgets/mod.rs index d80d4ca..e36c904 100644 --- a/src/ui/widgets/mod.rs +++ b/src/ui/widgets/mod.rs @@ -2,10 +2,14 @@ pub mod tui_dirlist; pub mod tui_dirlist_detailed; pub mod tui_footer; pub mod tui_menu; +pub mod tui_textfield; pub mod tui_topbar; +pub mod tui_view; pub use self::tui_dirlist::TuiDirList; pub use self::tui_dirlist_detailed::TuiDirListDetailed; pub use self::tui_footer::TuiFooter; -pub use self::tui_menu::TuiCommandMenu; +pub use self::tui_menu::{TuiCommandMenu, TuiMenu}; +pub use self::tui_textfield::TuiTextField; pub use self::tui_topbar::TuiTopBar; +pub use self::tui_view::TuiView; diff --git a/src/ui/widgets/tui_dirlist.rs b/src/ui/widgets/tui_dirlist.rs index 77684c7..4992fab 100644 --- a/src/ui/widgets/tui_dirlist.rs +++ b/src/ui/widgets/tui_dirlist.rs @@ -3,10 +3,8 @@ use tui::layout::Rect; use tui::style::{Color, Modifier, Style}; use tui::widgets::Widget; use unicode_width::UnicodeWidthStr; -use unicode_width::UnicodeWidthChar; use crate::fs::JoshutoDirList; -use crate::util::format; pub struct TuiDirList<'a> { dirlist: &'a JoshutoDirList, @@ -67,40 +65,32 @@ impl<'a> Widget for TuiDirList<'a> { let file_type = entry.metadata.file_type; if file_type.is_dir() { if name_width <= area_width { - buf.set_stringn(x, y + i as u16, - name, - area_width, style); + buf.set_stringn(x, y + i as u16, name, area_width, style); } else { - buf.set_stringn(x, y + i as u16, - name, - area_width - 1, style); - buf.set_string(x + area_width as u16 - 1, y + i as u16, - "…", style); + buf.set_stringn(x, y + i as u16, name, area_width - 1, style); + buf.set_string(x + area_width as u16 - 1, y + i as u16, "…", style); } continue; } if name_width < area_width { - buf.set_stringn(x, y + i as u16, - name, - area_width, style); + buf.set_stringn(x, y + i as u16, name, area_width, style); } else { match name.rfind('.') { None => { - buf.set_stringn(x, y + i as u16, - name, - area_width, style); + buf.set_stringn(x, y + i as u16, name, area_width, style); } Some(p_ind) => { let ext_width = name[p_ind..].width(); let file_name_width = area_width - ext_width - 1; - buf.set_stringn(x, y + i as u16, - &name[..p_ind], - file_name_width, style); - buf.set_string(x + file_name_width as u16, y + i as u16, - "…", style); - buf.set_string(x + file_name_width as u16 + 1, y + i as u16, - &name[p_ind..], style); + buf.set_stringn(x, y + i as u16, &name[..p_ind], file_name_width, style); + buf.set_string(x + file_name_width as u16, y + i as u16, "…", style); + buf.set_string( + x + file_name_width as u16 + 1, + y + i as u16, + &name[p_ind..], + style, + ); } } } diff --git a/src/ui/widgets/tui_dirlist_detailed.rs b/src/ui/widgets/tui_dirlist_detailed.rs index 2e01a26..d0f9c12 100644 --- a/src/ui/widgets/tui_dirlist_detailed.rs +++ b/src/ui/widgets/tui_dirlist_detailed.rs @@ -2,8 +2,8 @@ use tui::buffer::Buffer; use tui::layout::Rect; use tui::style::{Color, Modifier, Style}; use tui::widgets::Widget; -use unicode_width::UnicodeWidthStr; use unicode_width::UnicodeWidthChar; +use unicode_width::UnicodeWidthStr; use crate::fs::JoshutoDirList; use crate::util::format; @@ -35,9 +35,7 @@ impl<'a> Widget for TuiDirListDetailed<'a> { let dir_len = self.dirlist.contents.len(); if dir_len == 0 { - let style = Style::default() - .bg(Color::Red) - .fg(Color::White); + let style = Style::default().bg(Color::Red).fg(Color::White); buf.set_stringn(x, y, "empty", area.width as usize, style); return; } @@ -71,47 +69,43 @@ impl<'a> Widget for TuiDirListDetailed<'a> { let file_type = entry.metadata.file_type; if file_type.is_dir() { if name_width <= area_width { - buf.set_stringn(x, y + i as u16, - name, - area_width, style); + buf.set_stringn(x, y + i as u16, name, area_width, style); } else { - buf.set_stringn(x, y + i as u16, - name, - area_width - 1, style); - buf.set_string(x + area_width as u16 - 1, y + i as u16, - "…", style); + buf.set_stringn(x, y + i as u16, name, area_width - 1, style); + buf.set_string(x + area_width as u16 - 1, y + i as u16, "…", style); } continue; } if name_width < area_width - FILE_SIZE_WIDTH { - buf.set_stringn(x, y + i as u16, - name, - area_width - FILE_SIZE_WIDTH, style); + buf.set_stringn(x, y + i as u16, name, area_width - FILE_SIZE_WIDTH, style); } else { match name.rfind('.') { None => { - buf.set_stringn(x, y + i as u16, - name, - area_width - FILE_SIZE_WIDTH, style); + buf.set_stringn(x, y + i as u16, name, area_width - FILE_SIZE_WIDTH, style); } Some(p_ind) => { let ext_width = name[p_ind..].width(); let file_name_width = area_width - FILE_SIZE_WIDTH - ext_width - 2; - buf.set_stringn(x, y + i as u16, - &name[..p_ind], - file_name_width, style); - buf.set_string(x + file_name_width as u16, y + i as u16, - "…", style); - buf.set_string(x + file_name_width as u16 + 1, y + i as u16, - &name[p_ind..], style); + buf.set_stringn(x, y + i as u16, &name[..p_ind], file_name_width, style); + buf.set_string(x + file_name_width as u16, y + i as u16, "…", style); + buf.set_string( + x + file_name_width as u16 + 1, + y + i as u16, + &name[p_ind..], + style, + ); } } } let file_size_string = format::file_size_to_string(entry.metadata.len as f64); - buf.set_string(x + (area_width - FILE_SIZE_WIDTH) as u16, y + i as u16, - file_size_string, style); + buf.set_string( + x + (area_width - FILE_SIZE_WIDTH) as u16, + y + i as u16, + file_size_string, + style, + ); } } } diff --git a/src/ui/widgets/tui_footer.rs b/src/ui/widgets/tui_footer.rs index ac34b98..8bc1b49 100644 --- a/src/ui/widgets/tui_footer.rs +++ b/src/ui/widgets/tui_footer.rs @@ -1,5 +1,4 @@ use std::fs; -use std::path::Path; use tui::buffer::Buffer; use tui::layout::Rect; @@ -9,8 +8,6 @@ use tui::widgets::{Paragraph, Text, Widget}; use crate::fs::JoshutoDirEntry; use crate::util::format; -use crate::{HOSTNAME, USERNAME}; - pub struct TuiFooter<'a> { entry: &'a JoshutoDirEntry, } @@ -28,8 +25,7 @@ impl<'a> Widget for TuiFooter<'a> { let mode = self.entry.metadata.permissions.mode(); let mode = format::mode_to_string(mode); - let mode_style = Style::default() - .fg(Color::Cyan); + let mode_style = Style::default().fg(Color::Cyan); let mtime = self.entry.metadata.modified; let mtime = format::mtime_to_string(mtime); @@ -54,8 +50,6 @@ impl<'a> Widget for TuiFooter<'a> { } } - Paragraph::new(text.iter()) - .wrap(true) - .draw(area, buf); + Paragraph::new(text.iter()).wrap(true).draw(area, buf); } } diff --git a/src/ui/widgets/tui_menu.rs b/src/ui/widgets/tui_menu.rs index 64100f4..9dde1fe 100644 --- a/src/ui/widgets/tui_menu.rs +++ b/src/ui/widgets/tui_menu.rs @@ -1,28 +1,18 @@ -use std::io::{self, Write}; use std::iter::Iterator; -use tui::buffer::Buffer; -use termion::clear; -use termion::cursor::Goto; use termion::event::Key; -use termion::raw::IntoRawMode; -use termion::screen::AlternateScreen; -use tui::backend::TermionBackend; -use tui::layout::{Constraint, Direction, Layout, Rect}; +use tui::buffer::Buffer; +use tui::layout::Rect; use tui::style::{Color, Style}; -use tui::widgets::{Block, Borders, List, Paragraph, Text, Widget}; -use tui::Terminal; +use tui::widgets::{Block, Borders, Widget}; use unicode_width::UnicodeWidthStr; -use crate::commands::{CommandKeybind, CursorMoveUp, JoshutoCommand, JoshutoRunnable}; +use super::TuiView; +use crate::commands::{CommandKeybind, JoshutoCommand}; use crate::config::JoshutoCommandMapping; use crate::context::JoshutoContext; use crate::ui::TuiBackend; -use crate::util::event::{Event, Events}; -use super::{TuiDirList, TuiDirListDetailed, TuiTopBar}; - -use crate::{HOSTNAME, USERNAME}; |