Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ba2efe4

Browse files
committed
Merge branch 'total_item_count'
2 parents 606d60f + 3241022 commit ba2efe4

3 files changed

Lines changed: 23 additions & 11 deletions

File tree

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ open = { version = "5.0", optional = true }
3939
wild = "2.0.4"
4040
owo-colors = "3.5.0"
4141
human_format = "1.0.3"
42+
once_cell = "1.19"
4243

4344
[[bin]]
4445
name="dua"

src/interactive/widgets/entries.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use chrono::DateTime;
77
use dua::traverse::{EntryData, Tree, TreeIndex};
88
use human_format;
99
use itertools::Itertools;
10+
use once_cell::sync::Lazy;
1011
use std::time::SystemTime;
1112
use std::{borrow::Borrow, path::Path};
1213
use tui::{
@@ -23,6 +24,12 @@ use tui_react::{
2324
List, ListProps,
2425
};
2526

27+
static COUNT: Lazy<human_format::Formatter> = Lazy::new(|| {
28+
let mut formatter = human_format::Formatter::new();
29+
formatter.with_decimals(0).with_separator("");
30+
formatter
31+
});
32+
2633
pub struct EntriesProps<'a> {
2734
pub tree: &'a Tree,
2835
pub root: TreeIndex,
@@ -67,7 +74,12 @@ impl Entries {
6774
};
6875

6976
let total: u128 = entries.iter().map(|b| b.data.size).sum();
70-
let title = title(&current_path(tree, *root), entries.len());
77+
let (item_count, item_size): (u64, u128) = entries
78+
.iter()
79+
.map(|f| (f.data.entry_count.unwrap_or(1), f.data.size))
80+
.reduce(|a, b| (a.0 + b.0, a.1 + b.1))
81+
.unwrap_or_default();
82+
let title = title(&current_path(tree, *root), item_count, *display, item_size);
7183
let title_block = title_block(&title, *border_style);
7284
let entry_in_view = entry_in_view(*selected, entries);
7385

@@ -149,15 +161,16 @@ fn title_block(title: &str, border_style: Style) -> Block<'_> {
149161
.borders(Borders::ALL)
150162
}
151163

152-
fn title(current_path: &str, item_count: usize) -> String {
164+
fn title(current_path: &str, item_count: u64, display: DisplayOptions, size: u128) -> String {
153165
format!(
154-
" {} ({} item{}) ",
166+
" {} ({} item{}, {}) ",
155167
current_path,
156-
item_count,
168+
COUNT.format(item_count as f64),
157169
match item_count {
158170
1 => "",
159171
_ => "s",
160-
}
172+
},
173+
display.byte_format.display(size)
161174
)
162175
}
163176

@@ -250,10 +263,7 @@ fn count_column(entry_count: Option<u64>, style: Style) -> Span<'static> {
250263
"{:>4}",
251264
match entry_count {
252265
Some(count) => {
253-
human_format::Formatter::new()
254-
.with_decimals(0)
255-
.with_separator("")
256-
.format(count as f64)
266+
COUNT.format(count as f64)
257267
}
258268
None => "".to_string(),
259269
}

0 commit comments

Comments
 (0)