diff options
author | Jeff Zhao <jeff.no.zhao@gmail.com> | 2021-08-19 15:27:00 -0400 |
---|---|---|
committer | Jeff Zhao <jeff.no.zhao@gmail.com> | 2021-08-19 15:27:00 -0400 |
commit | c7053df125a6943786f412348d85324e926e5ba5 (patch) | |
tree | 5a3f7fe3cf2863fd5dd584b2c0e1b30d96ddab5e | |
parent | cefc938d62364ea91f97778ff3baaff71cc77c8e (diff) |
add support for counting files lazily
- this should prevent excessive filesystem reading
and increase performance on slower storage mediums such as
network drives, mtpfs, etc.
-rw-r--r-- | src/commands/cursor_move.rs | 30 | ||||
-rw-r--r-- | src/ui/views/tui_folder_view.rs | 3 | ||||
-rw-r--r-- | src/ui/widgets/tui_dirlist_detailed.rs | 6 |
3 files changed, 33 insertions, 6 deletions
diff --git a/src/commands/cursor_move.rs b/src/commands/cursor_move.rs index 71bb876..3bded3c 100644 --- a/src/commands/cursor_move.rs +++ b/src/commands/cursor_move.rs @@ -13,6 +13,36 @@ pub fn cursor_move(new_index: usize, context: &mut AppContext) -> JoshutoResult< curr_list.index = Some(new_index); } } + + let directory_size = match context + .tab_context_ref() + .curr_tab_ref() + .curr_list_ref() + .and_then(|l| l.curr_entry_ref()) + { + Some(curr_entry) => { + if let Some(_) = curr_entry.metadata.directory_size() { + None + } else if !curr_entry.metadata.file_type().is_dir() { + None + } else { + let history = context.tab_context_ref().curr_tab_ref().history_ref(); + history.get(curr_entry.file_path()).map(|d| d.len()) + } + } + None => None, + }; + + if let Some(s) = directory_size { + if let Some(curr_entry) = context + .tab_context_mut() + .curr_tab_mut() + .curr_list_mut() + .and_then(|l| l.curr_entry_mut()) + { + curr_entry.metadata.update_directory_size(s); + } + } Ok(()) } diff --git a/src/ui/views/tui_folder_view.rs b/src/ui/views/tui_folder_view.rs index 1e23aa6..d1e420e 100644 --- a/src/ui/views/tui_folder_view.rs +++ b/src/ui/views/tui_folder_view.rs @@ -30,7 +30,6 @@ impl<'a> Widget for TuiFolderView<'a> { fn render(self, area: Rect, buf: &mut Buffer) { let preview_context = self.context.preview_context_ref(); let curr_tab = self.context.tab_context_ref().curr_tab_ref(); - let history = curr_tab.history_ref(); let curr_list = curr_tab.curr_list_ref(); let parent_list = curr_tab.parent_list_ref(); @@ -128,7 +127,7 @@ impl<'a> Widget for TuiFolderView<'a> { // render current view if let Some(list) = curr_list.as_ref() { - TuiDirListDetailed::new(&list, history).render(layout_rect[1], buf); + TuiDirListDetailed::new(&list).render(layout_rect[1], buf); let rect = Rect { x: 0, y: area.height - 1, diff --git a/src/ui/widgets/tui_dirlist_detailed.rs b/src/ui/widgets/tui_dirlist_detailed.rs index 2ecec93..a43d4f6 100644 --- a/src/ui/widgets/tui_dirlist_detailed.rs +++ b/src/ui/widgets/tui_dirlist_detailed.rs @@ -4,7 +4,6 @@ use tui::style::{Color, Modifier, Style}; use tui::widgets::Widget; use crate::fs::{FileType, JoshutoDirEntry, JoshutoDirList, LinkType}; -use crate::history::JoshutoHistory; use crate::util::format; use crate::util::string::UnicodeTruncate; use crate::util::style; @@ -16,12 +15,11 @@ const ELLIPSIS: &str = "…"; pub struct TuiDirListDetailed<'a> { dirlist: &'a JoshutoDirList, - history: &'a JoshutoHistory, } impl<'a> TuiDirListDetailed<'a> { - pub fn new(dirlist: &'a JoshutoDirList, history: &'a JoshutoHistory) -> Self { - Self { dirlist, history } + pub fn new(dirlist: &'a JoshutoDirList) -> Self { + Self { dirlist } } } |