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
use super::*;
use terminal_size::{terminal_size, Height, Width};
pub struct Pretty {
entries: Vec<Entry>,
}
impl Pretty {
pub fn new() -> Self {
Self { entries: vec![] }
}
pub fn add(&mut self, entriy: Entry) {
self.entries.push(entriy);
}
pub fn width() -> usize {
let size = terminal_size();
if let Some((Width(w), Height(_))) = size {
w as usize
} else {
80
}
}
pub fn border_style() -> &'static str {
termion::style::Reset.as_ref()
}
pub fn border_color() -> &'static str {
termion::color::White.fg_str()
}
pub fn print(&self) {
let width = Self::width();
print!("{}{}", termion::clear::All, termion::cursor::Goto(1, 1));
if let Some((first, others)) = self.entries.split_first() {
first.print(width, true, others.is_empty());
if let Some((last, others)) = others.split_last() {
for entry in others {
entry.print(width, false, false);
}
last.print(width, false, true);
}
} else {
println!();
}
}
}