1use super::*;
2
3pub struct Entry {
4 status: Status,
5 title: Text,
6 title_message: Option<Text>,
7 messages: Vec<Message>,
8}
9
10impl Entry {
11 pub fn new(
12 status: Status,
13 title: Text,
14 title_message: Option<Text>,
15 messages: Vec<Message>,
16 ) -> Self {
17 let title = title.into();
18 let title_message = match title_message {
19 Some(m) => Some(m.into()),
20 None => None,
21 };
22 Self {
23 status,
24 title,
25 title_message,
26 messages,
27 }
28 }
29
30 pub fn padding() -> usize {
31 5
32 }
33
34 fn print_header(&self, width: usize, first: bool, last: bool) {
35 let left = if first { "┌" } else { "├" };
36 let right = if first { "─┐" } else { "─┤" };
37 let mut w: usize = 1 + Self::padding() + 2 + 2 + 2;
38
39 let mut s = left.to_string();
40 for _ in 0..Self::padding() {
42 s.push_str("─");
43 }
44 s.push_str("┤");
45 print!(
46 "{}{}{}{} ",
47 Pretty::border_style(),
48 Pretty::border_color(),
49 s,
50 termion::style::Reset,
51 );
52
53 w += self.title.len();
55 self.title.print();
56 if let Some(message) = &self.title_message {
57 w += message.len() + 2;
58 print!(": ");
59 message.print();
60 }
61
62 let mut s = " ├".to_string();
63 for _ in 0..width - w {
64 s.push_str("─");
65 }
66
67 print!(
68 "{}{}{}{}",
69 Pretty::border_style(),
70 Pretty::border_color(),
71 s,
72 termion::style::Reset,
73 );
74 if last || !self.messages.is_empty() {
75 println!("{}", self.status.as_str());
76 } else {
77 println!(
78 "{}{}{}{}",
79 Pretty::border_style(),
80 Pretty::border_color(),
81 right,
82 termion::style::Reset,
83 );
84 }
85 }
86
87 fn print_botton(width: usize) {
88 let left = "└";
89 let right = "┘";
90 let mut s = left.to_string();
93 for _ in 0..width - 2 {
94 s.push_str("─");
95 }
96 s.push_str(right);
97 println!(
98 "{}{}{}{}",
99 Pretty::border_style(),
100 Pretty::border_color(),
101 s,
102 termion::style::Reset,
103 );
104 }
105
106 pub fn print(&self, width: usize, first: bool, last: bool) {
107 self.print_header(width, first, last);
108 if !self.messages.is_empty() {
109 for message in self.messages.iter() {
110 message.print(width);
111 }
112 }
113 if last {
114 Self::print_botton(width);
115 }
116 }
117}