diff options
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/views/tui_folder_view.rs | 3 | ||||
-rw-r--r-- | src/ui/views/tui_hsplit_view.rs | 6 | ||||
-rw-r--r-- | src/ui/widgets/tui_dirlist_detailed.rs | 40 |
3 files changed, 36 insertions, 13 deletions
diff --git a/src/ui/views/tui_folder_view.rs b/src/ui/views/tui_folder_view.rs index d2eabf4..dfa70ee 100644 --- a/src/ui/views/tui_folder_view.rs +++ b/src/ui/views/tui_folder_view.rs @@ -167,7 +167,8 @@ impl<'a> Widget for TuiFolderView<'a> { // render current view if let Some(list) = curr_list.as_ref() { - TuiDirListDetailed::new(list, display_options, true).render(layout_rect[1], buf); + TuiDirListDetailed::new(list, display_options, curr_tab.option_ref(), true) + .render(layout_rect[1], buf); let footer_area = Self::footer_area(&area); if self.show_bottom_status { diff --git a/src/ui/views/tui_hsplit_view.rs b/src/ui/views/tui_hsplit_view.rs index 71b483e..ce0877d 100644 --- a/src/ui/views/tui_hsplit_view.rs +++ b/src/ui/views/tui_hsplit_view.rs @@ -78,7 +78,8 @@ impl<'a> Widget for TuiHSplitView<'a> { // render current view if let Some(list) = curr_list.as_ref() { - TuiDirListDetailed::new(list, display_options, true).render(layout_rect, buf); + TuiDirListDetailed::new(list, display_options, curr_tab.option_ref(), true) + .render(layout_rect, buf); let rect = Rect { x: 0, y: area.height - 1, @@ -150,7 +151,8 @@ impl<'a> Widget for TuiHSplitView<'a> { }; if let Some(list) = curr_list.as_ref() { - TuiDirListDetailed::new(list, display_options, false).render(layout_rect, buf); + TuiDirListDetailed::new(list, display_options, curr_tab.option_ref(), false) + .render(layout_rect, buf); } } } diff --git a/src/ui/widgets/tui_dirlist_detailed.rs b/src/ui/widgets/tui_dirlist_detailed.rs index 85d5c7f..7cf721f 100644 --- a/src/ui/widgets/tui_dirlist_detailed.rs +++ b/src/ui/widgets/tui_dirlist_detailed.rs @@ -5,7 +5,7 @@ use tui::layout::Rect; use tui::style::{Color, Modifier, Style}; use tui::widgets::Widget; -use crate::config::option::{DisplayOption, LineNumberStyle}; +use crate::config::option::{DisplayOption, LineMode, LineNumberStyle, TabDisplayOption}; use crate::fs::{FileType, JoshutoDirEntry, JoshutoDirList, LinkType}; use crate::util::format; use crate::util::string::UnicodeTruncate; @@ -19,17 +19,20 @@ const ELLIPSIS: &str = "…"; pub struct TuiDirListDetailed<'a> { dirlist: &'a JoshutoDirList, display_options: &'a DisplayOption, + tab_display_options: &'a TabDisplayOption, pub focused: bool, } impl<'a> TuiDirListDetailed<'a> { pub fn new( dirlist: &'a JoshutoDirList, display_options: &'a DisplayOption, + tab_display_options: &'a TabDisplayOption, focused: bool, ) -> Self { Self { dirlist, display_options, + tab_display_options, focused, } } @@ -105,6 +108,7 @@ impl<'a> Widget for TuiDirListDetailed<'a> { entry, style, (x + 1, y + i as u16), + self.tab_display_options.linemode, drawing_width - 1, &prefix, ); @@ -112,28 +116,44 @@ impl<'a> Widget for TuiDirListDetailed<'a> { } } +fn get_entry_size_string(entry: &JoshutoDirEntry) -> String { + match entry.metadata.file_type() { + FileType::Directory => entry + .metadata + .directory_size() + .map(|n| n.to_string()) + .unwrap_or_else(|| "".to_string()), + FileType::File => format::file_size_to_string(entry.metadata.len()), + } +} + fn print_entry( buf: &mut Buffer, entry: &JoshutoDirEntry, style: Style, (x, y): (u16, u16), + linemode: LineMode, drawing_width: usize, prefix: &str, ) { - let size_string = match entry.metadata.file_type() { - FileType::Directory => entry - .metadata - .directory_size() - .map(|n| n.to_string()) - .unwrap_or_else(|| "".to_string()), - FileType::File => format::file_size_to_string(entry.metadata.len()), - }; let symlink_string = match entry.metadata.link_type() { LinkType::Normal => "", LinkType::Symlink(_, _) => "-> ", }; let left_label_original = entry.label(); - let right_label_original = format!(" {}{} ", symlink_string, size_string); + let right_label_original = format!( + " {}{} ", + symlink_string, + match linemode { + LineMode::Size => get_entry_size_string(entry), + LineMode::MTime => format::mtime_to_string(entry.metadata.modified()), + LineMode::SizeMTime => format!( + "{} {}", + get_entry_size_string(entry), + format::mtime_to_string(entry.metadata.modified()) + ), + } + ); // draw prefix first let prefix_width = prefix.width(); |