Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions gui_common/src/log_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ impl Scrollback {
self.by_level[idx].iter()
}

/// Remove every retained record at all severities.
pub fn clear(&mut self) {
for ring in &mut self.by_level {
ring.clear();
}
}

/// All retained records at or above `min_level`, merged across the
/// per-severity rings **newest first** (so the most recent message renders at
/// the top of the panel). Each ring is appended in arrival order, so iterating
Expand Down Expand Up @@ -338,6 +345,7 @@ impl LogStatusPanel<'_> {
// Opening the tab clears the sticky alert.
self.state.mark_viewed();

let mut clear_clicked = false;
ui.horizontal(|ui| {
// "Show" filters what the panel displays from what's already captured.
ui.label("Show:");
Expand Down Expand Up @@ -367,8 +375,17 @@ impl LogStatusPanel<'_> {
if self.state.capture_level != previous_capture {
log::set_max_level(self.state.capture_level);
}

// "Clear" pins to the right edge of the row.
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
clear_clicked = ui.button("Clear").clicked();
});
});

if clear_clicked {
self.state.scrollback.lock().unwrap().clear();
}

ui.separator();

let scrollback = self.state.scrollback.lock().unwrap();
Expand Down Expand Up @@ -507,6 +524,27 @@ mod tests {
assert_eq!(warns[3].message, "warn 99");
}

#[test]
fn clear_empties_all_severities() {
let now = Local::now();
let mut sb = Scrollback::new(16);
sb.push(rec(Level::Error, "err", now));
sb.push(rec(Level::Warn, "warn", now));
sb.push(rec(Level::Info, "info", now));
assert_eq!(sb.newest_first(LevelFilter::Trace).count(), 3);

sb.clear();

assert_eq!(
sb.newest_first(LevelFilter::Trace).count(),
0,
"clear empties every severity"
);
assert_eq!(sb.level(Level::Error).count(), 0);
assert_eq!(sb.level(Level::Warn).count(), 0);
assert_eq!(sb.level(Level::Info).count(), 0);
}

#[test]
fn newest_first_merges_across_severities() {
let t = |h, m, s| Local.with_ymd_and_hms(2026, 5, 31, h, m, s).unwrap();
Expand Down
Binary file modified gui_common/tests/snapshots/log_status_panel_error_filter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified gui_common/tests/snapshots/log_status_panel_warn_filter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.