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
83
|
use crate::{
interactive::{widgets::COLOR_MARKED_DARK, EntryMarkMap},
ByteFormat,
};
use std::borrow::Borrow;
use tui::{
buffer::Buffer,
layout::Rect,
style::Modifier,
style::{Color, Style},
widgets::Widget,
widgets::{Paragraph, Text},
};
pub struct Footer;
pub struct FooterProps<'a> {
pub total_bytes: Option<u64>,
pub entries_traversed: u64,
pub format: ByteFormat,
pub marked: Option<&'a EntryMarkMap>,
pub message: Option<String>,
}
impl Footer {
pub fn render<'a>(&self, props: impl Borrow<FooterProps<'a>>, area: Rect, buf: &mut Buffer) {
let FooterProps {
total_bytes,
entries_traversed,
format,
marked,
message,
} = props.borrow();
let bg_color = Color::White;
let text_color = Color::Black;
let lines = [
Some(Text::Raw(
format!(
" Total disk usage: {} Entries: {} ",
match total_bytes {
Some(b) => format!("{}", format.display(*b)).to_owned(),
None => "-".to_owned(),
},
entries_traversed,
)
.into(),
)),
marked.and_then(|marked| match marked.is_empty() {
true => None,
false => Some(Text::Styled(
format!(
"Marked {} items ({}) ",
marked.len(),
format.display(marked.iter().map(|(_k, v)| v.size).sum::<u64>())
)
.into(),
Style {
fg: COLOR_MARKED_DARK,
bg: bg_color,
modifier: Modifier::BOLD | Modifier::RAPID_BLINK,
},
)),
}),
message.as_ref().map(|m| {
Text::Styled(
m.into(),
Style {
fg: Color::Red,
bg: bg_color,
modifier: Modifier::BOLD | Modifier::RAPID_BLINK,
},
)
}),
];
Paragraph::new(lines.iter().filter_map(|x| x.as_ref()))
.style(Style {
fg: text_color,
bg: bg_color,
..Default::default()
})
.draw(area, buf);
}
}
|