Craft Anything: understand how any software works, and craft your own.
Rust
Keep long lines in the feed's tool work inside the window (#785)
Fábio Soares42f44257aeaf
diff --git a/crates/ui-egui/src/project.rs b/crates/ui-egui/src/project.rsindex a53c66f2..fee3b226 100644--- a/crates/ui-egui/src/project.rs+++ b/crates/ui-egui/src/project.rs@@ -1371,11 +1371,14 @@ fn work(ui: &mut Ui, tools: &[(String, Option<bool>)], notes: &[String], advancelet running = tools.iter().any(|(_, d)| d.is_none());let failed = tools.iter().filter(|(_, d)| *d == Some(false)).count();let title = if tools.is_empty() {- notes.last().cloned().unwrap_or_default()+ one_line(notes.last().map(String::as_str).unwrap_or_default())} else {let n = tools.len().to_string();if running { trf("Working… ({n} steps so far)", &[("n", &n)]) } else { trf("Worked through {n} steps", &[("n", &n)]) }};+ // The notes in the body wrap inside the window (#666). A collapsing header's title never wraps+ // (egui lays it out on one line), so with no tool the title is the note's first line only.+ ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Wrap);egui::CollapsingHeader::new(RichText::new(title).color(t.text_dim).size(theme::CAPTION)).default_open(advanced).icon(widgets::disclosure_icon).show(ui,|ui| {@@ -1404,6 +1407,18 @@ fn work(ui: &mut Ui, tools: &[(String, Option<bool>)], notes: &[String], advance);}+/// A note's first line, cut to a length a header title can show on one line (#666).+fn one_line(text: &str) -> String {+ const MAX: usize = 90;+ let first = text.lines().map(str::trim).find(|l| !l.is_empty()).unwrap_or_default();+ if first.chars().count() <= MAX {+ first.to_string()+ } else {+ let cut: String = first.chars().take(MAX).collect();+ format!("{}…", cut.trim_end())+ }+}+/// A question or approval card. Returns the person's answer when they give one./// The project's last run stopped part-way without pausing (the app or the computer closed while/// it worked): its saved status still says it's working, but nothing is.@@ -2376,3 +2391,22 @@ mod tests {assert_eq!(feed.iter().filter(|f| matches!(f, FeedItem::Error { .. })).count(), 1, "a pause adds no error");}}++#[cfg(test)]+mod one_line_tests {+ use super::one_line;++ /// #666: a header title is one short line; the first line of a note, cut at 90 characters.+ #[test]+ fn a_header_title_is_the_first_line_cut_short() {+ assert_eq!(one_line(" Reading the code \nmore"), "Reading the code");+ assert_eq!(one_line("\n\nSecond\n"), "Second");+ assert_eq!(one_line(""), "");+ let long = "x".repeat(200);+ let cut = one_line(&long);+ assert_eq!(cut.chars().count(), 91, "90 characters and an ellipsis");+ assert!(cut.ends_with('…'));+ let spaced = format!("{} tail", "a".repeat(89));+ assert_eq!(one_line(&spaced), format!("{}…", "a".repeat(89)), "a cut never leaves a space before the ellipsis");+ }+}diff --git a/crates/ui-egui/tests/smoke.rs b/crates/ui-egui/tests/smoke.rsindex 11609703..bdec9e50 100644--- a/crates/ui-egui/tests/smoke.rs+++ b/crates/ui-egui/tests/smoke.rs@@ -2594,3 +2594,45 @@ fn the_first_frames_callback_runs_once_after_frames_were_shown() {h.run_steps(8);assert_eq!(calls.load(Ordering::SeqCst), 1);}++/// #666: a builder's words with a long decompiled line (a Deep-mode dump, with literal `\n`+/// sequences) stay inside the window instead of running off the feed to the left.+#[test]+fn a_long_line_in_the_builders_words_stays_in_the_window() {+ use craft_anything_ui_egui::state::FeedItem;+ let dump = "local_10b0 = (undefined8 *)0x1;\\n ".repeat(40);+ let text = format!("Decompiled:\n```c\n{dump}\n```\nDone.");+ let mut h = harness(move || {+ let mut a = demo::app(demo::engine(Mode::Beginner, true));+ demo::fill_project(&mut a);+ a.state.feed.push(FeedItem::Agent { text, streaming: false });+ a+ });+ h.run_steps(3);+ let r = h.get_by_label_contains("local_10b0").rect();+ eprintln!("RECT {r:?}");+ assert!(r.min.x >= 0.0 && r.max.x <= 1280.0, "the builder's line leaves the window: {r:?}");+}++/// #666: in Experienced mode, the tool-work rows (their status notes) wrap inside the window too.+#[test]+fn a_long_status_note_in_the_work_rows_stays_in_the_window() {+ use craft_anything_ui_egui::state::FeedItem;+ let note = "local_10b0 = 0;\\n ".repeat(30);+ let mut h = harness(move || {+ let mut a = demo::app(demo::engine(Mode::Experienced, true));+ demo::fill_project(&mut a);+ a.state.feed.push(FeedItem::Work { tools: vec![("ghidra_decompile".into(), Some(true))], notes: vec![format!("first {note}")] });+ a.state.feed.push(FeedItem::Work { tools: Vec::new(), notes: vec![format!("header {note}")] });+ a+ });+ h.run_steps(3);+ let r = h.get_by_label_contains("first local_10b0").rect();+ eprintln!("RECT {r:?}");+ assert!(r.min.x >= 0.0 && r.max.x <= 1280.0, "the note leaves the window: {r:?}");+ for n in h.get_all_by_label_contains("header local_10b0") {+ let r = n.rect();+ eprintln!("HEADER {r:?}");+ assert!(r.min.x >= 0.0 && r.max.x <= 1280.0, "the header leaves the window: {r:?}");+ }+}diff --git a/docs/ROADMAP.md b/docs/ROADMAP.mdindex 3adecd99..5937ef01 100644--- a/docs/ROADMAP.md+++ b/docs/ROADMAP.md@@ -654,6 +654,10 @@ Gaps found while using the app for real projects.- [ ] A question's own cost: a forked Claude Code session reports the whole session's runningtotal, so a forked answer shows none; count questions in the project's usage- [ ] "Make this change" on an answer that suggests one (sends it as a normal message)+- [x] #666: a long line in a feed's tool-work row (a Deep-mode decompile, a status note) ran off+ the window and pushed the feed left; the header title can't wrap in egui, so it's the note's+ first line now, cut at 90 characters, and the full note wraps in the body — claimed: claude,+ branch bugfix/r2.9-feed-text-overflow- [ ] **decision** A program started from the CLI (`project_play`) keeps the shell's output pipeopen, so the command doesn't return until it closes (#207). Every fix found needs `unsafe` oran unstable API: an exception to rule 9, or a limit we document. Meanwhile a reproducing test