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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
use {
crate::*,
anyhow::*,
serde::{
Deserialize,
Serialize,
},
std::io::Write,
termimad::crossterm::style::Stylize,
};
/// a kind of section
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum Kind {
/// a warning
Warning,
/// an error
Error,
/// a test failure
TestFail,
/// a test output (may be a failure, or just --show-output)
TestOutput,
/// a sum of errors and/or warnings, typically occurring
/// at the end of the compilation of a package
Sum,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum LineType {
/// the start of a section
Title(Kind),
/// the end of a section (not part of the section)
SectionEnd,
/// a line locating the problem
Location,
/// the line saying if a test was passed
TestResult(bool),
/// a suggestion to try with backtrace
BacktraceSuggestion,
/// a line we know is useless noise
Garbage,
/// Raw line, unclassified
Raw(CommandStream),
/// Continuation of a previous line
Continuation {
/// offset to count back to get to first (starting at 1)
offset: usize,
/// whether the line is a summary
summary: bool,
},
/// any other line
Normal,
}
impl LineType {
/// Width on screen for the specific prefix of line of this type
pub fn cols(self) -> usize {
match self {
Self::Title(_) => 3,
_ => 0,
}
}
pub fn at_index_in(
idx: usize,
lines: &[Line],
) -> Option<Self> {
let line = lines.get(idx)?;
match line.line_type {
Self::Continuation { offset, .. } => {
if offset > idx {
error!("inconsistent offset in continuation line");
return None;
}
let idx = idx - offset;
let line = lines.get(idx)?;
Some(line.line_type)
}
line_type => Some(line_type),
}
}
pub fn is_summary(self) -> bool {
match self {
Self::Normal | Self::Raw(_) => false,
Self::Continuation { summary, .. } => summary,
_ => true,
}
}
pub fn matches(
self,
summary: bool,
) -> bool {
!summary || self.is_summary()
}
pub fn draw(
self,
w: &mut W,
item_idx: usize,
) -> Result<()> {
match self {
Self::Title(Kind::Error) => {
write!(w, "{}", format!("{item_idx:^3}").black().bold().on_red())?;
}
Self::Title(Kind::TestFail | Kind::TestOutput) => {
write!(
w,
"\u{1b}[1m\u{1b}[38;5;235m\u{1b}[48;5;208m{item_idx:^3}\u{1b}[0m\u{1b}[0m"
)?;
}
Self::Title(Kind::Warning) => {
write!(w, "{}", format!("{item_idx:^3}").black().bold().on_yellow())?;
}
_ => {}
}
Ok(())
}
}