A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.
Rust agentagent-orchestrationaiai-agentsclaude-codecodexcoding-agentlinuxmacosmultiplayermultiplexerrustterminalterminal-emulatorterminal-multiplexertmuxtuiweztermwindows
gui: empty the line quad scratch on error returns too
RoversX56449af584a9
diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rsindex bb46509b..3a9fa2d7 100644--- a/wezterm-gui/src/termwindow/mod.rs+++ b/wezterm-gui/src/termwindow/mod.rs@@ -3004,11 +3004,14 @@ impl TermWindow {self.semantic_zones.len(),));lines.push(format!(- "{label}: line_quad_scratch={}KiB (entries are stored at exact size; line_quad above no longer includes doubling slack)",- self.line_quad_scratch- .try_borrow()- .map_or(0, |scratch| scratch.resident_bytes())- / 1024,+ "{label}: line_quad_scratch={} (entries are stored at exact size; line_quad above no longer includes doubling slack)",+ match self.line_quad_scratch.try_borrow() {+ Ok(scratch) => format!("{}KiB", scratch.resident_bytes() / 1024),+ // Only borrowed while a line is being recorded, which never+ // overlaps this report; say so rather than print a 0 that+ // reads as "empty".+ Err(_) => "busy".to_string(),+ },));{let ui = self.ui_shape_caches.borrow();diff --git a/wezterm-gui/src/termwindow/render/paint.rs b/wezterm-gui/src/termwindow/render/paint.rsindex 70b0a3d7..070e72b5 100644--- a/wezterm-gui/src/termwindow/render/paint.rs+++ b/wezterm-gui/src/termwindow/render/paint.rs@@ -923,12 +923,15 @@ impl crate::TermWindow {ui.domain(UiTextDomain::FilePreview).total_weight(),);}- crate::perf::log_counter(- "line_quad_scratch_bytes",- self.line_quad_scratch- .try_borrow()- .map_or(0, |scratch| scratch.resident_bytes()),- );+ // Skipped rather than logged as 0 if a line is+ // somehow still being recorded: a 0 would read+ // as "empty", which is the healthy value.+ if let Ok(scratch) = self.line_quad_scratch.try_borrow() {+ crate::perf::log_counter(+ "line_quad_scratch_bytes",+ scratch.resident_bytes(),+ );+ }if let Some(render_state) = self.render_state.as_ref() {let glyphs = render_state.glyph_cache.borrow();crate::perf::log_counter(diff --git a/wezterm-gui/src/termwindow/render/pane.rs b/wezterm-gui/src/termwindow/render/pane.rsindex d2eb4569..a1f40311 100644--- a/wezterm-gui/src/termwindow/render/pane.rs+++ b/wezterm-gui/src/termwindow/render/pane.rs@@ -131,6 +131,24 @@ const COLLAPSED_SECTION_GAP: usize = 10;/// released rather than pinned for the window's life.const LINE_QUAD_SCRATCH_MAX_BYTES: usize = 512 * 1024;+/// Leaves the line quad scratch recorder empty, and within its size cap,+/// on every way out of `LineRender::render_line` -- the cache insert, the+/// uncached image line and both `?` error returns alike.+struct LineQuadScratchExit<'a>(&'a mut HeapQuadAllocator);++impl Drop for LineQuadScratchExit<'_> {+ fn drop(&mut self) {+ self.0.recycle();+ // The scratch keeps its buffers between lines on purpose, but one+ // unusually wide line must not pin them for the life of the window+ // (only macOS and Windows report the occlusion that otherwise+ // releases it).+ if self.0.resident_bytes() > LINE_QUAD_SCRATCH_MAX_BYTES {+ *self.0 = HeapQuadAllocator::default();+ }+ }+}+impl crate::TermWindow {/// Height of the nav bar for this pane: the metric height, clamped so/// that at least one terminal row of the pane's cell remains visible.@@ -1944,9 +1962,9 @@ impl crate::TermWindow {// Recorded into the window's one scratch recorder and// moved out at exact size below, rather than growing a- // fresh allocator from zero on every miss. Recycled on- // entry as well as on exit, so an early `?` return- // leaves nothing stale for the next line.+ // fresh allocator from zero on every miss. The exit+ // guard empties it on every return, `?` included, so+ // nothing is left stale for the next line.// No painter re-enters this while a line is being// recorded (the only other borrowers run outside a// paint); should one ever do so, that line falls back to@@ -1954,13 +1972,14 @@ impl crate::TermWindow {// which costs the old doubling churn for that line only.let mut scratch_guard = self.term_window.line_quad_scratch.try_borrow_mut();let mut fallback = HeapQuadAllocator::default();- let buf: &mut HeapQuadAllocator = match scratch_guard.as_mut() {+ let scratch_exit = LineQuadScratchExit(match scratch_guard.as_mut() {Ok(scratch) => {scratch.recycle();&mut **scratch}Err(_) => &mut fallback,- };+ });+ let buf: &mut HeapQuadAllocator = &mut *scratch_exit.0;let next_due = self.term_window.has_animation.borrow_mut().take();let shape_key = LineToEleShapeCacheKey {@@ -2066,18 +2085,9 @@ impl crate::TermWindow {.line_quad_cache.borrow_mut().put_weighted(quad_key, quad_value, weight);- } else {- // Not cached: leave the scratch empty rather than- // holding this line's quads until the next miss.- buf.recycle();- }- // The scratch keeps its buffers between lines on purpose,- // but one unusually wide line must not pin them for the- // life of the window (only macOS and Windows report the- // occlusion that otherwise releases it).- if buf.resident_bytes() > LINE_QUAD_SCRATCH_MAX_BYTES {- *buf = HeapQuadAllocator::default();}+ // Not cached (or cached and already moved out): the exit+ // guard empties the scratch and applies the size cap.Ok(())}