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
use {
crate::*,
anyhow::*,
std::io::Write,
termimad::crossterm::style::Stylize,
};
/// a kind of section
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Kind {
/// a warning
Warning,
/// an error
Error,
/// a test failure
TestFail,
/// a sum of errors and/or warnings, typically occuring
/// at the end of the compilation of a package
Sum,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum LineType {
/// the start of a section
Title(Kind),
/// a line locating the problem
Location,
/// the line saying if a test was passed
TestResult(bool),
/// a suggestion to try with backtrace
BacktraceSuggestion,
/// any other line
Normal,
}
impl LineType {
pub fn cols(self) -> usize {
match self {
Self::Title(_) => 3,
_ => 0,
}
}
pub fn draw(
self,
w: &mut W,
item_idx: usize,
) -> Result<()> {
match self {
Self::Title(Kind::Error) => {
write!(w, "{}", format!("{:^3}", item_idx).black().bold().on_red())?;
}
Self::Title(Kind::TestFail) => {
write!(
w,
"\u{1b}[1m\u{1b}[38;5;235m\u{1b}[48;5;208m{:^3}\u{1b}[0m\u{1b}[0m",
item_idx
)?;
}
Self::Title(Kind::Warning) => {
write!(
w,
"{}",
format!("{:^3}", item_idx).black().bold().on_yellow()
)?;
}
_ => {}
}
Ok(())
}
}