summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPiotr Wach <pwach@bloomberg.net>2023-12-19 20:32:28 +0000
committerPiotr Wach <pwach@bloomberg.net>2023-12-19 21:14:12 +0000
commitf3b5d00549be57b5da03f3220057b887372ff254 (patch)
tree92150455e3c95195c62d559efedf8f11a0df3540 /src
parentdf6a02cd8fdbe693f507ab34a89227431d7c112e (diff)
Replace EntryData in EntryDataBundle with individual properties
Diffstat (limited to 'src')
-rw-r--r--src/interactive/app/common.rs37
-rw-r--r--src/interactive/app/eventloop.rs7
-rw-r--r--src/interactive/widgets/entries.rs15
3 files changed, 30 insertions, 29 deletions
diff --git a/src/interactive/app/common.rs b/src/interactive/app/common.rs
index f4d5939..9d1d0e4 100644
--- a/src/interactive/app/common.rs
+++ b/src/interactive/app/common.rs
@@ -1,8 +1,8 @@
use crate::interactive::path_of;
-use dua::traverse::{EntryData, Tree, TreeIndex};
+use dua::traverse::{Tree, TreeIndex};
use itertools::Itertools;
use petgraph::Direction;
-use std::path::Path;
+use std::time::SystemTime;
use std::{cmp::Ordering, path::PathBuf};
use unicode_segmentation::UnicodeSegmentation;
@@ -48,16 +48,12 @@ impl SortMode {
pub struct EntryDataBundle {
pub index: TreeIndex,
- pub data: EntryData,
+ pub name: PathBuf,
+ pub size: u128,
+ pub mtime: SystemTime,
+ pub entry_count: Option<u64>,
pub is_dir: bool,
pub exists: bool,
- pub glob_name: Option<PathBuf>,
-}
-
-impl EntryDataBundle {
- pub fn name(&self) -> &Path {
- self.glob_name.as_deref().unwrap_or(&self.data.name)
- }
}
pub fn sorted_entries(
@@ -68,10 +64,9 @@ pub fn sorted_entries(
) -> Vec<EntryDataBundle> {
use SortMode::*;
fn cmp_count(l: &EntryDataBundle, r: &EntryDataBundle) -> Ordering {
- l.data
- .entry_count
- .cmp(&r.data.entry_count)
- .then_with(|| l.data.name.cmp(&r.data.name))
+ l.entry_count
+ .cmp(&r.entry_count)
+ .then_with(|| l.name.cmp(&r.name))
}
tree.neighbors_directed(node_idx, Direction::Outgoing)
.filter_map(|idx| {
@@ -84,18 +79,20 @@ pub fn sorted_entries(
let pm = p.symlink_metadata();
EntryDataBundle {
index: idx,
- data: w.clone(),
+ name: if use_glob_path { p } else { w.name.clone() },
+ size: w.size,
+ mtime: w.mtime,
+ entry_count: w.entry_count,
exists: pm.is_ok(),
is_dir: pm.ok().map_or(false, |m| m.is_dir()),
- glob_name: if use_glob_path { Some(p) } else { None },
}
})
})
.sorted_by(|l, r| match sorting {
- SizeDescending => r.data.size.cmp(&l.data.size),
- SizeAscending => l.data.size.cmp(&r.data.size),
- MTimeAscending => l.data.mtime.cmp(&r.data.mtime),
- MTimeDescending => r.data.mtime.cmp(&l.data.mtime),
+ SizeDescending => r.size.cmp(&l.size),
+ SizeAscending => l.size.cmp(&r.size),
+ MTimeAscending => l.mtime.cmp(&r.mtime),
+ MTimeDescending => r.mtime.cmp(&l.mtime),
CountAscending => cmp_count(l, r),
CountDescending => cmp_count(l, r).reverse(),
})
diff --git a/src/interactive/app/eventloop.rs b/src/interactive/app/eventloop.rs
index ec31ca1..f394c53 100644
--- a/src/interactive/app/eventloop.rs
+++ b/src/interactive/app/eventloop.rs
@@ -297,7 +297,12 @@ impl AppState {
let new_entries = self.navigation().selected.map(|previously_selected| {
(
previously_selected,
- tree_view.sorted_entries(self.navigation().view_root, self.sorting),
+ sorted_entries(
+ tree_view.tree(),
+ self.navigation().view_root,
+ self.sorting,
+ None,
+ ),
)
});
self.enter_node(new_entries);
diff --git a/src/interactive/widgets/entries.rs b/src/interactive/widgets/entries.rs
index 34c5a8e..eecd223 100644
--- a/src/interactive/widgets/entries.rs
+++ b/src/interactive/widgets/entries.rs
@@ -57,10 +57,10 @@ impl Entries {
} = props.borrow();
let list = &mut self.list;
- let total: u128 = entries.iter().map(|b| b.data.size).sum();
+ let total: u128 = entries.iter().map(|b| b.size).sum();
let (item_count, item_size): (u64, u128) = entries
.iter()
- .map(|f| (f.data.entry_count.unwrap_or(1), f.data.size))
+ .map(|f| (f.entry_count.unwrap_or(1), f.size))
.reduce(|a, b| (a.0 + b.0, a.1 + b.1))
.unwrap_or_default();
let title = title(current_path, item_count, *display, item_size);
@@ -73,33 +73,32 @@ impl Entries {
};
let lines = entries.iter().map(|bundle| {
let node_idx = &bundle.index;
- let entry_data = &bundle.data;
let is_dir = &bundle.is_dir;
let exists = &bundle.exists;
- let name = bundle.name();
+ let name = bundle.name.as_path();
let is_marked = marked.map(|m| m.contains_key(node_idx)).unwrap_or(false);
let is_selected = selected.map_or(false, |idx| idx == *node_idx);
- let fraction = entry_data.size as f32 / total as f32;
+ let fraction = bundle.size as f32 / total as f32;
let text_style = style(is_selected, *is_focussed);
let percentage_style = percentage_style(fraction, text_style);
let mut columns = Vec::new();
if show_mtime_column(sort_mode) {
columns.push(mtime_column(
- entry_data.mtime,
+ bundle.mtime,
column_style(Column::MTime, *sort_mode, text_style),
));
}
columns.push(bytes_column(
*display,
- entry_data.size,
+ bundle.size,
column_style(Column::Bytes, *sort_mode, text_style),
));
columns.push(percentage_column(*display, fraction, percentage_style));
if show_count_column(sort_mode) {
columns.push(count_column(
- entry_data.entry_count,
+ bundle.entry_count,
column_style(Column::Count, *sort_mode, text_style),
));
}