1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
use dua::ByteFormat;
use std::borrow::Borrow;
use tui::{
buffer::Buffer,
layout::Rect,
style::Modifier,
style::{Color, Style},
text::{Line, Span, Text},
widgets::{Paragraph, Widget},
};
use crate::interactive::SortMode;
pub struct Footer;
pub struct FooterProps {
pub total_bytes: u128,
pub entries_traversed: u64,
pub traversal_start: std::time::Instant,
pub elapsed: Option<std::time::Duration>,
pub format: ByteFormat,
pub message: Option<String>,
pub sort_mode: SortMode,
}
impl Footer {
pub fn render(&self, props: impl Borrow<FooterProps>, area: Rect, buf: &mut Buffer) {
let FooterProps {
total_bytes,
entries_traversed,
elapsed,
traversal_start,
format,
message,
sort_mode,
} = props.borrow();
let spans = vec![
Span::from(format!(
"Sort mode: {} Total disk usage: {} Processed {} items {progress} ",
match sort_mode {
SortMode::SizeAscending => "size ascending",
SortMode::SizeDescending => "size descending",
SortMode::MTimeAscending => "modified ascending",
SortMode::MTimeDescending => "modified descending",
SortMode::CountAscending => "items ascending",
SortMode::CountDescending => "items descending",
},
format.display(*total_bytes),
entries_traversed,
progress = match elapsed {
Some(elapsed) => format!("in {:.02}s", elapsed.as_secs_f32()),
None => {
let elapsed = traversal_start.elapsed();
format!(
"in {:.0}s ({:.0}/s)",
elapsed.as_secs_f32(),
*entries_traversed as f32 / elapsed.as_secs_f32()
)
}
}
))
.into(),
message.as_ref().map(|m| {
Span::styled(
m,
Style {
fg: Color::Red.into(),
bg: Color::Reset.into(),
add_modifier: Modifier::BOLD | Modifier::RAPID_BLINK,
..Style::default()
},
)
}),
];
Paragraph::new(Text::from(Line::from(
spans.into_iter().flatten().collect::<Vec<_>>(),
)))
.style(Style::default().add_modifier(Modifier::REVERSED))
.render(area, buf);
}
}
|