@@ -7,6 +7,7 @@ use chrono::DateTime;
77use dua:: traverse:: { EntryData , Tree , TreeIndex } ;
88use human_format;
99use itertools:: Itertools ;
10+ use once_cell:: sync:: Lazy ;
1011use std:: time:: SystemTime ;
1112use std:: { borrow:: Borrow , path:: Path } ;
1213use 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+
2633pub 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