summaryrefslogtreecommitdiffstats
path: root/src/interactive/widgets/entries.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/interactive/widgets/entries.rs')
-rw-r--r--src/interactive/widgets/entries.rs30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/interactive/widgets/entries.rs b/src/interactive/widgets/entries.rs
index 8e4132d..9357587 100644
--- a/src/interactive/widgets/entries.rs
+++ b/src/interactive/widgets/entries.rs
@@ -7,6 +7,7 @@ use chrono::DateTime;
use dua::traverse::{EntryData, Tree, TreeIndex};
use human_format;
use itertools::Itertools;
+use once_cell::sync::Lazy;
use std::time::SystemTime;
use std::{borrow::Borrow, path::Path};
use tui::{
@@ -23,6 +24,12 @@ use tui_react::{
List, ListProps,
};
+static COUNT: Lazy<human_format::Formatter> = Lazy::new(|| {
+ let mut formatter = human_format::Formatter::new();
+ formatter.with_decimals(0).with_separator("");
+ formatter
+});
+
pub struct EntriesProps<'a> {
pub tree: &'a Tree,
pub root: TreeIndex,
@@ -67,11 +74,12 @@ impl Entries {
};
let total: u128 = entries.iter().map(|b| b.data.size).sum();
- let item_count: u64 = entries
+ let (item_count, item_size): (u64, u128) = entries
.iter()
- .map(|f| f.data.entry_count.unwrap_or(1))
- .sum();
- let title = title(&current_path(tree, *root), item_count);
+ .map(|f| (f.data.entry_count.unwrap_or(1), f.data.size))
+ .reduce(|a, b| (a.0 + b.0, a.1 + b.1))
+ .unwrap_or_default();
+ let title = title(&current_path(tree, *root), item_count, *display, item_size);
let title_block = title_block(&title, *border_style);
let entry_in_view = entry_in_view(*selected, entries);
@@ -153,15 +161,16 @@ fn title_block(title: &str, border_style: Style) -> Block<'_> {
.borders(Borders::ALL)
}
-fn title(current_path: &str, item_count: u64) -> String {
+fn title(current_path: &str, item_count: u64, display: DisplayOptions, size: u128) -> String {
format!(
- " {} ({} item{}) ",
+ " {} ({} item{}, {}) ",
current_path,
- item_count,
+ COUNT.format(item_count as f64),
match item_count {
1 => "",
_ => "s",
- }
+ },
+ display.byte_format.display(size)
)
}
@@ -254,10 +263,7 @@ fn count_column(entry_count: Option<u64>, style: Style) -> Span<'static> {
"{:>4}",
match entry_count {
Some(count) => {
- human_format::Formatter::new()
- .with_decimals(0)
- .with_separator("")
- .format(count as f64)
+ COUNT.format(count as f64)
}
None => "".to_string(),
}