M9: lens block, ctrl-p picker, /resume, wide side panel
ci / check (push) Canceled after 0s
ci / check (pull_request) Canceled after 0s

Closes #78, closes #82, closes #83
This commit is contained in:
hermes committed 2026-10-01 09:16:59 +00:00
1 parent b3960a09ed
commit d7aeaf0bb9
11 files changed
+604 -24

No files matched your search

+111
View File
@@ -23,6 +23,8 @@ pub enum Item {
},
Info(String),
Error(String),
/// Hook reports injected at turn end (`[lens] …`), shown as the lens block.
Lens(Vec<String>),
}
#[derive(Default)]
@@ -85,6 +87,7 @@ impl Transcript {
}
}
Event::Info(s) => self.push(Item::Info(s.clone())),
Event::Injected(t) => self.push(Item::Lens(t.clone())),
_ => {}
}
}
@@ -286,6 +289,7 @@ fn render(it: &Item, expanded: bool, width: usize, out: &mut Vec<Line<'static>>)
th.dim().add_modifier(Modifier::ITALIC),
)),
Item::Info(s) => out.push(Line::styled(format!("{} {s}", th.sym.info), th.dim())),
Item::Lens(texts) => lens_block(texts, expanded, width, out),
Item::Error(s) => out.push(Line::styled(format!("{} {s}", th.sym.err), th.err())),
Item::Tool {
name,
@@ -305,6 +309,88 @@ fn render(it: &Item, expanded: bool, width: usize, out: &mut Vec<Line<'static>>)
}
}
/// `┄ lens ┄┄┄` rule, then per report a summary line (errors red, all-pass green) and,
/// collapsed, the first findings; `ctrl-o` shows all.
fn lens_block(texts: &[String], expanded: bool, width: usize, out: &mut Vec<Line<'static>>) {
let th = theme::t();
let rule = if th.sym.ok == "+" { "-" } else { "┄" };
let head = format!(" {rule} lens ");
let fill = rule.repeat(width.saturating_sub(Span::raw(head.as_str()).width()));
out.push(Line::styled(format!("{head}{fill}"), th.dim()));
for t in texts {
let mut lines = t.lines();
let first = lines.next().unwrap_or_default();
let title = first
.strip_prefix("[lens] ")
.unwrap_or(first)
.trim_end_matches(':');
let rest: Vec<&str> = lines.collect();
// counts only mean something for diagnostics; test output quotes compiler lines
let diag = title.starts_with("diagnostics");
let count = |k: &str| rest.iter().filter(|l| diag && l.contains(k)).count();
let (errors, warnings) = (count(" error: "), count(" warning: "));
let (mark, st) = if title.contains("failing") || errors > 0 {
(th.sym.err, th.err())
} else if warnings > 0 {
("!", th.warn())
} else {
(th.sym.ok, th.ok())
};
let mut counts = vec![];
if errors > 0 {
counts.push(format!(
"{errors} error{}",
if errors == 1 { "" } else { "s" }
));
}
if warnings > 0 {
counts.push(format!(
"{warnings} warning{}",
if warnings == 1 { "" } else { "s" }
));
}
let counts = if counts.is_empty() {
String::new()
} else {
format!(" · {}", counts.join(", "))
};
out.push(Line::from(vec![
Span::styled(format!(" {mark} "), st),
Span::raw(title.to_string()),
Span::styled(counts, th.dim()),
]));
let n = if expanded {
rest.len()
} else {
rest.len().min(LENS_PREVIEW)
};
for l in &rest[..n] {
let ls = if l.contains(" error: ") {
th.err()
} else if l.contains(" warning: ") {
th.warn()
} else {
th.dim()
};
out.push(Line::from(vec![
Span::styled(format!(" {} ", th.sym.gutter), th.dim()),
Span::styled(l.trim_start().to_string(), ls),
]));
}
if n < rest.len() {
out.push(Line::styled(
format!(
" {} {} more lines (ctrl-o)",
th.sym.ellipsis,
rest.len() - n
),
th.dim(),
));
}
}
}
const LENS_PREVIEW: usize = 4;
const DIFF_PREVIEW: usize = 6;
const ERR_TAIL: usize = 5;
@@ -557,6 +643,31 @@ mod tests {
assert_eq!(text(&out), [" a b c"]);
}
#[test]
fn lens() {
let mut t = Transcript::default();
t.apply(&Event::Injected(vec![
"[lens] diagnostics for files changed this turn:\nsrc/a.rs:\n 3:1 error: E0308 mismatched (rust-analyzer)\n 9:2 warning: unused (rust-analyzer)\n 10:2 warning: x (r)\n 11:2 warning: y (r)\n 12:2 warning: z (r)".into(),
"[lens] tests: all 21 selected tests pass now".into(),
]));
let s = text(&t.lines(false, 30));
assert_eq!(s[0].chars().count(), 30);
assert!(s[0].starts_with(" ┄ lens ┄"));
assert_eq!(
s[1],
" ✗ diagnostics for files changed this turn · 1 error, 4 warnings"
);
assert_eq!(s[2], " │ src/a.rs:");
assert_eq!(s[3], " │ 3:1 error: E0308 mismatched (rust-analyzer)");
assert_eq!(s[6], " … 2 more lines (ctrl-o)");
assert_eq!(s[7], " ✓ tests: all 21 selected tests pass now");
assert_eq!(
text(&t.lines(true, 30)).len(),
10,
"expanded shows every finding"
);
}
#[test]
fn activity() {
let l = activity_line("bash", Duration::from_millis(12_900), 2);