From 4705929c74a65af8bae2e84830bc369d7177d002 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Fri, 30 Oct 2026 08:40:29 -0300 Subject: [PATCH 01/10] feat(ui): a Session log view in the History pane (#797, part 2) The History pane gets two views, as Mavrick-F proposed on #1216: Tool runs (the tools run on the project, saved with it, each can run again) and Session log. The log view lists the session's commands newest first (the newest 200 that match, with the count), each with whether it worked, its time (UTC), how long it took, its error and its parameters (on hover in full; right-click copies them), filtered by part of the command's id and to those that failed. Save Log As... writes it through project.exportLog (CSV or JSON Lines by the extension, CSV without one), or downloads it as CSV in the browser; Clear Log and Log Commands run project.clearLog and project.logCommands. The CSV/JSON Lines writer moves unchanged to SessionLog::write, with LogEntry::time_utc, so the download writes what project.exportLog does. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/project.rs | 37 +--- crates/engine/src/project_log.rs | 45 +++++ crates/ui-egui/src/lib.rs | 4 + crates/ui-egui/src/panes.rs | 3 + crates/ui-egui/src/sessionlog.rs | 304 +++++++++++++++++++++++++++++++ docs/user-guide/workspace.md | 9 + 6 files changed, 366 insertions(+), 36 deletions(-) create mode 100644 crates/ui-egui/src/sessionlog.rs diff --git a/crates/engine/src/cmd/project.rs b/crates/engine/src/cmd/project.rs index 7ad9bea8b1..6683361bac 100644 --- a/crates/engine/src/cmd/project.rs +++ b/crates/engine/src/cmd/project.rs @@ -85,13 +85,6 @@ fn log(s: &mut Session, p: &Value) -> CmdResult { Ok(json!({"entries": shown, "count": count, "total": total, "on": s.log.on()})) } -/// A CSV cell: quoted, and kept from being read as a formula where it starts as one does (`=`, -/// `+`, `-`, `@`, or a tab or carriage return before them), as spreadsheets would. -fn csv_cell(t: &str) -> String { - let lead = if t.starts_with(['=', '+', '-', '@', '\t', '\r']) { "'" } else { "" }; - format!("\"{lead}{}\"", t.replace('"', "\"\"")) -} - /// `project.exportLog`: the log written out, as CSV (one row an entry, the parameters as a JSON /// column) or JSON Lines (one entry a line). fn export_log(s: &mut Session, p: &Value) -> CmdResult { @@ -126,39 +119,11 @@ fn export_log(s: &mut Session, p: &Value) -> CmdResult { // Written entry by entry, so a long log isn't held as text first; a failure part way leaves // an existing file as it was. let n = s.log.len(); - rustgis_data::io::write_atomic_with(&path, |w| { - use std::io::Write; - if format == "csv" { - w.write_all(b"time_utc,at,command,ok,millis,error,params\n")?; - } - s.log.entries().try_for_each(|e| write_entry(w, e, format)) - }) - .map_err(|e| format!("{}: {e}", path.display()))?; + rustgis_data::io::write_atomic_with(&path, |w| s.log.write(w, format == "csv")).map_err(|e| format!("{}: {e}", path.display()))?; s.notify(format!("Exported the session log ({n} entries) to {}", path.display()), false); Ok(json!({"path": path.display().to_string(), "entries": n, "format": format})) } -/// Entry `e` as a CSV row or a JSON line, written to `w`. -fn write_entry(w: &mut dyn std::io::Write, e: &crate::project_log::LogEntry, format: &str) -> std::io::Result<()> { - if format == "csv" { - let (date, time) = rustgis_map::graphics::civil(e.at / 1000); - writeln!( - w, - "{date} {time}:{:02},{},{},{},{},{},{}", - (e.at / 1000) % 60, - e.at, - csv_cell(&e.command), - e.ok, - e.millis, - csv_cell(e.error.as_deref().unwrap_or("")), - csv_cell(&e.params.to_string()) - ) - } else { - serde_json::to_writer(&mut *w, e).map_err(std::io::Error::other)?; - w.write_all(b"\n") - } -} - /// `project.clearLog`: empties the log, which then holds this command's own entry, so a cleared /// log says it was cleared. fn clear_log(s: &mut Session, _: &Value) -> CmdResult { diff --git a/crates/engine/src/project_log.rs b/crates/engine/src/project_log.rs index b7dcab5a44..02e945f0da 100644 --- a/crates/engine/src/project_log.rs +++ b/crates/engine/src/project_log.rs @@ -342,6 +342,14 @@ pub struct LogEntry { pub millis: u64, } +impl LogEntry { + /// When it started, as `2026-10-30 14:05:09` (UTC). + pub fn time_utc(&self) -> String { + let (date, time) = rustgis_map::graphics::civil(self.at / 1000); + format!("{date} {time}:{:02}", (self.at / 1000) % 60) + } +} + /// The session's log (#797): one entry for each command run in the session, from any front end /// and in whatever project was open, oldest first. It sits outside the project and its undo /// history: undoing a command doesn't take its entry back, and saving, sharing or packaging a @@ -427,9 +435,46 @@ impl SessionLog { self.entries.is_empty() } + /// Writes the log to `w`, oldest first: as CSV (`csv`: a header, then one row an entry, a + /// readable UTC time first and the parameters as a JSON column) or as JSON Lines (one entry a + /// line). Entry by entry, so a long log isn't held as text first. + pub fn write(&self, w: &mut dyn std::io::Write, csv: bool) -> std::io::Result<()> { + if csv { + w.write_all(b"time_utc,at,command,ok,millis,error,params\n")?; + } + self.entries.iter().try_for_each(|e| write_entry(w, e, csv)) + } + /// Empties the log; how many entries it had. pub fn clear(&mut self) -> usize { self.plugin_entries = 0; std::mem::take(&mut self.entries).len() } } + +/// A CSV cell: quoted, and kept from being read as a formula where it starts as one does (`=`, +/// `+`, `-`, `@`, or a tab or carriage return before them), as spreadsheets would. +fn csv_cell(t: &str) -> String { + let lead = if t.starts_with(['=', '+', '-', '@', '\t', '\r']) { "'" } else { "" }; + format!("\"{lead}{}\"", t.replace('"', "\"\"")) +} + +/// Entry `e` as a CSV row (`csv`) or a JSON line, written to `w`. +fn write_entry(w: &mut dyn std::io::Write, e: &LogEntry, csv: bool) -> std::io::Result<()> { + if csv { + writeln!( + w, + "{},{},{},{},{},{},{}", + e.time_utc(), + e.at, + csv_cell(&e.command), + e.ok, + e.millis, + csv_cell(e.error.as_deref().unwrap_or("")), + csv_cell(&e.params.to_string()) + ) + } else { + serde_json::to_writer(&mut *w, e).map_err(std::io::Error::other)?; + w.write_all(b"\n") + } +} diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index d664a30a73..798abd1149 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -72,6 +72,7 @@ mod scriptcolor; mod scriptcomplete; mod searchbox; mod serviceui; +mod sessionlog; mod shortcutfile; mod shortcutui; mod showme; @@ -690,6 +691,8 @@ pub struct UiState { pub embeddings: embeddingsui::State, /// Data Cubes: the filters, the period, and what the last action said. pub cubes: cubesui::State, + /// The History pane: the tools run or the session log, and the log's filters (#797). + pub session_log: sessionlog::State, /// NASA Earthaccess: the dataset, the granules found and the request under way. pub earthaccess: earthaccessui::State, /// Add From Service › Sign in to ArcGIS. @@ -837,6 +840,7 @@ impl Default for UiState { opendata: Default::default(), embeddings: Default::default(), cubes: Default::default(), + session_log: Default::default(), earthaccess: Default::default(), arcgis: Default::default(), nldi: Default::default(), diff --git a/crates/ui-egui/src/panes.rs b/crates/ui-egui/src/panes.rs index 1b61d62301..51ffca963f 100644 --- a/crates/ui-egui/src/panes.rs +++ b/crates/ui-egui/src/panes.rs @@ -5459,6 +5459,9 @@ fn line_strokes_editor(app: &mut RustGisApp, ui: &mut Ui, l: &rustgis_engine::ma // History and Details fn history(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { + if crate::sessionlog::tabs(app, ui) { + return crate::sessionlog::pane(app, ui, t); + } let hist = app.session.project.gp_history.clone(); if hist.is_empty() { ui.label(egui::RichText::new(tl!("Tools you run appear here.")).color(t.text_dim)); diff --git a/crates/ui-egui/src/sessionlog.rs b/crates/ui-egui/src/sessionlog.rs new file mode 100644 index 0000000000..e77c4671db --- /dev/null +++ b/crates/ui-egui/src/sessionlog.rs @@ -0,0 +1,304 @@ +//! The History pane's session log (opengeos/RustGIS#797, part 2): the commands run in the +//! session, newest first, filtered by command and to those that failed; saved as CSV or JSON +//! Lines; cleared or turned off. It shows the session's log (`Session::log`) as `project.log` +//! gives it, and changes it only through the log's commands, so what the pane does is logged as +//! a script's would be. + +use egui::{CornerRadius, Sense, Stroke, Ui, vec2}; +use rustgis_engine::project_log::LogEntry; +use serde_json::{Value, json}; + +use crate::RustGisApp; +use crate::theme::{Tokens, semibold}; + +/// Most entries the pane lists, the newest: it says how many more match. +pub const SHOWN: usize = 200; + +/// Which list the History pane shows, and the log's filters. +#[derive(Default)] +pub struct State { + /// The session log rather than the tool runs. + pub open: bool, + /// Words the command's id holds (`layer.`, `export`), in any case. + pub query: String, + /// Only the commands that failed. + pub failed: bool, +} + +/// The switch at the top of the History pane, between its two records (named as Mavrick-F +/// proposed on opengeos/RustGIS#1216): the tool runs and the session log; whether the log is the +/// one shown. +pub fn tabs(app: &mut RustGisApp, ui: &mut Ui) -> bool { + ui.horizontal(|ui| { + let s = &mut app.ui.session_log; + ui.selectable_value(&mut s.open, false, tl!("Tool runs")) + .on_hover_text(tl!("The tools run on this project: saved with it, and each can run again")); + ui.selectable_value(&mut s.open, true, tl!("Session log")) + .on_hover_text(tl!("Everything done in this session, from the app, scripts, the AI Assistant or plugins")); + }); + ui.add_space(4.0); + app.ui.session_log.open +} + +/// Whether entry `e` is one the filters keep: `query` already in lower case. +fn kept(e: &LogEntry, query: &str, failed: bool) -> bool { + (!failed || !e.ok) && (query.is_empty() || e.command.to_lowercase().contains(query)) +} + +/// The session log: its filters, its newest entries that match, and what can be done with it. +pub fn pane(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { + ui.horizontal(|ui| { + let s = &mut app.ui.session_log; + ui.add(egui::TextEdit::singleline(&mut s.query).hint_text(tl!("Filter by command")).desired_width(170.0)) + .on_hover_text(tl!("Words in the command's id, such as layer. or export")); + ui.checkbox(&mut s.failed, tl!("Failed only")); + }); + let query = app.ui.session_log.query.trim().to_lowercase(); + let failed = app.ui.session_log.failed; + let (shown, count, total) = app.session.log.select(|e| kept(e, &query, failed), SHOWN); + let note = if total == 0 { + tl!("Commands that change the project, or that name a file, folder or address, appear here.").to_string() + } else if count == 0 { + tl!("No command matches").to_string() + } else if count > shown.len() { + crate::i18n::fmt("The newest {shown} of {count} entries", &[("shown", &shown.len().to_string()), ("count", &count.to_string())]) + } else if count < total { + crate::i18n::fmt("{count} of {total} entries", &[("count", &count.to_string()), ("total", &total.to_string())]) + } else { + crate::i18n::fmt("{count} entries", &[("count", &count.to_string())]) + }; + ui.label(egui::RichText::new(note).size(11.0).color(t.text_dim)); + if !app.session.log.on() { + ui.label(egui::RichText::new(tl!("Logging is off: commands run now aren't recorded.")).size(11.0).color(t.red)); + } + ui.add_space(4.0); + for e in shown.iter().rev() { + row(ui, e, t); + ui.add_space(4.0); + } + ui.horizontal_wrapped(|ui| { + let tip = tl!("The whole log, as CSV or JSON Lines (.jsonl): it may name files and addresses, so look at it before sharing it"); + if ui.add_enabled(total > 0, egui::Button::new(tl!("Save Log As…"))).on_hover_text(tip).clicked() { + save(app); + } + if ui.add_enabled(total > 0, egui::Button::new(tl!("Clear Log"))).clicked() + && let Err(e) = app.run("project.clearLog", Value::Null) + { + app.session.notify(e, true); + } + let mut on = app.session.log.on(); + let tip = tl!("Off, the commands run aren't recorded; what is in the log stays"); + if ui.checkbox(&mut on, tl!("Log Commands")).on_hover_text(tip).changed() + && let Err(e) = app.run("project.logCommands", json!({"on": on})) + { + app.session.notify(e, true); + } + }); +} + +/// One entry: whether it worked, its command, how long it took, when it started, its error and +/// its parameters (all of them on hover; right-click copies them). +fn row(ui: &mut Ui, e: &LogEntry, t: &Tokens) { + let params = match &e.params { + Value::Null => String::new(), + Value::Object(m) if m.is_empty() => String::new(), + p => p.to_string(), + }; + let frame = + egui::Frame::NONE.stroke(Stroke::new(1.0, t.border)).corner_radius(CornerRadius::same(6)).inner_margin(egui::Margin::same(8)); + let r = frame.show(ui, |ui| { + ui.set_width(ui.available_width()); + ui.horizontal(|ui| { + let (r, _) = ui.allocate_exact_size(vec2(10.0, 10.0), Sense::hover()); + ui.painter().circle_filled(r.center(), 4.5, if e.ok { t.green } else { t.red }); + ui.label(egui::RichText::new(&e.command).font(semibold(12.5))); + ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { + ui.label(egui::RichText::new(format!("{} ms", e.millis)).size(11.0).color(t.text_dim)); + }); + }); + ui.label(egui::RichText::new(format!("{} UTC", e.time_utc())).size(11.0).color(t.text_dim)); + if let Some(err) = &e.error { + ui.label(egui::RichText::new(err).size(11.0).color(t.red)); + } + if !params.is_empty() { + // One line in the list; the whole of it (up to the log's 4 KB) on hover. + let line: String = params.chars().take(120).collect(); + let more = if line.len() < params.len() { "…" } else { "" }; + ui.add(egui::Label::new(egui::RichText::new(format!("{line}{more}")).monospace().size(10.5).color(t.text_dim)).truncate()) + .on_hover_text(egui::RichText::new(¶ms).monospace()); + } + }); + r.response.interact(Sense::click()).context_menu(|ui| { + if ui.add_enabled(!params.is_empty(), egui::Button::new(tl!("Copy Parameters"))).clicked() { + ui.ctx().copy_text(params.clone()); + ui.close(); + } + if ui.button(tl!("Copy Command")).clicked() { + ui.ctx().copy_text(e.command.clone()); + ui.close(); + } + }); +} + +/// Saves the log: downloaded as CSV in the browser, where `project.exportLog` can't write a +/// file; else to the CSV or JSON Lines file the user picks, through `project.exportLog`. +fn save(app: &mut RustGisApp) { + if app.services.download.is_some() { + let mut bytes = Vec::new(); + match app.session.log.write(&mut bytes, true) { + Ok(()) => app.download_bytes("session-log.csv", bytes), + Err(e) => app.session.notify(e.to_string(), true), + } + return; + } + let Some(path) = crate::dialogs::pick_save("session-log.csv", &["csv", "jsonl"], tl!("Session log")) else { + // Cancelled: nothing was saved. + return; + }; + // A name typed without an extension is saved as CSV, the first kind offered. + let mut params = json!({"path": path}); + if std::path::Path::new(&path).extension().is_none() { + params["format"] = "csv".into(); + } + if let Err(e) = app.run("project.exportLog", params) { + app.session.notify(e, true); + } +} + +#[cfg(test)] +mod tests { + use super::*; + use egui_kittest::kittest::Queryable; + + fn harness(app: RustGisApp) -> egui_kittest::Harness<'static, RustGisApp> { + let mut fonts = false; + egui_kittest::Harness::builder().with_size(vec2(520.0, 2400.0)).build_ui_state( + move |ui, app: &mut RustGisApp| { + if !fonts { + crate::theme::install_fonts(ui.ctx(), &[], None); + fonts = true; + return; + } + let t = crate::theme::Tokens::light(); + if tabs(app, ui) { + pane(app, ui, &t); + } + }, + app, + ) + } + + /// The History pane's session log lists the session's commands, newest first, filtered by + /// command and to those that failed, and says how many match; reading is left out, as in + /// the log. + #[test] + fn the_session_log_lists_the_commands_run_newest_first() { + let mut app = RustGisApp::with_sample(); + app.session.log.clear(); + app.run("map.new", json!({"name": "Second"})).unwrap(); + assert!(app.run("layer.remove", json!({"layer": 999_999})).is_err()); + app.run("info.project", Value::Null).unwrap(); + app.ui.session_log.open = true; + let mut h = harness(app); + h.run(); + assert!(h.query_by_label("Tool runs").is_some() && h.query_by_label("Session log").is_some(), "the two views, by name"); + assert!(h.query_by_label("2 entries").is_some()); + let y = |h: &egui_kittest::Harness<'_, RustGisApp>, name: &str| h.get_by_label(name).rect().center().y; + assert!(y(&h, "layer.remove") < y(&h, "map.new"), "newest first"); + assert!(h.query_by_label("info.project").is_none(), "reading isn't logged"); + // Its parameters, on one line. + assert!(h.query_by_label(r#"{"name":"Second"}"#).is_some()); + h.state_mut().ui.session_log.failed = true; + h.run(); + assert!(h.query_by_label("1 of 2 entries").is_some()); + assert!(h.query_by_label("map.new").is_none()); + let s = &mut h.state_mut().ui.session_log; + (s.failed, s.query) = (false, "MAP.".into()); + h.run(); + assert!(h.query_by_label("map.new").is_some() && h.query_by_label("layer.remove").is_none()); + h.state_mut().ui.session_log.query = "no such command".into(); + h.run(); + assert!(h.query_by_label("No command matches").is_some()); + // Tool runs shows the tools run instead. + h.state_mut().ui.session_log.open = false; + h.run(); + assert!(h.query_by_label("Filter by command").is_none()); + } + + /// Past [`SHOWN`] entries the pane lists the newest and says how many match. + #[test] + fn a_long_log_shows_its_newest_entries() { + let mut app = RustGisApp::with_sample(); + app.session.log.clear(); + for i in 0..SHOWN + 5 { + app.run("map.new", json!({"name": format!("Map {i}")})).unwrap(); + } + app.ui.session_log.open = true; + let mut h = harness(app); + h.run(); + assert!(h.query_by_label(&format!("The newest {SHOWN} of {} entries", SHOWN + 5)).is_some()); + assert!(h.query_by_label(&format!(r#"{{"name":"Map {}"}}"#, SHOWN + 4)).is_some()); + assert!(h.query_by_label(r#"{"name":"Map 4"}"#).is_none()); + } + + /// Save Log As… writes the log where the user picks, as CSV or JSON Lines by the name's + /// extension (CSV without one), through `project.exportLog`; Clear Log empties it, leaving its + /// own entry; Log Commands turns it off, saying so. + #[test] + fn the_session_log_is_saved_cleared_and_turned_off() { + let mut app = RustGisApp::with_sample(); + app.session.log.clear(); + app.run("map.new", json!({"name": "Second"})).unwrap(); + let dir = tempfile::tempdir().unwrap(); + app.ui.session_log.open = true; + let mut h = harness(app); + h.run(); + for (name, first) in [("log.csv", "time_utc,"), ("log.jsonl", "{\"at\":"), ("log", "time_utc,")] { + let path = dir.path().join(name); + crate::dialogs::PICKED.with(|p| *p.borrow_mut() = Some(path.display().to_string())); + h.get_by_label("Save Log As…").click(); + h.run(); + let text = std::fs::read_to_string(&path).unwrap_or_else(|e| panic!("{name}: {e}")); + assert!(text.starts_with(first), "{name}: {text}"); + assert!(text.contains("map.new"), "{name}"); + } + // Each save is in the log, as a script's would be. + assert_eq!(h.state().session.log.entries().filter(|e| e.command == "project.exportLog").count(), 3); + h.get_by_label("Clear Log").click(); + h.run(); + let commands: Vec = h.state().session.log.entries().map(|e| e.command.clone()).collect(); + assert_eq!(commands, ["project.clearLog"]); + h.get_by_label("Log Commands").click(); + h.run(); + assert!(!h.state().session.log.on()); + assert!(h.query_by_label("Logging is off: commands run now aren't recorded.").is_some()); + h.state_mut().run("map.new", json!({"name": "Third"})).unwrap(); + assert!(h.state().session.log.entries().all(|e| e.command != "map.new")); + } + + /// In the browser, where `project.exportLog` can't write a file, Save Log As… downloads the + /// log as CSV. + #[test] + fn in_the_browser_the_session_log_is_downloaded_as_csv() { + let mut app = RustGisApp::with_sample(); + app.session.log.clear(); + app.run("map.new", json!({"name": "Second"})).unwrap(); + let got = std::rc::Rc::new(std::cell::RefCell::new(None)); + let sink = got.clone(); + app.services.download = Some(Box::new(move |name, bytes| { + *sink.borrow_mut() = Some((name.to_string(), String::from_utf8(bytes).unwrap())); + Ok(()) + })); + save(&mut app); + let (name, text) = got.borrow_mut().take().expect("downloaded"); + assert_eq!(name, "session-log.csv"); + assert!( + text.starts_with( + "time_utc,at,command,ok,millis,error,params +" + ), + "{text}" + ); + assert!(text.contains("\"map.new\",true"), "{text}"); + } +} diff --git a/docs/user-guide/workspace.md b/docs/user-guide/workspace.md index f799d244cd..82adad1524 100644 --- a/docs/user-guide/workspace.md +++ b/docs/user-guide/workspace.md @@ -78,6 +78,15 @@ whether it worked. It is an audit trail of the session, for reviewing work or re run; it runs nothing again (History's Copy as code and recorded tasks do that). Every front end goes into it alike: the app, scripts, the AI Assistant, the command line, Python and MCP. +In the app, the **History** pane has two views: **Tool runs**, the tools run on the project (saved +with it, and each can run again), and **Session log**, which shows the log newest first: each +command with whether it worked, when it started (UTC), how long it took, its error and its +parameters (on one line; all of them on hover, and a right-click copies them). It lists the newest +200 that match and says how many there are; type part of a command's id (`layer.`, `export`) to +filter, or tick **Failed only**. **Save Log As…** writes the whole log as CSV or JSON Lines, as +the name's extension says (CSV without one; in the browser it is downloaded as CSV). **Clear Log** +empties it and **Log Commands** turns it off or on. + - **What goes in:** each command that changes the project, and each that names a file, folder, address or connection, reads included (an export, a download, a save, opening a file), plus undo and redo, with the step they took back or brought back. Reading and looking around within From 0c93bb6b1a38bf8c4130f9204ddbd679a4272fa8 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Mon, 2 Nov 2026 14:34:33 -0300 Subject: [PATCH 02/10] Keep the session log's rows between frames; units through i18n; web save noted - The rows listed, with their parameters as text, are kept in the pane's state while the log's length, its newest entry (SessionLog::newest) and the filters are unchanged, so a repaint doesn't go through the log again. - "{ms} ms" and "{time} UTC" go through i18n::fmt. - The user guide says the browser download isn't itself an entry in the log. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/project_log.rs | 5 +++ crates/ui-egui/src/sessionlog.rs | 61 +++++++++++++++++++++++--------- docs/user-guide/workspace.md | 5 +-- 3 files changed, 53 insertions(+), 18 deletions(-) diff --git a/crates/engine/src/project_log.rs b/crates/engine/src/project_log.rs index 02e945f0da..ae3dc03d8e 100644 --- a/crates/engine/src/project_log.rs +++ b/crates/engine/src/project_log.rs @@ -431,6 +431,11 @@ impl SessionLog { self.entries.len() } + /// The last entry recorded. + pub fn newest(&self) -> Option<&LogEntry> { + self.entries.back() + } + pub fn is_empty(&self) -> bool { self.entries.is_empty() } diff --git a/crates/ui-egui/src/sessionlog.rs b/crates/ui-egui/src/sessionlog.rs index e77c4671db..8665353552 100644 --- a/crates/ui-egui/src/sessionlog.rs +++ b/crates/ui-egui/src/sessionlog.rs @@ -14,6 +14,10 @@ use crate::theme::{Tokens, semibold}; /// Most entries the pane lists, the newest: it says how many more match. pub const SHOWN: usize = 200; +/// What the listed rows were picked from: the log's length and newest entry (which change with +/// each entry, a clear, or the oldest going past the log's limit) and the filters. +type Key = (usize, Option, String, bool); + /// Which list the History pane shows, and the log's filters. #[derive(Default)] pub struct State { @@ -23,6 +27,10 @@ pub struct State { pub query: String, /// Only the commands that failed. pub failed: bool, + /// The rows last listed (entries with their parameters as one line of text) and how many + /// match and are in the log, kept while their [`Key`] holds: the pane is drawn each frame, + /// and picking them goes through the whole log. + cache: Option<(Key, Vec<(LogEntry, String)>, usize, usize)>, } /// The switch at the top of the History pane, between its two records (named as Mavrick-F @@ -55,13 +63,25 @@ pub fn pane(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { }); let query = app.ui.session_log.query.trim().to_lowercase(); let failed = app.ui.session_log.failed; - let (shown, count, total) = app.session.log.select(|e| kept(e, &query, failed), SHOWN); + let key: Key = (app.session.log.len(), app.session.log.newest().cloned(), query, failed); + if app.ui.session_log.cache.as_ref().is_none_or(|c| c.0 != key) { + let (shown, count, total) = app.session.log.select(|e| kept(e, &key.2, key.3), SHOWN); + let rows = shown + .into_iter() + .map(|e| { + let params = params_text(&e); + (e, params) + }) + .collect(); + app.ui.session_log.cache = Some((key, rows, count, total)); + } + let (count, total, listed) = app.ui.session_log.cache.as_ref().map_or((0, 0, 0), |(_, rows, c, t)| (*c, *t, rows.len())); let note = if total == 0 { tl!("Commands that change the project, or that name a file, folder or address, appear here.").to_string() } else if count == 0 { tl!("No command matches").to_string() - } else if count > shown.len() { - crate::i18n::fmt("The newest {shown} of {count} entries", &[("shown", &shown.len().to_string()), ("count", &count.to_string())]) + } else if count > listed { + crate::i18n::fmt("The newest {shown} of {count} entries", &[("shown", &listed.to_string()), ("count", &count.to_string())]) } else if count < total { crate::i18n::fmt("{count} of {total} entries", &[("count", &count.to_string()), ("total", &total.to_string())]) } else { @@ -72,9 +92,11 @@ pub fn pane(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { ui.label(egui::RichText::new(tl!("Logging is off: commands run now aren't recorded.")).size(11.0).color(t.red)); } ui.add_space(4.0); - for e in shown.iter().rev() { - row(ui, e, t); - ui.add_space(4.0); + if let Some((_, rows, ..)) = &app.ui.session_log.cache { + for (e, params) in rows.iter().rev() { + row(ui, e, params, t); + ui.add_space(4.0); + } } ui.horizontal_wrapped(|ui| { let tip = tl!("The whole log, as CSV or JSON Lines (.jsonl): it may name files and addresses, so look at it before sharing it"); @@ -96,14 +118,18 @@ pub fn pane(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { }); } -/// One entry: whether it worked, its command, how long it took, when it started, its error and -/// its parameters (all of them on hover; right-click copies them). -fn row(ui: &mut Ui, e: &LogEntry, t: &Tokens) { - let params = match &e.params { +/// An entry's parameters as one line of JSON: none for no parameters. +fn params_text(e: &LogEntry) -> String { + match &e.params { Value::Null => String::new(), Value::Object(m) if m.is_empty() => String::new(), p => p.to_string(), - }; + } +} + +/// One entry: whether it worked, its command, how long it took, when it started, its error and +/// its parameters, `params` (all of them on hover; right-click copies them). +fn row(ui: &mut Ui, e: &LogEntry, params: &str, t: &Tokens) { let frame = egui::Frame::NONE.stroke(Stroke::new(1.0, t.border)).corner_radius(CornerRadius::same(6)).inner_margin(egui::Margin::same(8)); let r = frame.show(ui, |ui| { @@ -113,10 +139,12 @@ fn row(ui: &mut Ui, e: &LogEntry, t: &Tokens) { ui.painter().circle_filled(r.center(), 4.5, if e.ok { t.green } else { t.red }); ui.label(egui::RichText::new(&e.command).font(semibold(12.5))); ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { - ui.label(egui::RichText::new(format!("{} ms", e.millis)).size(11.0).color(t.text_dim)); + let took = crate::i18n::fmt("{ms} ms", &[("ms", &e.millis.to_string())]); + ui.label(egui::RichText::new(took).size(11.0).color(t.text_dim)); }); }); - ui.label(egui::RichText::new(format!("{} UTC", e.time_utc())).size(11.0).color(t.text_dim)); + let at = crate::i18n::fmt("{time} UTC", &[("time", &e.time_utc())]); + ui.label(egui::RichText::new(at).size(11.0).color(t.text_dim)); if let Some(err) = &e.error { ui.label(egui::RichText::new(err).size(11.0).color(t.red)); } @@ -125,12 +153,12 @@ fn row(ui: &mut Ui, e: &LogEntry, t: &Tokens) { let line: String = params.chars().take(120).collect(); let more = if line.len() < params.len() { "…" } else { "" }; ui.add(egui::Label::new(egui::RichText::new(format!("{line}{more}")).monospace().size(10.5).color(t.text_dim)).truncate()) - .on_hover_text(egui::RichText::new(¶ms).monospace()); + .on_hover_text(egui::RichText::new(params).monospace()); } }); r.response.interact(Sense::click()).context_menu(|ui| { if ui.add_enabled(!params.is_empty(), egui::Button::new(tl!("Copy Parameters"))).clicked() { - ui.ctx().copy_text(params.clone()); + ui.ctx().copy_text(params.to_string()); ui.close(); } if ui.button(tl!("Copy Command")).clicked() { @@ -141,7 +169,8 @@ fn row(ui: &mut Ui, e: &LogEntry, t: &Tokens) { } /// Saves the log: downloaded as CSV in the browser, where `project.exportLog` can't write a -/// file; else to the CSV or JSON Lines file the user picks, through `project.exportLog`. +/// file (so the download isn't itself an entry in the log, said in the user guide); else to the +/// CSV or JSON Lines file the user picks, through `project.exportLog`, which the log records. fn save(app: &mut RustGisApp) { if app.services.download.is_some() { let mut bytes = Vec::new(); diff --git a/docs/user-guide/workspace.md b/docs/user-guide/workspace.md index 82adad1524..76ecd2c221 100644 --- a/docs/user-guide/workspace.md +++ b/docs/user-guide/workspace.md @@ -84,8 +84,9 @@ command with whether it worked, when it started (UTC), how long it took, its err parameters (on one line; all of them on hover, and a right-click copies them). It lists the newest 200 that match and says how many there are; type part of a command's id (`layer.`, `export`) to filter, or tick **Failed only**. **Save Log As…** writes the whole log as CSV or JSON Lines, as -the name's extension says (CSV without one; in the browser it is downloaded as CSV). **Clear Log** -empties it and **Log Commands** turns it off or on. +the name's extension says (CSV without one; in the browser it is downloaded as CSV, and the +download isn't itself an entry in the log, as a saved file is). **Clear Log** empties it and +**Log Commands** turns it off or on. - **What goes in:** each command that changes the project, and each that names a file, folder, address or connection, reads included (an export, a download, a save, opening a file), plus From 1fac74f0597b3b34ead7b4a1ba823c59be40a5f8 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Mon, 2 Nov 2026 15:10:04 -0300 Subject: [PATCH 03/10] Compare the session log's cache key in place, so a repaint allocates nothing The stored key is compared field by field against the log's length, its newest entry (by reference) and the filters as typed; the query is lowercased and the key cloned only when the rows are picked again. The closure's `t` no longer shadows the Tokens. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/sessionlog.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/sessionlog.rs b/crates/ui-egui/src/sessionlog.rs index 8665353552..74bbaf0d66 100644 --- a/crates/ui-egui/src/sessionlog.rs +++ b/crates/ui-egui/src/sessionlog.rs @@ -15,7 +15,8 @@ use crate::theme::{Tokens, semibold}; pub const SHOWN: usize = 200; /// What the listed rows were picked from: the log's length and newest entry (which change with -/// each entry, a clear, or the oldest going past the log's limit) and the filters. +/// each entry, a clear, or the oldest going past the log's limit) and the filters, the query as +/// typed (trimmed). type Key = (usize, Option, String, bool); /// Which list the History pane shows, and the log's filters. @@ -61,11 +62,14 @@ pub fn pane(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { .on_hover_text(tl!("Words in the command's id, such as layer. or export")); ui.checkbox(&mut s.failed, tl!("Failed only")); }); - let query = app.ui.session_log.query.trim().to_lowercase(); - let failed = app.ui.session_log.failed; - let key: Key = (app.session.log.len(), app.session.log.newest().cloned(), query, failed); - if app.ui.session_log.cache.as_ref().is_none_or(|c| c.0 != key) { - let (shown, count, total) = app.session.log.select(|e| kept(e, &key.2, key.3), SHOWN); + // Compared in place, so a repaint that changes nothing allocates and clones nothing; the + // rows are picked again only when the key changed. + let (log, State { query, failed, cache, .. }) = (&app.session.log, &mut app.ui.session_log); + let raw = query.trim(); + let same = cache.as_ref().is_some_and(|(k, ..)| k.0 == log.len() && k.1.as_ref() == log.newest() && k.2 == raw && k.3 == *failed); + if !same { + let lower = raw.to_lowercase(); + let (shown, count, total) = log.select(|e| kept(e, &lower, *failed), SHOWN); let rows = shown .into_iter() .map(|e| { @@ -73,9 +77,9 @@ pub fn pane(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { (e, params) }) .collect(); - app.ui.session_log.cache = Some((key, rows, count, total)); + *cache = Some(((log.len(), log.newest().cloned(), raw.to_string(), *failed), rows, count, total)); } - let (count, total, listed) = app.ui.session_log.cache.as_ref().map_or((0, 0, 0), |(_, rows, c, t)| (*c, *t, rows.len())); + let (count, total, listed) = cache.as_ref().map_or((0, 0, 0), |(_, rows, matched, all)| (*matched, *all, rows.len())); let note = if total == 0 { tl!("Commands that change the project, or that name a file, folder or address, appear here.").to_string() } else if count == 0 { From c87b5cf18fea4e24e1fd878774b0a8d569e39073 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Mon, 2 Nov 2026 15:50:04 -0300 Subject: [PATCH 04/10] Key the session log's rows on its change count; make each row's texts once - SessionLog counts its changes (an entry added, a clear): the pane's cache key is that count and the filters, so an entry equal to the newest one at the log's limit isn't missed. newest() goes. - Each listed row keeps its duration, UTC time and one-line parameters, made when the rows are picked, not on each repaint. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/project_log.rs | 12 +++-- crates/ui-egui/src/sessionlog.rs | 75 +++++++++++++++++++------------- 2 files changed, 53 insertions(+), 34 deletions(-) diff --git a/crates/engine/src/project_log.rs b/crates/engine/src/project_log.rs index ae3dc03d8e..ee44d40b25 100644 --- a/crates/engine/src/project_log.rs +++ b/crates/engine/src/project_log.rs @@ -363,6 +363,9 @@ pub struct SessionLog { /// How many of `entries` are plugins' commands', kept in step with them so a push doesn't /// count them. plugin_entries: usize, + /// Counts each change to `entries` (an entry added, the log cleared), so a view of it knows + /// when to read it again ([`SessionLog::changes`]). + changes: u64, } impl SessionLog { @@ -393,6 +396,7 @@ impl SessionLog { if plugin(&e) { self.plugin_entries += 1; } + self.changes = self.changes.wrapping_add(1); self.entries.push_back(e); while self.entries.len() > LOG_LIMIT { if self.entries.pop_front().is_some_and(|x| plugin(&x)) { @@ -431,9 +435,10 @@ impl SessionLog { self.entries.len() } - /// The last entry recorded. - pub fn newest(&self) -> Option<&LogEntry> { - self.entries.back() + /// How many times the entries have changed (one added, the log cleared): the same number + /// means the same entries. + pub fn changes(&self) -> u64 { + self.changes } pub fn is_empty(&self) -> bool { @@ -453,6 +458,7 @@ impl SessionLog { /// Empties the log; how many entries it had. pub fn clear(&mut self) -> usize { self.plugin_entries = 0; + self.changes = self.changes.wrapping_add(1); std::mem::take(&mut self.entries).len() } } diff --git a/crates/ui-egui/src/sessionlog.rs b/crates/ui-egui/src/sessionlog.rs index 74bbaf0d66..2d709fa963 100644 --- a/crates/ui-egui/src/sessionlog.rs +++ b/crates/ui-egui/src/sessionlog.rs @@ -14,10 +14,34 @@ use crate::theme::{Tokens, semibold}; /// Most entries the pane lists, the newest: it says how many more match. pub const SHOWN: usize = 200; -/// What the listed rows were picked from: the log's length and newest entry (which change with -/// each entry, a clear, or the oldest going past the log's limit) and the filters, the query as -/// typed (trimmed). -type Key = (usize, Option, String, bool); +/// What the listed rows were picked from: the log's [`changes`](rustgis_engine::project_log::SessionLog::changes) +/// and the filters, the query as typed (trimmed). +type Key = (u64, String, bool); + +/// An entry as the pane draws it: its texts made once, when the rows are picked. +struct Row { + e: LogEntry, + /// Its parameters as one line of JSON (none for no parameters), and that line as listed. + params: String, + line: String, + /// How long it took, and when it started. + took: String, + at: String, +} + +impl Row { + fn of(e: LogEntry) -> Row { + let params = params_text(&e); + // One line in the list; the whole of it (up to the log's 4 KB) on hover. + let mut line: String = params.chars().take(120).collect(); + if line.len() < params.len() { + line.push('…'); + } + let took = crate::i18n::fmt("{ms} ms", &[("ms", &e.millis.to_string())]); + let at = crate::i18n::fmt("{time} UTC", &[("time", &e.time_utc())]); + Row { e, params, line, took, at } + } +} /// Which list the History pane shows, and the log's filters. #[derive(Default)] @@ -28,10 +52,9 @@ pub struct State { pub query: String, /// Only the commands that failed. pub failed: bool, - /// The rows last listed (entries with their parameters as one line of text) and how many - /// match and are in the log, kept while their [`Key`] holds: the pane is drawn each frame, - /// and picking them goes through the whole log. - cache: Option<(Key, Vec<(LogEntry, String)>, usize, usize)>, + /// The rows last listed and how many match and are in the log, kept while their [`Key`] + /// holds: the pane is drawn each frame, and picking them goes through the whole log. + cache: Option<(Key, Vec, usize, usize)>, } /// The switch at the top of the History pane, between its two records (named as Mavrick-F @@ -62,22 +85,16 @@ pub fn pane(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { .on_hover_text(tl!("Words in the command's id, such as layer. or export")); ui.checkbox(&mut s.failed, tl!("Failed only")); }); - // Compared in place, so a repaint that changes nothing allocates and clones nothing; the - // rows are picked again only when the key changed. + // Compared in place, so a repaint that changes nothing picks, formats and clones nothing; + // the rows (and their texts) are made again only when the key changed. let (log, State { query, failed, cache, .. }) = (&app.session.log, &mut app.ui.session_log); let raw = query.trim(); - let same = cache.as_ref().is_some_and(|(k, ..)| k.0 == log.len() && k.1.as_ref() == log.newest() && k.2 == raw && k.3 == *failed); + let same = cache.as_ref().is_some_and(|(k, ..)| k.0 == log.changes() && k.1 == raw && k.2 == *failed); if !same { let lower = raw.to_lowercase(); let (shown, count, total) = log.select(|e| kept(e, &lower, *failed), SHOWN); - let rows = shown - .into_iter() - .map(|e| { - let params = params_text(&e); - (e, params) - }) - .collect(); - *cache = Some(((log.len(), log.newest().cloned(), raw.to_string(), *failed), rows, count, total)); + let rows = shown.into_iter().map(Row::of).collect(); + *cache = Some(((log.changes(), raw.to_string(), *failed), rows, count, total)); } let (count, total, listed) = cache.as_ref().map_or((0, 0, 0), |(_, rows, matched, all)| (*matched, *all, rows.len())); let note = if total == 0 { @@ -97,8 +114,8 @@ pub fn pane(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { } ui.add_space(4.0); if let Some((_, rows, ..)) = &app.ui.session_log.cache { - for (e, params) in rows.iter().rev() { - row(ui, e, params, t); + for r in rows.iter().rev() { + row(ui, r, t); ui.add_space(4.0); } } @@ -132,8 +149,9 @@ fn params_text(e: &LogEntry) -> String { } /// One entry: whether it worked, its command, how long it took, when it started, its error and -/// its parameters, `params` (all of them on hover; right-click copies them). -fn row(ui: &mut Ui, e: &LogEntry, params: &str, t: &Tokens) { +/// its parameters (all of them on hover; right-click copies them). +fn row(ui: &mut Ui, item: &Row, t: &Tokens) { + let (e, params) = (&item.e, item.params.as_str()); let frame = egui::Frame::NONE.stroke(Stroke::new(1.0, t.border)).corner_radius(CornerRadius::same(6)).inner_margin(egui::Margin::same(8)); let r = frame.show(ui, |ui| { @@ -143,20 +161,15 @@ fn row(ui: &mut Ui, e: &LogEntry, params: &str, t: &Tokens) { ui.painter().circle_filled(r.center(), 4.5, if e.ok { t.green } else { t.red }); ui.label(egui::RichText::new(&e.command).font(semibold(12.5))); ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { - let took = crate::i18n::fmt("{ms} ms", &[("ms", &e.millis.to_string())]); - ui.label(egui::RichText::new(took).size(11.0).color(t.text_dim)); + ui.label(egui::RichText::new(&item.took).size(11.0).color(t.text_dim)); }); }); - let at = crate::i18n::fmt("{time} UTC", &[("time", &e.time_utc())]); - ui.label(egui::RichText::new(at).size(11.0).color(t.text_dim)); + ui.label(egui::RichText::new(&item.at).size(11.0).color(t.text_dim)); if let Some(err) = &e.error { ui.label(egui::RichText::new(err).size(11.0).color(t.red)); } if !params.is_empty() { - // One line in the list; the whole of it (up to the log's 4 KB) on hover. - let line: String = params.chars().take(120).collect(); - let more = if line.len() < params.len() { "…" } else { "" }; - ui.add(egui::Label::new(egui::RichText::new(format!("{line}{more}")).monospace().size(10.5).color(t.text_dim)).truncate()) + ui.add(egui::Label::new(egui::RichText::new(&item.line).monospace().size(10.5).color(t.text_dim)).truncate()) .on_hover_text(egui::RichText::new(params).monospace()); } }); From e261c99156bc70339b0c94caffd806fbf28dbb3c Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Mon, 2 Nov 2026 16:23:30 -0300 Subject: [PATCH 05/10] Count a step joined to the session log's newest entry as a change join_last replaces the newest entry in place (a held key's nudges); it now bumps the change count, so the History pane's Session log picks its rows again and shows the joined duration and parameters. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/project_log.rs | 2 ++ crates/engine/src/tests.rs | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/crates/engine/src/project_log.rs b/crates/engine/src/project_log.rs index ee44d40b25..5c349a0038 100644 --- a/crates/engine/src/project_log.rs +++ b/crates/engine/src/project_log.rs @@ -413,6 +413,8 @@ impl SessionLog { e.at = last.at; e.millis = last.millis.saturating_add(e.millis); *last = e; + // The newest entry changed: a view of the log reads it again. + self.changes = self.changes.wrapping_add(1); return; } self.push(e); diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index a45eaedab8..379bfb582d 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -21698,6 +21698,13 @@ fn the_session_log_records_each_command_run_in_the_session() { let _ = s.run("project.importQgis", &json!({"text": qgs})); let doc = last(&s); assert_eq!(doc.params["text"], json!(format!("(a document of {} characters)", qgs.chars().count())), "{doc:?}"); + // A step joined to the newest entry (a held key's nudges) is a change too, so a view of the + // log reads it again. + let nudge = |millis| LogEntry { at: 1, command: "layout.nudge".into(), params: json!({"dx": 1}), ok: true, error: None, millis }; + s.log.push(nudge(2)); + let before = s.log.changes(); + s.log.join_last(nudge(3)); + assert!(s.log.changes() != before && last(&s).millis == 5, "{:?}", last(&s)); // So is one after a byte-order mark (a QGIS project read from a file that has one). let marked = format!("\u{feff}{qgs}"); let _ = s.run("project.importQgis", &json!({"text": marked})); From edbe85510cef26937b43f33f76e23a2752553b8d Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Mon, 2 Nov 2026 17:27:14 -0300 Subject: [PATCH 06/10] Count the session log's entries dropped past its limits, and say so SessionLog counts the entries dropped past LOG_LIMIT and LOG_PLUGIN_LIMIT (`dropped`, reset by a clear). The History pane's Session log says "The N oldest entries were dropped past the log's limits", project.exportLog's notice says the saved file lacks them, and the user guide says both give the count. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/project.rs | 7 ++++++- crates/engine/src/project_log.rs | 11 +++++++++++ crates/engine/src/tests.rs | 13 +++++++++++++ crates/ui-egui/src/sessionlog.rs | 6 ++++++ docs/user-guide/workspace.md | 3 ++- 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/project.rs b/crates/engine/src/cmd/project.rs index 6683361bac..891df7426c 100644 --- a/crates/engine/src/cmd/project.rs +++ b/crates/engine/src/cmd/project.rs @@ -120,7 +120,12 @@ fn export_log(s: &mut Session, p: &Value) -> CmdResult { // an existing file as it was. let n = s.log.len(); rustgis_data::io::write_atomic_with(&path, |w| s.log.write(w, format == "csv")).map_err(|e| format!("{}: {e}", path.display()))?; - s.notify(format!("Exported the session log ({n} entries) to {}", path.display()), false); + // Entries dropped past the log's limits aren't in the file: said. + let dropped = match s.log.dropped() { + 0 => String::new(), + d => format!("; the {d} oldest were dropped past the log's limits before it"), + }; + s.notify(format!("Exported the session log ({n} entries) to {}{dropped}", path.display()), false); Ok(json!({"path": path.display().to_string(), "entries": n, "format": format})) } diff --git a/crates/engine/src/project_log.rs b/crates/engine/src/project_log.rs index 5c349a0038..19e3d112d2 100644 --- a/crates/engine/src/project_log.rs +++ b/crates/engine/src/project_log.rs @@ -366,6 +366,9 @@ pub struct SessionLog { /// Counts each change to `entries` (an entry added, the log cleared), so a view of it knows /// when to read it again ([`SessionLog::changes`]). changes: u64, + /// How many entries were dropped past [`LOG_LIMIT`] or [`LOG_PLUGIN_LIMIT`] since the log + /// was last cleared ([`SessionLog::dropped`]), so a view or a saved file can say so. + dropped: u64, } impl SessionLog { @@ -392,6 +395,7 @@ impl SessionLog { { self.entries.remove(oldest); self.plugin_entries = self.plugin_entries.saturating_sub(1); + self.dropped = self.dropped.saturating_add(1); } if plugin(&e) { self.plugin_entries += 1; @@ -402,6 +406,7 @@ impl SessionLog { if self.entries.pop_front().is_some_and(|x| plugin(&x)) { self.plugin_entries = self.plugin_entries.saturating_sub(1); } + self.dropped = self.dropped.saturating_add(1); } } @@ -443,6 +448,11 @@ impl SessionLog { self.changes } + /// How many entries were dropped past the log's limits since it was last cleared. + pub fn dropped(&self) -> u64 { + self.dropped + } + pub fn is_empty(&self) -> bool { self.entries.is_empty() } @@ -460,6 +470,7 @@ impl SessionLog { /// Empties the log; how many entries it had. pub fn clear(&mut self) -> usize { self.plugin_entries = 0; + self.dropped = 0; self.changes = self.changes.wrapping_add(1); std::mem::take(&mut self.entries).len() } diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 379bfb582d..2840c9f561 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -21815,6 +21815,19 @@ fn the_session_log_records_each_command_run_in_the_session() { } assert_eq!(s.log.len(), LOG_LIMIT); assert_eq!(s.log.entries().next().unwrap().at, 5); + // What was dropped is counted, and an export says so; a clear starts the count again. + assert!(s.log.dropped() >= 5, "{}", s.log.dropped()); + let out = std::env::temp_dir().join(format!("rustgis-log-dropped-{}.csv", std::process::id())); + let mark = s.notice_mark(); + s.run("project.exportLog", &json!({"path": out.display().to_string()})).unwrap(); + assert!( + s.notices_since(mark).iter().any(|n| n.text.contains("oldest were dropped past the log's limits")), + "{:?}", + s.notices_since(mark) + ); + let _ = std::fs::remove_file(&out); + s.log.clear(); + assert_eq!(s.log.dropped(), 0); // Undo or redo with nothing to take back changes nothing, and isn't logged. s.clear_history(); let n = s.log.len(); diff --git a/crates/ui-egui/src/sessionlog.rs b/crates/ui-egui/src/sessionlog.rs index 2d709fa963..fc46d23350 100644 --- a/crates/ui-egui/src/sessionlog.rs +++ b/crates/ui-egui/src/sessionlog.rs @@ -109,6 +109,12 @@ pub fn pane(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { crate::i18n::fmt("{count} entries", &[("count", &count.to_string())]) }; ui.label(egui::RichText::new(note).size(11.0).color(t.text_dim)); + // Entries dropped past the log's limits aren't listed, nor saved: said. + let dropped = app.session.log.dropped(); + if dropped > 0 { + let said = crate::i18n::fmt("The {n} oldest entries were dropped past the log's limits", &[("n", &dropped.to_string())]); + ui.label(egui::RichText::new(said).size(11.0).color(t.text_dim)); + } if !app.session.log.on() { ui.label(egui::RichText::new(tl!("Logging is off: commands run now aren't recorded.")).size(11.0).color(t.red)); } diff --git a/docs/user-guide/workspace.md b/docs/user-guide/workspace.md index 76ecd2c221..25ce7b7864 100644 --- a/docs/user-guide/workspace.md +++ b/docs/user-guide/workspace.md @@ -113,7 +113,8 @@ download isn't itself an entry in the log, as a saved file is). **Clear Log** em as plain words, with no name or address form (a password typed into a note), isn't recognised: look at an exported log before sharing it. Each entry's parameters are clipped to about 4 KB of JSON (a long text is cut, a list keeps its first 100 items), its error to 500 characters and a - `…`, and the log keeps its last 10,000 entries, the oldest dropped first. Plugins' commands take + `…`, and the log keeps its last 10,000 entries, the oldest dropped first (the pane and an + export say how many were dropped). Plugins' commands take at most 1,000 of those places: past that, a plugin's new entry pushes out an older plugin entry, not one of the user's. From 2a7d61543c5951c4376bd6134285ca88363a3337 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Mon, 2 Nov 2026 17:50:36 -0300 Subject: [PATCH 07/10] Say the dropped count on a browser download too; test a clean export MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The browser's Save Log As… download says how many of the oldest entries the log dropped past its limits, as the desktop export's notice does. The tests check both ways: nothing said when nothing was dropped. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/tests.rs | 5 +++++ crates/ui-egui/src/sessionlog.rs | 23 ++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 2840c9f561..1c154fd0b5 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -21828,6 +21828,11 @@ fn the_session_log_records_each_command_run_in_the_session() { let _ = std::fs::remove_file(&out); s.log.clear(); assert_eq!(s.log.dropped(), 0); + // A clean export says nothing of it. + let mark = s.notice_mark(); + s.run("project.exportLog", &json!({"path": out.display().to_string()})).unwrap(); + assert!(!s.notices_since(mark).iter().any(|n| n.text.contains("were dropped past")), "{:?}", s.notices_since(mark)); + let _ = std::fs::remove_file(&out); // Undo or redo with nothing to take back changes nothing, and isn't logged. s.clear_history(); let n = s.log.len(); diff --git a/crates/ui-egui/src/sessionlog.rs b/crates/ui-egui/src/sessionlog.rs index fc46d23350..07f12ff849 100644 --- a/crates/ui-egui/src/sessionlog.rs +++ b/crates/ui-egui/src/sessionlog.rs @@ -198,7 +198,19 @@ fn save(app: &mut RustGisApp) { if app.services.download.is_some() { let mut bytes = Vec::new(); match app.session.log.write(&mut bytes, true) { - Ok(()) => app.download_bytes("session-log.csv", bytes), + Ok(()) => { + app.download_bytes("session-log.csv", bytes); + // Entries dropped past the log's limits aren't in the file: said, as an export + // says it on the desktop. + let dropped = app.session.log.dropped(); + if dropped > 0 { + let said = crate::i18n::fmt( + "session-log.csv: the {n} oldest entries were dropped past the log's limits before it", + &[("n", &dropped.to_string())], + ); + app.session.notify(said, false); + } + } Err(e) => app.session.notify(e.to_string(), true), } return; @@ -352,5 +364,14 @@ mod tests { "{text}" ); assert!(text.contains("\"map.new\",true"), "{text}"); + let dropped = |app: &RustGisApp| app.session.notices.iter().any(|n| n.text.contains("dropped past the log's limits")); + assert!(!dropped(&app), "nothing dropped, nothing said"); + // Past the log's limit, the download says how many it lacks. + for i in 0..rustgis_engine::project_log::LOG_LIMIT + 3 { + app.session.log.push(LogEntry { at: i as u64, command: "x".into(), params: Value::Null, ok: true, error: None, millis: 0 }); + } + save(&mut app); + assert!(got.borrow_mut().take().is_some()); + assert!(dropped(&app), "{:?}", app.session.notices); } } From 75947d4cf51a407194f9d030962a8ba1d23d5a6d Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Mon, 2 Nov 2026 18:16:47 -0300 Subject: [PATCH 08/10] Say whether each logged command worked in words; test the pane's dropped note - The status dot says "Worked" or "Failed" on hover and to a screen reader. - a_log_past_its_limit_says_what_it_dropped checks the pane's note past the limit; a clean log shows none. - The browser test's header literal is one line. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/sessionlog.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/sessionlog.rs b/crates/ui-egui/src/sessionlog.rs index 07f12ff849..caa8a98319 100644 --- a/crates/ui-egui/src/sessionlog.rs +++ b/crates/ui-egui/src/sessionlog.rs @@ -163,8 +163,13 @@ fn row(ui: &mut Ui, item: &Row, t: &Tokens) { let r = frame.show(ui, |ui| { ui.set_width(ui.available_width()); ui.horizontal(|ui| { - let (r, _) = ui.allocate_exact_size(vec2(10.0, 10.0), Sense::hover()); + // Worked or failed, said in words too (on hover, and to a screen reader), not by its + // colour alone. + let (r, dot) = ui.allocate_exact_size(vec2(10.0, 10.0), Sense::hover()); ui.painter().circle_filled(r.center(), 4.5, if e.ok { t.green } else { t.red }); + let worked = if e.ok { tl!("Worked") } else { tl!("Failed") }; + dot.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Label, true, worked)); + dot.on_hover_text(worked); ui.label(egui::RichText::new(&e.command).font(semibold(12.5))); ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { ui.label(egui::RichText::new(&item.took).size(11.0).color(t.text_dim)); @@ -303,6 +308,23 @@ mod tests { assert!(h.query_by_label(&format!("The newest {SHOWN} of {} entries", SHOWN + 5)).is_some()); assert!(h.query_by_label(&format!(r#"{{"name":"Map {}"}}"#, SHOWN + 4)).is_some()); assert!(h.query_by_label(r#"{"name":"Map 4"}"#).is_none()); + // Nothing dropped, nothing said; each entry says whether it worked, in words. + assert!(h.query_by_label_contains("dropped past the log's limits").is_none()); + assert!(h.query_all_by_label("Worked").next().is_some()); + } + + /// Past the log's limit, the pane says how many of the oldest entries it dropped. + #[test] + fn a_log_past_its_limit_says_what_it_dropped() { + let mut app = RustGisApp::with_sample(); + app.session.log.clear(); + for i in 0..rustgis_engine::project_log::LOG_LIMIT + 7 { + app.session.log.push(LogEntry { at: i as u64, command: "x".into(), params: Value::Null, ok: true, error: None, millis: 0 }); + } + app.ui.session_log.open = true; + let mut h = harness(app); + h.run(); + assert!(h.query_by_label("The 7 oldest entries were dropped past the log's limits").is_some()); } /// Save Log As… writes the log where the user picks, as CSV or JSON Lines by the name's From 030ec00ae0d81bb21f40fb4bdb7a3b3b0900d36f Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Mon, 2 Nov 2026 18:33:54 -0300 Subject: [PATCH 09/10] Session log tests: draw the History pane as the app does; one-line CSV header check Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/panes.rs | 2 +- crates/ui-egui/src/sessionlog.rs | 16 +++++----------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/crates/ui-egui/src/panes.rs b/crates/ui-egui/src/panes.rs index 51ffca963f..5e1190b9e1 100644 --- a/crates/ui-egui/src/panes.rs +++ b/crates/ui-egui/src/panes.rs @@ -5458,7 +5458,7 @@ fn line_strokes_editor(app: &mut RustGisApp, ui: &mut Ui, l: &rustgis_engine::ma // --------------------------------------------------------------------------------------------- // History and Details -fn history(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { +pub(crate) fn history(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { if crate::sessionlog::tabs(app, ui) { return crate::sessionlog::pane(app, ui, t); } diff --git a/crates/ui-egui/src/sessionlog.rs b/crates/ui-egui/src/sessionlog.rs index caa8a98319..240bcc786a 100644 --- a/crates/ui-egui/src/sessionlog.rs +++ b/crates/ui-egui/src/sessionlog.rs @@ -248,10 +248,9 @@ mod tests { fonts = true; return; } + // The History pane as the app draws it: its two views. let t = crate::theme::Tokens::light(); - if tabs(app, ui) { - pane(app, ui, &t); - } + crate::panes::history(app, ui, &t); }, app, ) @@ -288,10 +287,11 @@ mod tests { h.state_mut().ui.session_log.query = "no such command".into(); h.run(); assert!(h.query_by_label("No command matches").is_some()); - // Tool runs shows the tools run instead. + // Tool runs shows the tools run instead (none here). h.state_mut().ui.session_log.open = false; h.run(); assert!(h.query_by_label("Filter by command").is_none()); + assert!(h.query_by_label("Tools you run appear here.").is_some()); } /// Past [`SHOWN`] entries the pane lists the newest and says how many match. @@ -378,13 +378,7 @@ mod tests { save(&mut app); let (name, text) = got.borrow_mut().take().expect("downloaded"); assert_eq!(name, "session-log.csv"); - assert!( - text.starts_with( - "time_utc,at,command,ok,millis,error,params -" - ), - "{text}" - ); + assert!(text.starts_with("time_utc,at,command,ok,millis,error,params\n"), "{text}"); assert!(text.contains("\"map.new\",true"), "{text}"); let dropped = |app: &RustGisApp| app.session.notices.iter().any(|n| n.text.contains("dropped past the log's limits")); assert!(!dropped(&app), "nothing dropped, nothing said"); From a8080dbf8b98a38eadc62b567bd454849fd99645 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Tue, 3 Nov 2026 00:54:29 -0300 Subject: [PATCH 10/10] Session log: name dropped entries by kind; keep row hover texts - The log counts drops past LOG_LIMIT and past the plugins' limit apart, and one wording (SessionLog::dropped_said) serves the pane, the export and the browser download. - The browser save says what the file lacks only when the download was delivered (download_bytes returns whether it was). - A row's right-click is sensed behind its contents, so the Worked dot's and the parameters' hover texts show; the row's labels aren't selectable, so a right-click on them still opens the menu. - One entry reads "1 entry". Tests for a populated Tool runs view, a joined entry in the view, the exact drop count and hover/right-click. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/project.rs | 5 +- crates/engine/src/project_log.rs | 27 +++++- crates/engine/src/tests.rs | 4 +- crates/ui-egui/src/lib.rs | 7 +- crates/ui-egui/src/sessionlog.rs | 160 +++++++++++++++++++++++-------- docs/user-guide/workspace.md | 2 +- 6 files changed, 153 insertions(+), 52 deletions(-) diff --git a/crates/engine/src/cmd/project.rs b/crates/engine/src/cmd/project.rs index 891df7426c..62afab9ae5 100644 --- a/crates/engine/src/cmd/project.rs +++ b/crates/engine/src/cmd/project.rs @@ -121,10 +121,7 @@ fn export_log(s: &mut Session, p: &Value) -> CmdResult { let n = s.log.len(); rustgis_data::io::write_atomic_with(&path, |w| s.log.write(w, format == "csv")).map_err(|e| format!("{}: {e}", path.display()))?; // Entries dropped past the log's limits aren't in the file: said. - let dropped = match s.log.dropped() { - 0 => String::new(), - d => format!("; the {d} oldest were dropped past the log's limits before it"), - }; + let dropped = s.log.dropped_said().map(|d| format!("; not in it: {d}")).unwrap_or_default(); s.notify(format!("Exported the session log ({n} entries) to {}{dropped}", path.display()), false); Ok(json!({"path": path.display().to_string(), "entries": n, "format": format})) } diff --git a/crates/engine/src/project_log.rs b/crates/engine/src/project_log.rs index 19e3d112d2..12ac74c07a 100644 --- a/crates/engine/src/project_log.rs +++ b/crates/engine/src/project_log.rs @@ -366,9 +366,11 @@ pub struct SessionLog { /// Counts each change to `entries` (an entry added, the log cleared), so a view of it knows /// when to read it again ([`SessionLog::changes`]). changes: u64, - /// How many entries were dropped past [`LOG_LIMIT`] or [`LOG_PLUGIN_LIMIT`] since the log - /// was last cleared ([`SessionLog::dropped`]), so a view or a saved file can say so. + /// How many entries were dropped since the log was last cleared, so a view or a saved file + /// can say so ([`SessionLog::dropped_said`]): the oldest, past [`LOG_LIMIT`], and older plugin + /// commands' (newer than some of the user's still kept), past [`LOG_PLUGIN_LIMIT`]. dropped: u64, + dropped_plugin: u64, } impl SessionLog { @@ -395,7 +397,7 @@ impl SessionLog { { self.entries.remove(oldest); self.plugin_entries = self.plugin_entries.saturating_sub(1); - self.dropped = self.dropped.saturating_add(1); + self.dropped_plugin = self.dropped_plugin.saturating_add(1); } if plugin(&e) { self.plugin_entries += 1; @@ -450,7 +452,23 @@ impl SessionLog { /// How many entries were dropped past the log's limits since it was last cleared. pub fn dropped(&self) -> u64 { - self.dropped + self.dropped.saturating_add(self.dropped_plugin) + } + + /// What was dropped past the log's limits since it was last cleared, by kind, as the pane, an + /// export and a download say it; `None` when nothing was. + pub fn dropped_said(&self) -> Option { + let mut said = Vec::new(); + if self.dropped > 0 { + said.push(format!("{} oldest entries were dropped past the log's limit of {LOG_LIMIT}", self.dropped)); + } + if self.dropped_plugin > 0 { + said.push(format!( + "{} older plugin command entries were dropped past the {LOG_PLUGIN_LIMIT} kept for plugins", + self.dropped_plugin + )); + } + (!said.is_empty()).then(|| said.join("; ")) } pub fn is_empty(&self) -> bool { @@ -471,6 +489,7 @@ impl SessionLog { pub fn clear(&mut self) -> usize { self.plugin_entries = 0; self.dropped = 0; + self.dropped_plugin = 0; self.changes = self.changes.wrapping_add(1); std::mem::take(&mut self.entries).len() } diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 1c154fd0b5..e93935bf2c 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -21821,7 +21821,9 @@ fn the_session_log_records_each_command_run_in_the_session() { let mark = s.notice_mark(); s.run("project.exportLog", &json!({"path": out.display().to_string()})).unwrap(); assert!( - s.notices_since(mark).iter().any(|n| n.text.contains("oldest were dropped past the log's limits")), + s.notices_since(mark) + .iter() + .any(|n| n.text.contains("; not in it: ") && n.text.contains("oldest entries were dropped past the log's limit of 10000")), "{:?}", s.notices_since(mark) ); diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 798abd1149..651cbfd998 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -1515,9 +1515,10 @@ impl RustGisApp { Ok(()) } - /// Offers bytes as a download (web). - pub(crate) fn download_bytes(&mut self, name: &str, bytes: Vec) { - self.download(name, bytes); + /// Offers bytes as a download (web), and says whether it was delivered (a failure is + /// notified). + pub(crate) fn download_bytes(&mut self, name: &str, bytes: Vec) -> bool { + self.download(name, bytes) } /// Offers bytes as a download (web) and reports whether a download hook exists. diff --git a/crates/ui-egui/src/sessionlog.rs b/crates/ui-egui/src/sessionlog.rs index 240bcc786a..1da4562c77 100644 --- a/crates/ui-egui/src/sessionlog.rs +++ b/crates/ui-egui/src/sessionlog.rs @@ -105,14 +105,14 @@ pub fn pane(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { crate::i18n::fmt("The newest {shown} of {count} entries", &[("shown", &listed.to_string()), ("count", &count.to_string())]) } else if count < total { crate::i18n::fmt("{count} of {total} entries", &[("count", &count.to_string()), ("total", &total.to_string())]) + } else if count == 1 { + tl!("1 entry").to_string() } else { crate::i18n::fmt("{count} entries", &[("count", &count.to_string())]) }; ui.label(egui::RichText::new(note).size(11.0).color(t.text_dim)); // Entries dropped past the log's limits aren't listed, nor saved: said. - let dropped = app.session.log.dropped(); - if dropped > 0 { - let said = crate::i18n::fmt("The {n} oldest entries were dropped past the log's limits", &[("n", &dropped.to_string())]); + if let Some(said) = app.session.log.dropped_said() { ui.label(egui::RichText::new(said).size(11.0).color(t.text_dim)); } if !app.session.log.on() { @@ -155,36 +155,41 @@ fn params_text(e: &LogEntry) -> String { } /// One entry: whether it worked, its command, how long it took, when it started, its error and -/// its parameters (all of them on hover; right-click copies them). +/// its parameters (all of them on hover; right-click copies them). The right-click is sensed +/// behind the row's contents, which only sense hover, so their hover texts still show. fn row(ui: &mut Ui, item: &Row, t: &Tokens) { let (e, params) = (&item.e, item.params.as_str()); let frame = egui::Frame::NONE.stroke(Stroke::new(1.0, t.border)).corner_radius(CornerRadius::same(6)).inner_margin(egui::Margin::same(8)); - let r = frame.show(ui, |ui| { - ui.set_width(ui.available_width()); - ui.horizontal(|ui| { - // Worked or failed, said in words too (on hover, and to a screen reader), not by its - // colour alone. - let (r, dot) = ui.allocate_exact_size(vec2(10.0, 10.0), Sense::hover()); - ui.painter().circle_filled(r.center(), 4.5, if e.ok { t.green } else { t.red }); - let worked = if e.ok { tl!("Worked") } else { tl!("Failed") }; - dot.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Label, true, worked)); - dot.on_hover_text(worked); - ui.label(egui::RichText::new(&e.command).font(semibold(12.5))); - ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { - ui.label(egui::RichText::new(&item.took).size(11.0).color(t.text_dim)); + let r = ui.scope_builder(egui::UiBuilder::new().sense(Sense::click()), |ui| { + frame.show(ui, |ui| { + ui.set_width(ui.available_width()); + ui.horizontal(|ui| { + // Worked or failed, said in words too (on hover, and to a screen reader), not by its + // colour alone. + let (r, dot) = ui.allocate_exact_size(vec2(10.0, 10.0), Sense::hover()); + ui.painter().circle_filled(r.center(), 4.5, if e.ok { t.green } else { t.red }); + let worked = if e.ok { tl!("Worked") } else { tl!("Failed") }; + dot.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Label, true, worked)); + dot.on_hover_text(worked); + text(ui, egui::RichText::new(&e.command).font(semibold(12.5))); + ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { + text(ui, egui::RichText::new(&item.took).size(11.0).color(t.text_dim)); + }); }); - }); - ui.label(egui::RichText::new(&item.at).size(11.0).color(t.text_dim)); - if let Some(err) = &e.error { - ui.label(egui::RichText::new(err).size(11.0).color(t.red)); - } - if !params.is_empty() { - ui.add(egui::Label::new(egui::RichText::new(&item.line).monospace().size(10.5).color(t.text_dim)).truncate()) + text(ui, egui::RichText::new(&item.at).size(11.0).color(t.text_dim)); + if let Some(err) = &e.error { + text(ui, egui::RichText::new(err).size(11.0).color(t.red)); + } + if !params.is_empty() { + ui.add( + egui::Label::new(egui::RichText::new(&item.line).monospace().size(10.5).color(t.text_dim)).truncate().selectable(false), + ) .on_hover_text(egui::RichText::new(params).monospace()); - } + } + }) }); - r.response.interact(Sense::click()).context_menu(|ui| { + r.response.context_menu(|ui| { if ui.add_enabled(!params.is_empty(), egui::Button::new(tl!("Copy Parameters"))).clicked() { ui.ctx().copy_text(params.to_string()); ui.close(); @@ -196,6 +201,11 @@ fn row(ui: &mut Ui, item: &Row, t: &Tokens) { }); } +/// A row's text: not selectable, so a right-click on it reaches the row. +fn text(ui: &mut Ui, t: egui::RichText) { + ui.add(egui::Label::new(t).selectable(false)); +} + /// Saves the log: downloaded as CSV in the browser, where `project.exportLog` can't write a /// file (so the download isn't itself an entry in the log, said in the user guide); else to the /// CSV or JSON Lines file the user picks, through `project.exportLog`, which the log records. @@ -204,16 +214,12 @@ fn save(app: &mut RustGisApp) { let mut bytes = Vec::new(); match app.session.log.write(&mut bytes, true) { Ok(()) => { - app.download_bytes("session-log.csv", bytes); // Entries dropped past the log's limits aren't in the file: said, as an export - // says it on the desktop. - let dropped = app.session.log.dropped(); - if dropped > 0 { - let said = crate::i18n::fmt( - "session-log.csv: the {n} oldest entries were dropped past the log's limits before it", - &[("n", &dropped.to_string())], - ); - app.session.notify(said, false); + // says it on the desktop (not of a download that failed, which says why). + if app.download_bytes("session-log.csv", bytes) + && let Some(said) = app.session.log.dropped_said() + { + app.session.notify(format!("session-log.csv: not in it: {said}"), false); } } Err(e) => app.session.notify(e.to_string(), true), @@ -287,11 +293,43 @@ mod tests { h.state_mut().ui.session_log.query = "no such command".into(); h.run(); assert!(h.query_by_label("No command matches").is_some()); - // Tool runs shows the tools run instead (none here). + // Tool runs shows the tools run instead: none here, then one. h.state_mut().ui.session_log.open = false; h.run(); assert!(h.query_by_label("Filter by command").is_none()); assert!(h.query_by_label("Tools you run appear here.").is_some()); + h.state_mut().session.project.gp_history.push(rustgis_engine::GpRecord { + tool: "Buffer".into(), + id: "buffer".into(), + params: json!({}), + command: None, + at: 0, + ok: true, + messages: vec!["Made 3 features".into()], + millis: 7, + outputs: Vec::new(), + }); + h.run(); + assert!(h.query_by_label("Buffer").is_some() && h.query_by_label("Made 3 features").is_some()); + assert!(h.query_by_label("Tools you run appear here.").is_none()); + } + + /// A step joined to the newest entry (a held key's nudges) shows in the pane at once, though + /// the log's length is the same. + #[test] + fn a_joined_entry_is_shown_as_it_is_now() { + let mut app = RustGisApp::with_sample(); + app.session.log.clear(); + let nudge = |millis| LogEntry { at: 1, command: "layout.nudge".into(), params: json!({"dx": 1}), ok: true, error: None, millis }; + app.session.log.push(nudge(2)); + app.ui.session_log.open = true; + let mut h = harness(app); + h.run(); + assert!(h.query_by_label("2 ms").is_some()); + h.state_mut().session.log.join_last(nudge(3)); + h.run(); + assert!(h.query_by_label("5 ms").is_some() && h.query_by_label("2 ms").is_none()); + assert!(h.query_by_label("1 entry").is_some()); } /// Past [`SHOWN`] entries the pane lists the newest and says how many match. @@ -309,7 +347,7 @@ mod tests { assert!(h.query_by_label(&format!(r#"{{"name":"Map {}"}}"#, SHOWN + 4)).is_some()); assert!(h.query_by_label(r#"{"name":"Map 4"}"#).is_none()); // Nothing dropped, nothing said; each entry says whether it worked, in words. - assert!(h.query_by_label_contains("dropped past the log's limits").is_none()); + assert!(h.query_by_label_contains("were dropped past").is_none()); assert!(h.query_all_by_label("Worked").next().is_some()); } @@ -324,7 +362,16 @@ mod tests { app.ui.session_log.open = true; let mut h = harness(app); h.run(); - assert!(h.query_by_label("The 7 oldest entries were dropped past the log's limits").is_some()); + assert!(h.query_by_label("7 oldest entries were dropped past the log's limit of 10000").is_some()); + // Past the plugins' limit, an older plugin command's entry goes, and is said as that. + let app = h.state_mut(); + app.session.log.clear(); + for i in 0..rustgis_engine::project_log::LOG_PLUGIN_LIMIT + 2 { + let command = format!("{}eng/f", rustgis_plugins::PREFIX); + app.session.log.push(LogEntry { at: i as u64, command, params: Value::Null, ok: true, error: None, millis: 0 }); + } + h.run(); + assert!(h.query_by_label("2 older plugin command entries were dropped past the 1000 kept for plugins").is_some()); } /// Save Log As… writes the log where the user picks, as CSV or JSON Lines by the name's @@ -380,7 +427,9 @@ mod tests { assert_eq!(name, "session-log.csv"); assert!(text.starts_with("time_utc,at,command,ok,millis,error,params\n"), "{text}"); assert!(text.contains("\"map.new\",true"), "{text}"); - let dropped = |app: &RustGisApp| app.session.notices.iter().any(|n| n.text.contains("dropped past the log's limits")); + let dropped = |app: &RustGisApp| { + app.session.notices.iter().any(|n| n.text.contains("session-log.csv: not in it: 4 oldest entries were dropped past")) + }; assert!(!dropped(&app), "nothing dropped, nothing said"); // Past the log's limit, the download says how many it lacks. for i in 0..rustgis_engine::project_log::LOG_LIMIT + 3 { @@ -389,5 +438,38 @@ mod tests { save(&mut app); assert!(got.borrow_mut().take().is_some()); assert!(dropped(&app), "{:?}", app.session.notices); + // A download that fails says why, not what a file it didn't deliver lacks. + app.session.notices.clear(); + app.services.download = Some(Box::new(|_, _| Err("no room".into()))); + save(&mut app); + assert!(app.session.notices.iter().any(|n| n.text.contains("no room")), "{:?}", app.session.notices); + assert!(!dropped(&app), "{:?}", app.session.notices); + } + + /// The row's right-click doesn't cover its hover texts (whether it worked, and the whole of + /// its parameters), and works on its text too. + #[test] + fn a_rows_hover_texts_show_under_its_context_menu() { + let mut app = RustGisApp::with_sample(); + app.session.log.clear(); + let long = "n".repeat(200); + app.run("map.new", json!({"name": long})).unwrap(); + app.ui.session_log.open = true; + let mut h = harness(app); + h.run(); + let line = format!(r#"{{"name":"{}"#, "n".repeat(20)); + h.get_by_label_contains(&line).hover(); + h.run(); + h.run(); + let whole = format!(r#"{{"name":"{long}"}}"#); + assert!(h.query_by_label(&whole).is_some(), "the whole parameters on hover"); + h.get_by_label("Worked").hover(); + h.run(); + h.run(); + assert!(h.query_all_by_label("Worked").count() > 1, "the dot's hover text"); + // A right-click on the row's text still opens its menu. + h.get_by_label("map.new").click_secondary(); + h.run(); + assert!(h.query_by_label("Copy Command").is_some()); } } diff --git a/docs/user-guide/workspace.md b/docs/user-guide/workspace.md index 25ce7b7864..99877df2d6 100644 --- a/docs/user-guide/workspace.md +++ b/docs/user-guide/workspace.md @@ -114,7 +114,7 @@ download isn't itself an entry in the log, as a saved file is). **Clear Log** em look at an exported log before sharing it. Each entry's parameters are clipped to about 4 KB of JSON (a long text is cut, a list keeps its first 100 items), its error to 500 characters and a `…`, and the log keeps its last 10,000 entries, the oldest dropped first (the pane and an - export say how many were dropped). Plugins' commands take + export say how many were dropped, and which: the oldest, or older plugin entries). Plugins' commands take at most 1,000 of those places: past that, a plugin's new entry pushes out an older plugin entry, not one of the user's.