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
use regex::Regex;
use std::sync::OnceLock;
static PROGRESS_RE: OnceLock<Regex> = OnceLock::new();
fn progress_re() -> &'static Regex {
PROGRESS_RE.get_or_init(|| Regex::new(r"^\s*\d+K\s+.*\d+%").unwrap())
}
pub fn compress(output: &str) -> Option<String> {
let trimmed = output.trim();
if trimmed.is_empty() {
return Some("ok".to_string());
}
let useful: Vec<&str> = trimmed
.lines()
.filter(|l| {
let t = l.trim();
!t.is_empty()
&& !progress_re().is_match(t)
&& !t.starts_with("Length:")
&& !t.starts_with("Connecting to")
&& !t.starts_with("Resolving")
&& !t.starts_with("HTTP request sent")
&& !t.starts_with("Reusing existing")
})
.collect();
let saved = trimmed.lines().find(|l| l.contains("saved"));
if let Some(saved_line) = saved {
let mut result = Vec::new();
for line in &useful {
if line.contains("Saving to") || line.contains("saved") || line.contains("--") {
result.push(line.to_string());
}
}
if result.is_empty() {
result.push(saved_line.trim().to_string());
}
return Some(result.join("\n"));
}
if useful.len() <= 5 {
return Some(useful.join("\n"));
}
Some(format!(
"{}\n... ({} more lines)",
useful[..3].join("\n"),
useful.len() - 3
))
}