diff options
Diffstat (limited to 'src/ui/widgets/tui_dirlist_detailed.rs')
-rw-r--r-- | src/ui/widgets/tui_dirlist_detailed.rs | 127 |
1 files changed, 73 insertions, 54 deletions
diff --git a/src/ui/widgets/tui_dirlist_detailed.rs b/src/ui/widgets/tui_dirlist_detailed.rs index 142757e..c76e198 100644 --- a/src/ui/widgets/tui_dirlist_detailed.rs +++ b/src/ui/widgets/tui_dirlist_detailed.rs @@ -4,7 +4,7 @@ use tui::style::{Color, Modifier, Style}; use tui::widgets::Widget; use unicode_width::UnicodeWidthStr; -use crate::fs::JoshutoDirList; +use crate::fs::{FileType, JoshutoDirList}; use crate::util::format; const FILE_SIZE_WIDTH: usize = 8; @@ -27,7 +27,6 @@ impl<'a> Widget for TuiDirListDetailed<'a> { let x = area.left(); let y = area.top(); - let curr_index = match self.dirlist.index { Some(i) => i, None => { @@ -38,12 +37,7 @@ impl<'a> Widget for TuiDirListDetailed<'a> { }; let skip_dist = curr_index / area.height as usize * area.height as usize; - - let screen_index = if skip_dist > 0 { - curr_index % skip_dist - } else { - curr_index - }; + let screen_index = curr_index % area.height as usize; let area_width = area.width as usize; for (i, entry) in self @@ -63,57 +57,82 @@ 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); - } 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); + match file_type { + FileType::Directory => { + if name_width <= area_width { + buf.set_string(x, y + i as u16, name, 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); + } } - // TODO: print out symlink path - // } else if file_type.is_symlink() { - } else { - if name_width < area_width - FILE_SIZE_WIDTH { - 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, - ); - } - Some(p_ind) => { - let ext_width = name[p_ind..].width(); - let file_name_width = area_width - FILE_SIZE_WIDTH - ext_width - 2; + FileType::Symlink(p) => { + if name_width < area_width - 4 { + buf.set_string(x, y + i as u16, name, style); + buf.set_string(x + area_width as u16 - 4, y + i as u16, "->", 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); + } + } + FileType::File => { + if name_width < area_width - FILE_SIZE_WIDTH { + 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, + ); + } + Some(p_ind) => { + let ext_width = name[p_ind..].width(); + let file_name_width = + if ext_width > area_width - FILE_SIZE_WIDTH - 2 { + 0 + } else { + 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, + ); + + let file_ext_width = + area_width - file_name_width - FILE_SIZE_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 + file_name_width as u16 + 1, + y + i as u16, + &name[p_ind..], + file_ext_width, + style, + ); + } } } + let file_size_string = format::file_size_to_string(entry.metadata.len); + buf.set_string( + x + (area_width - FILE_SIZE_WIDTH) as u16, + y + i as u16, + file_size_string, + style, + ); } - let file_size_string = format::file_size_to_string(entry.metadata.len); - buf.set_string( - x + (area_width - FILE_SIZE_WIDTH) as u16, - y + i as u16, - file_size_string, - style, - ); } } } |