Skip to content

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.

Account the render caches by bytes, not entries

RoversX26ac5607f13e
diff --git a/scripts/mem-baseline.sh b/scripts/mem-baseline.sh
new file mode 100755
index 00000000..7609a3fd
--- /dev/null
+++ b/scripts/mem-baseline.sh
@@ -0,0 +1,57 @@
+#!/bin/sh
+# Snapshot the memory of a running thinkterm-gui so before/after numbers for
+# memory work come from the same probe every time.
+#
+# Usage: scripts/mem-baseline.sh [label]
+# Env: MEM_BASELINE_LOG append target (default: ./mem-baseline.log)
+# MEM_BASELINE_PID pid override (default: newest thinkterm-gui)
+#
+# Suggested scenario, one invocation per step so runs stay comparable:
+# 1. fresh-start (launch, one window, no output yet)
+# 2. windows-open (open the usual number of windows/panes)
+# 3. after-scroll (seq 1 100000 in one pane)
+# 4. overview-closed (open Live Overview, close it again)
+# 5. all-occluded (cover/minimize every window, wait ~2 min)
+#
+# The in-app view of the same story (per-cache byte totals, atlas size,
+# quad_capacity) lives in Settings -> memory; capture it alongside if the
+# per-window split matters for the step.
+
+set -eu
+
+label="${1:-snapshot}"
+log="${MEM_BASELINE_LOG:-mem-baseline.log}"
+pid="${MEM_BASELINE_PID:-$(pgrep -nx thinkterm-gui || true)}"
+
+if [ -z "$pid" ]; then
+ echo "mem-baseline: no running thinkterm-gui" >&2
+ exit 1
+fi
+
+{
+ echo "=== ${label} | pid ${pid} | $(date '+%Y-%m-%d %H:%M:%S') ==="
+
+ footprint "$pid" 2>/dev/null \
+ | grep 'phys_footprint' \
+ | sed 's/^ */ /'
+
+ echo "--- footprint dirty, top categories ---"
+ footprint "$pid" 2>/dev/null \
+ | sed -n '/^ Dirty/,/^ *TOTAL/p' \
+ | grep -v '^ *---' \
+ | head -12 \
+ | sed 's/^/ /'
+
+ echo "--- vmmap key regions (virtual/resident/dirty/swapped) ---"
+ vmmap --summary "$pid" 2>/dev/null \
+ | sed '/^MALLOC ZONE/,$d' \
+ | grep -E '^(MALLOC_(TINY|SMALL|LARGE) |IOSurface|IOAccelerator \(graphics\)|owned unmapped \(graphics\)|TOTAL)' \
+ | sed 's/^/ /'
+
+ echo "--- malloc zones (allocated vs dirty+swap gap = fragmentation) ---"
+ vmmap --summary "$pid" 2>/dev/null \
+ | sed -n '/^MALLOC ZONE/,$p' \
+ | sed 's/^/ /'
+
+ echo
+} | tee -a "$log"
diff --git a/wezterm-gui/src/quad.rs b/wezterm-gui/src/quad.rs
index bd916106..1c16f8cf 100644
--- a/wezterm-gui/src/quad.rs
+++ b/wezterm-gui/src/quad.rs
@@ -768,6 +768,15 @@ impl HeapQuadAllocator {
self.position_transform = None;
}
+ /// Estimated resident heap bytes for the recorded quads. Counts vector
+ /// capacity, not length: a buffer that grew during recording keeps that
+ /// allocation until it is dropped, and capacity is what a byte-accounted
+ /// cache needs to know about.
+ pub fn resident_bytes(&self) -> usize {
+ (self.layer0.capacity() + self.layer1.capacity() + self.layer2.capacity())
+ .saturating_mul(std::mem::size_of::<BoxedQuad>())
+ }
+
/// Where the next quad will land, for later use with [`Self::apply_before`],
/// [`Self::apply_between`] and [`Self::apply_after`].
pub fn mark(&self) -> HeapQuadMark {
diff --git a/wezterm-gui/src/termwindow/box_model.rs b/wezterm-gui/src/termwindow/box_model.rs
index a9fcb2ef..3c5392e5 100644
--- a/wezterm-gui/src/termwindow/box_model.rs
+++ b/wezterm-gui/src/termwindow/box_model.rs
@@ -607,7 +607,11 @@ impl super::TermWindow {
let direction = wezterm_bidi::Direction::LeftToRight;
let infos = element.font.shape(
&s,
- move |chars: &[char]| window.notify(TermWindowNotif::InvalidateShapeCacheForChars(chars.to_vec())),
+ move |chars: &[char]| {
+ window.notify(TermWindowNotif::InvalidateShapeCacheForChars(
+ chars.to_vec(),
+ ))
+ },
BlockKey::filter_out_synthetic,
element.presentation,
direction,
diff --git a/wezterm-gui/src/termwindow/live_overview.rs b/wezterm-gui/src/termwindow/live_overview.rs
index 7d199d75..0d864ed8 100644
--- a/wezterm-gui/src/termwindow/live_overview.rs
+++ b/wezterm-gui/src/termwindow/live_overview.rs
@@ -369,7 +369,8 @@ impl LiveOverviewView {
// Extremely narrow/tall terminals still need a useful overview;
// within this safety range every card keeps the exact same host
// aspect instead of inheriting a source mux tab's split geometry.
- host_preview_aspect: host_preview_aspect.clamp(HOST_PREVIEW_ASPECT_MIN, HOST_PREVIEW_ASPECT_MAX),
+ host_preview_aspect: host_preview_aspect
+ .clamp(HOST_PREVIEW_ASPECT_MIN, HOST_PREVIEW_ASPECT_MAX),
scroll: ScrollState::new(),
revealed_active: false,
last_ui_scale: 1.0,
@@ -754,12 +755,12 @@ impl LiveOverviewView {
gap,
);
seen_keys.insert(card.key.clone());
- let rect = self
- .settle_card_rect(&card.key, target, now)
- .translate(euclid::vec2(
- 0.0,
- self.viewport.origin.y - self.scroll.offset,
- ));
+ let rect =
+ self.settle_card_rect(&card.key, target, now)
+ .translate(euclid::vec2(
+ 0.0,
+ self.viewport.origin.y - self.scroll.offset,
+ ));
// Keep one complete row warm above and below the viewport
// so a scroll does not reveal an uncaptured thumbnail. All
@@ -881,8 +882,9 @@ impl LiveOverviewView {
// Only once the name of the thread has been given
// its space: which terminal this is comes first,
// what it is doing second.
- let title_width =
- ctx.measure_text_width(card_font, &card.title).min(text_limit);
+ let title_width = ctx
+ .measure_text_width(card_font, &card.title)
+ .min(text_limit);
let running_x = text_x + title_width + ctx.px(RUNNING_LABEL_GAP);
let running_limit = text_x + text_limit - running_x;
if running_limit >= ctx.px(RUNNING_LABEL_MIN_WIDTH) {
@@ -1592,7 +1594,8 @@ impl ContentView for LiveOverviewView {
fn set_host_preview_aspect(&mut self, aspect: f32) {
if aspect.is_finite() && aspect > 0.0 {
- self.host_preview_aspect = aspect.clamp(HOST_PREVIEW_ASPECT_MIN, HOST_PREVIEW_ASPECT_MAX);
+ self.host_preview_aspect =
+ aspect.clamp(HOST_PREVIEW_ASPECT_MIN, HOST_PREVIEW_ASPECT_MAX);
}
}
@@ -2590,7 +2593,8 @@ mod tests {
let layouts = reveal_layout(2, 3, 300.0);
let groups = vec![live_group_with_active(6, 5)];
// Three rows of 300 separated by a 16 gap, below a 40px heading.
- view.scroll.set_extents(400.0, 40.0 + 3.0 * 300.0 + 2.0 * 16.0);
+ view.scroll
+ .set_extents(400.0, 40.0 + 3.0 * 300.0 + 2.0 * 16.0);
let offset = view
.offset_revealing_active(&groups, &layouts, 0.0, 1000.0, 16.0)
@@ -2605,7 +2609,8 @@ mod tests {
view.viewport = euclid::rect(0.0, 0.0, 1000.0, 400.0);
let layouts = reveal_layout(1, 10, 100.0);
let groups = vec![live_group_with_active(10, 4)];
- view.scroll.set_extents(400.0, 40.0 + 10.0 * 100.0 + 9.0 * 16.0);
+ view.scroll
+ .set_extents(400.0, 40.0 + 10.0 * 100.0 + 9.0 * 16.0);
let offset = view
.offset_revealing_active(&groups, &layouts, 0.0, 1000.0, 16.0)
@@ -2621,7 +2626,8 @@ mod tests {
view.viewport = euclid::rect(0.0, 0.0, 1000.0, 400.0);
let layouts = reveal_layout(2, 3, 300.0);
let groups = vec![live_group_with_active(6, 0)];
- view.scroll.set_extents(400.0, 40.0 + 3.0 * 300.0 + 2.0 * 16.0);
+ view.scroll
+ .set_extents(400.0, 40.0 + 3.0 * 300.0 + 2.0 * 16.0);
assert!(view
.offset_revealing_active(&groups, &layouts, 0.0, 1000.0, 16.0)
@@ -2635,7 +2641,8 @@ mod tests {
let layouts = reveal_layout(2, 3, 300.0);
let mut groups = vec![live_group_with_active(6, 0)];
groups[0].cards[0].active = false;
- view.scroll.set_extents(400.0, 40.0 + 3.0 * 300.0 + 2.0 * 16.0);
+ view.scroll
+ .set_extents(400.0, 40.0 + 3.0 * 300.0 + 2.0 * 16.0);
assert!(view
.offset_revealing_active(&groups, &layouts, 0.0, 1000.0, 16.0)
@@ -2910,20 +2917,21 @@ mod tests {
let now = Instant::now();
let mut budget = usize::MAX;
let mut captures = 0;
- let mut capture = |cache: &mut HashMap<_, _>, at: Instant, seq: usize, budget: &mut usize| {
- resolve_snapshot(
- cache,
- &key,
- Some(test_fingerprint(seq)),
- at,
- Some(preview_refresh_interval()),
- budget,
- || {
- captures += 1;
- Some(seq as u8)
- },
- )
- };
+ let mut capture =
+ |cache: &mut HashMap<_, _>, at: Instant, seq: usize, budget: &mut usize| {
+ resolve_snapshot(
+ cache,
+ &key,
+ Some(test_fingerprint(seq)),
+ at,
+ Some(preview_refresh_interval()),
+ budget,
+ || {
+ captures += 1;
+ Some(seq as u8)
+ },
+ )
+ };
// A frame every 8ms for a second, with the content different every
// time. What comes out is one capture per refresh interval, not the
@@ -2941,7 +2949,10 @@ mod tests {
}
let interval_ms = preview_refresh_interval().as_millis() as u64;
assert_eq!(captures, 1 + (FRAMES * FRAME_MS / interval_ms) as usize);
- assert!(captures < 12, "{captures} captures in a second is not a throttle");
+ assert!(
+ captures < 12,
+ "{captures} captures in a second is not a throttle"
+ );
}
/// Opening the overview used to capture every card in the frame that
diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs
index e3429e90..c924d725 100644
--- a/wezterm-gui/src/termwindow/mod.rs
+++ b/wezterm-gui/src/termwindow/mod.rs
@@ -2190,14 +2190,34 @@ impl TermWindow {
}
lines.push(format!(
- "{label}: caches shape={} line_state={} line_quad={} line_to_element_shape={} pane_font={} semantic_zones={}",
+ "{label}: caches shape={} ({}KiB) line_state={} ({}KiB) line_quad={} ({}KiB) line_to_element_shape={} ({}KiB) pane_font={} semantic_zones={}",
self.shape_cache.borrow().len(),
+ self.shape_cache.borrow().total_weight() / 1024,
self.line_state_cache.borrow().len(),
+ self.line_state_cache.borrow().total_weight() / 1024,
self.line_quad_cache.borrow().len(),
+ self.line_quad_cache.borrow().total_weight() / 1024,
self.line_to_ele_shape_cache.borrow().len(),
+ self.line_to_ele_shape_cache.borrow().total_weight() / 1024,
self.pane_font_cache.borrow().len(),
self.semantic_zones.len(),
));
+ {
+ let ui = self.ui_shape_caches.borrow();
+ lines.push(format!(
+ "{label}: ui_shape_caches chrome={} ({}KiB) note={} ({}KiB) file_preview={} ({}KiB)",
+ ui.domain(crate::shapecache::UiTextDomain::Chrome).len(),
+ ui.domain(crate::shapecache::UiTextDomain::Chrome)
+ .total_weight()
+ / 1024,
+ ui.domain(crate::shapecache::UiTextDomain::Note).len(),
+ ui.domain(crate::shapecache::UiTextDomain::Note).total_weight() / 1024,
+ ui.domain(crate::shapecache::UiTextDomain::FilePreview).len(),
+ ui.domain(crate::shapecache::UiTextDomain::FilePreview)
+ .total_weight()
+ / 1024,
+ ));
+ }
lines
}
@@ -3118,7 +3138,9 @@ impl TermWindow {
Ok(state) => webgpu = Some(Rc::new(state)),
Err(err) => {
log::error!("WebGpu is unavailable ({err:#}); falling back to OpenGL");
- gpu_debug(format!("WebGpu unavailable: {err:#}; falling back to OpenGL"));
+ gpu_debug(format!(
+ "WebGpu unavailable: {err:#}; falling back to OpenGL"
+ ));
effective_renderer = crate::native_settings::NativeRendererBackend::OpenGL;
}
}
diff --git a/wezterm-gui/src/termwindow/render/fancy_tab_bar.rs b/wezterm-gui/src/termwindow/render/fancy_tab_bar.rs
index a1007a89..a93b6d4e 100644
--- a/wezterm-gui/src/termwindow/render/fancy_tab_bar.rs
+++ b/wezterm-gui/src/termwindow/render/fancy_tab_bar.rs
@@ -1353,7 +1353,11 @@ impl crate::TermWindow {
let miss_stage = crate::input_diagnostics::StageTimer::begin(domain.miss_stage_name());
let infos = match font.shape(
text,
- move |chars: &[char]| window.notify(TermWindowNotif::InvalidateShapeCacheForChars(chars.to_vec())),
+ move |chars: &[char]| {
+ window.notify(TermWindowNotif::InvalidateShapeCacheForChars(
+ chars.to_vec(),
+ ))
+ },
BlockKey::filter_out_synthetic,
None,
Direction::LeftToRight,
diff --git a/wezterm-gui/src/termwindow/render/mod.rs b/wezterm-gui/src/termwindow/render/mod.rs
index 9c789796..4c19ad0d 100644
--- a/wezterm-gui/src/termwindow/render/mod.rs
+++ b/wezterm-gui/src/termwindow/render/mod.rs
@@ -138,6 +138,56 @@ pub struct RenderScreenLineResult {
pub invalidate_on_hover_change: bool,
}
+/// Per-entry bookkeeping cost of the LFU cache itself (the shared `Rc`
+/// entry holding the intrusive links), matching the constant used by the
+/// UI shape caches in `shapecache.rs`.
+const CACHE_ENTRY_FIXED_OVERHEAD: usize = 128;
+
+/// Estimated resident bytes for one `line_state_cache` entry: the
+/// `Arc<CachedLineState>` allocation plus the u64 key.
+pub const LINE_STATE_ENTRY_BYTES: usize =
+ CACHE_ENTRY_FIXED_OVERHEAD + std::mem::size_of::<CachedLineState>() + 24;
+
+/// Estimated resident bytes for one `line_quad_cache` entry. The dominant
+/// term is the `HeapQuadAllocator` capacity.
+pub fn estimate_line_quad_entry_bytes(key: &LineQuadCacheKey, value: &LineQuadCacheValue) -> usize {
+ CACHE_ENTRY_FIXED_OVERHEAD
+ .saturating_add(std::mem::size_of::<LineQuadCacheKey>())
+ .saturating_add(key.composing.as_ref().map_or(0, |s| s.capacity()))
+ .saturating_add(std::mem::size_of::<LineQuadCacheValue>())
+ .saturating_add(value.layers.resident_bytes())
+}
+
+/// Estimated resident bytes for one `line_to_ele_shape_cache` entry. The
+/// `glyph_info` Rc inside each shape is shared with (and counted by) the
+/// `shape_cache` entry that minted it, so only each shape's inline size and
+/// its cluster's own heap are counted here.
+pub fn estimate_line_to_ele_entry_bytes(
+ key: &LineToEleShapeCacheKey,
+ value: &LineToElementShapeItem,
+) -> usize {
+ let key_bytes = std::mem::size_of::<LineToEleShapeCacheKey>()
+ .saturating_add(key.composing.as_ref().map_or(0, |(_, s)| s.capacity()));
+ let shaped_bytes = std::mem::size_of::<Vec<LineToElementShape>>()
+ .saturating_add(
+ value
+ .shaped
+ .capacity()
+ .saturating_mul(std::mem::size_of::<LineToElementShape>()),
+ )
+ .saturating_add(
+ value
+ .shaped
+ .iter()
+ .map(|shape| shape.cluster.resident_heap_bytes())
+ .sum(),
+ );
+ CACHE_ENTRY_FIXED_OVERHEAD
+ .saturating_add(key_bytes)
+ .saturating_add(std::mem::size_of::<LineToElementShapeItem>())
+ .saturating_add(shaped_bytes)
+}
+
pub struct RenderScreenLineParams<'a> {
/// zero-based offset from top of the window viewport to the line that
/// needs to be rendered, measured in pixels
@@ -888,7 +938,11 @@ impl crate::TermWindow {
let hb_started = crate::perf::now();
match font.shape(
&cluster.text,
- move |chars: &[char]| window.notify(TermWindowNotif::InvalidateShapeCacheForChars(chars.to_vec())),
+ move |chars: &[char]| {
+ window.notify(TermWindowNotif::InvalidateShapeCacheForChars(
+ chars.to_vec(),
+ ))
+ },
BlockKey::filter_out_synthetic,
Some(cluster.presentation),
cluster.direction,
@@ -908,9 +962,12 @@ impl crate::TermWindow {
crate::perf::accum("glyph_raster", raster_started);
let shaped = Rc::new(ShapedInfo::process(&info, &glyphs));
+ let key = key.to_owned();
+ let value = Ok(Rc::clone(&shaped));
+ let weight = crate::shapecache::estimate_shaped_entry_bytes(&key, &value);
self.shape_cache
.borrow_mut()
- .put(key.to_owned(), Ok(Rc::clone(&shaped)));
+ .put_weighted(key, value, weight);
shaped
}
Err(err) => {
@@ -919,7 +976,12 @@ impl crate::TermWindow {
}
let res = anyhow!("shaper error: {}", err);
- self.shape_cache.borrow_mut().put(key.to_owned(), Err(err));
+ let key = key.to_owned();
+ let value = Err(err);
+ let weight = crate::shapecache::estimate_shaped_entry_bytes(&key, &value);
+ self.shape_cache
+ .borrow_mut()
+ .put_weighted(key, value, weight);
return Err(res);
}
}
@@ -1008,7 +1070,11 @@ impl crate::TermWindow {
let hb_started = crate::perf::now();
match font.shape(
seg,
- move |chars: &[char]| window.notify(TermWindowNotif::InvalidateShapeCacheForChars(chars.to_vec())),
+ move |chars: &[char]| {
+ window.notify(TermWindowNotif::InvalidateShapeCacheForChars(
+ chars.to_vec(),
+ ))
+ },
BlockKey::filter_out_synthetic,
Some(cluster.presentation),
cluster.direction,
@@ -1027,9 +1093,13 @@ impl crate::TermWindow {
)?;
crate::perf::accum("glyph_raster", raster_started);
let shaped = Rc::new(ShapedInfo::process(&info, &glyphs));
+ let key = key.to_owned();
+ let value = Ok(Rc::clone(&shaped));
+ let weight =
+ crate::shapecache::estimate_shaped_entry_bytes(&key, &value);
self.shape_cache
.borrow_mut()
- .put(key.to_owned(), Ok(Rc::clone(&shaped)));
+ .put_weighted(key, value, weight);
shaped
}
Err(err) => {
@@ -1037,7 +1107,13 @@ impl crate::TermWindow {
return Err(err);
}
let res = anyhow!("shaper error: {}", err);
- self.shape_cache.borrow_mut().put(key.to_owned(), Err(err));
+ let key = key.to_owned();
+ let value = Err(err);
+ let weight =
+ crate::shapecache::estimate_shaped_entry_bytes(&key, &value);
+ self.shape_cache
+ .borrow_mut()
+ .put_weighted(key, value, weight);
return Err(res);
}
}
@@ -1116,7 +1192,9 @@ impl crate::TermWindow {
line.set_appdata(Arc::clone(&state));
- self.line_state_cache.borrow_mut().put(id, state);
+ self.line_state_cache
+ .borrow_mut()
+ .put_weighted(id, state, LINE_STATE_ENTRY_BYTES);
shape_hash
}
}
diff --git a/wezterm-gui/src/termwindow/render/paint.rs b/wezterm-gui/src/termwindow/render/paint.rs
index da536cb7..45c3d9e0 100644
--- a/wezterm-gui/src/termwindow/render/paint.rs
+++ b/wezterm-gui/src/termwindow/render/paint.rs
@@ -88,7 +88,9 @@ const PREVIEW_CONTENT_FADE: Duration = Duration::from_millis(120);
pub(crate) enum PreviewContentFade {
/// Still blank. `snapshot` is the address of the snapshot last scanned,
/// so each snapshot is scanned for content at most once.
- Blank { snapshot: usize },
+ Blank {
+ snapshot: usize,
+ },
ContentSince(Instant),
}
@@ -1524,8 +1526,8 @@ impl crate::TermWindow {
// card's (invisible) quads out of the blending special cases.
PreviewContentFade::Blank { .. } => 1.0,
PreviewContentFade::ContentSince(since) => {
- let t = now.duration_since(*since).as_secs_f32()
- / PREVIEW_CONTENT_FADE.as_secs_f32();
+ let t =
+ now.duration_since(*since).as_secs_f32() / PREVIEW_CONTENT_FADE.as_secs_f32();
if t >= 1.0 {
1.0
} else {
@@ -3839,8 +3841,7 @@ impl crate::TermWindow {
self.paint_file_drag_ghost()
.context("paint_file_drag_ghost")?;
// Last, so the tag sits above every chrome surface it might overhang.
- self.paint_hover_tooltip()
- .context("paint_hover_tooltip")?;
+ self.paint_hover_tooltip().context("paint_hover_tooltip")?;
Ok(())
}
diff --git a/wezterm-gui/src/termwindow/render/pane.rs b/wezterm-gui/src/termwindow/render/pane.rs
index fe505e61..4fd42d62 100644
--- a/wezterm-gui/src/termwindow/render/pane.rs
+++ b/wezterm-gui/src/termwindow/render/pane.rs
@@ -1646,10 +1646,14 @@ impl crate::TermWindow {
},
};
+ let weight = crate::termwindow::render::estimate_line_quad_entry_bytes(
+ &quad_key,
+ &quad_value,
+ );
self.term_window
.line_quad_cache
.borrow_mut()
- .put(quad_key, quad_value);
+ .put_weighted(quad_key, quad_value, weight);
Ok(())
}
diff --git a/wezterm-gui/src/termwindow/render/screen_line.rs b/wezterm-gui/src/termwindow/render/screen_line.rs
index 12fbfcd2..fc2f4e66 100644
--- a/wezterm-gui/src/termwindow/render/screen_line.rs
+++ b/wezterm-gui/src/termwindow/render/screen_line.rs
@@ -875,9 +875,7 @@ impl crate::TermWindow {
let style_params = last_style.as_ref().expect("we just set it up").clone();
- let glyph_info = if params.simple_shaping
- || cluster_is_tui_graphics(&cluster.text)
- {
+ let glyph_info = if params.simple_shaping || cluster_is_tui_graphics(&cluster.text) {
self.cached_cluster_shape_by_cell(
style_params.style,
&cluster,
@@ -920,19 +918,21 @@ impl crate::TermWindow {
let shaped = Rc::new(shaped);
if let Some(shape_key) = params.shape_key {
- self.line_to_ele_shape_cache.borrow_mut().put(
- shape_key.clone(),
- LineToElementShapeItem {
- expires,
- shaped: Rc::clone(&shaped),
- invalidate_on_hover_change,
- current_highlight: if invalidate_on_hover_change {
- self.current_highlight.clone()
- } else {
- None
- },
+ let item = LineToElementShapeItem {
+ expires,
+ shaped: Rc::clone(&shaped),
+ invalidate_on_hover_change,
+ current_highlight: if invalidate_on_hover_change {
+ self.current_highlight.clone()
+ } else {
+ None
},
- );
+ };
+ let weight =
+ crate::termwindow::render::estimate_line_to_ele_entry_bytes(&shape_key, &item);
+ self.line_to_ele_shape_cache
+ .borrow_mut()
+ .put_weighted(shape_key.clone(), item, weight);
}
Ok((shaped, invalidate_on_hover_change))
diff --git a/wezterm-gui/src/termwindow/space_swipe.rs b/wezterm-gui/src/termwindow/space_swipe.rs
index a7833d0b..cbb47caa 100644
--- a/wezterm-gui/src/termwindow/space_swipe.rs
+++ b/wezterm-gui/src/termwindow/space_swipe.rs
@@ -304,13 +304,7 @@ impl SidebarSpaceSwipeState {
source_scroll_offset: gesture.source_scroll_offset,
// The pages are already where the finger left them, so
// there is nothing new to draw before travelling back.
- travel: Timeline::running(
- now,
- from,
- 0.0,
- SETTLE_DURATION,
- Easing::OutCubic,
- ),
+ travel: Timeline::running(now, from, 0.0, SETTLE_DURATION, Easing::OutCubic),
committed: false,
});
SidebarSpaceSwipeFinish::AnimateBack
diff --git a/wezterm-gui/src/termwindow/ui/agent_panel.rs b/wezterm-gui/src/termwindow/ui/agent_panel.rs
index f686574e..8c4c4f08 100644
--- a/wezterm-gui/src/termwindow/ui/agent_panel.rs
+++ b/wezterm-gui/src/termwindow/ui/agent_panel.rs
@@ -177,14 +177,7 @@ impl TermWindow {
.saturating_sub(button_size + self.ui_px(SIDEBAR_ICON_GAP))
.saturating_sub(text_x);
self.paint_sidebar_text(
- layers,
- ui_font,
- ui_metrics,
- &line,
- text_x,
- text_y,
- text_width,
- muted_fg,
+ layers, ui_font, ui_metrics, &line, text_x, text_y, text_width, muted_fg,
)?;
// Only the "detection is off" line is actionable: it names the
// switch that turns the panel back on, so it must lead there.
@@ -305,8 +298,7 @@ impl TermWindow {
// Rows are laid out top-down, so nothing below is visible.
break;
}
- let Some(band) =
- agent_row_visible_band(row_top, row_height, list_top, row_clip_bottom)
+ let Some(band) = agent_row_visible_band(row_top, row_height, list_top, row_clip_bottom)
else {
continue;
};
@@ -395,27 +387,18 @@ impl TermWindow {
// places: blue for in progress, amber for needs input, and a
// muted tick for idle, which must not compete for attention.
let state_icon = match agent.state {
- AgentState::Working => {
- Some((SvgIcon::LoaderCircle, AGENT_WORKING_COLOR, true))
- }
- AgentState::Blocked => {
- Some((SvgIcon::CircleAlert, AGENT_BLOCKED_COLOR, false))
- }
+ AgentState::Working => Some((SvgIcon::LoaderCircle, AGENT_WORKING_COLOR, true)),
+ AgentState::Blocked => Some((SvgIcon::CircleAlert, AGENT_BLOCKED_COLOR, false)),
AgentState::Idle => Some((SvgIcon::CircleCheck, muted_fg, false)),
AgentState::Unknown => None,
};
let has_state_icon = state_icon.is_some();
- if let Some((icon, color, spinning)) = state_icon.filter(|_| visible(state_y, state_size))
+ if let Some((icon, color, spinning)) =
+ state_icon.filter(|_| visible(state_y, state_size))
{
if spinning {
self.paint_spinning_ui_icon(
- layers,
- 2,
- icon,
- state_x,
- state_y,
- state_size,
- color,
+ layers, 2, icon, state_x, state_y, state_size, color,
)?;
} else {
self.paint_sidebar_icon(layers, icon, state_x, state_y, state_size, color)?;
@@ -612,20 +595,14 @@ impl TermWindow {
else {
return;
};
- if let Some(thread_id) =
- crate::workspace_threads::thread_id_for_workspace_any(&workspace)
- {
+ if let Some(thread_id) = crate::workspace_threads::thread_id_for_workspace_any(&workspace) {
// Only a thread of this Space (or one it references) can be
// activated here; activate_workspace_thread's guard silently
// drops anything else, which used to make these clicks no-ops.
let home_space = crate::workspace_threads::thread_space_id(&thread_id);
- let in_this_space =
- home_space.as_deref() == Some(self.active_space_id.as_str());
+ let in_this_space = home_space.as_deref() == Some(self.active_space_id.as_str());
let referenced = !in_this_space
- && crate::workspace_threads::thread_ref_exists(
- &self.active_space_id,
- &thread_id,
- );
+ && crate::workspace_threads::thread_ref_exists(&self.active_space_id, &thread_id);
if in_this_space || referenced {
self.activate_workspace_thread(thread_id, context);
return;
@@ -643,9 +620,7 @@ impl TermWindow {
crate::workspace_threads::window_owner_for_space(&home_space)
{
let Some(target) = crate::frontend::front_end()
- .gui_window_for_recovery_slot(FrontendRecoverySlot::Window(
- target_owner_id,
- ))
+ .gui_window_for_recovery_slot(FrontendRecoverySlot::Window(target_owner_id))
else {
return;
};
@@ -661,8 +636,7 @@ impl TermWindow {
{
return;
}
- target_term_window
- .activate_workspace_thread(thread_id, &target_window);
+ target_term_window.activate_workspace_thread(thread_id, &target_window);
target_window.focus();
},
)));
diff --git a/wezterm-gui/src/termwindow/ui/status_icon.rs b/wezterm-gui/src/termwindow/ui/status_icon.rs
index 8a3e215d..38771a64 100644
--- a/wezterm-gui/src/termwindow/ui/status_icon.rs
+++ b/wezterm-gui/src/termwindow/ui/status_icon.rs
@@ -165,7 +165,10 @@ mod tests {
#[test]
fn braille_spinner_splits() {
- assert_eq!(split_leading_legacy_progress_marker("⠋ build"), Some("build"));
+ assert_eq!(
+ split_leading_legacy_progress_marker("⠋ build"),
+ Some("build")
+ );
}
#[test]
diff --git a/wezterm-surface/src/cellcluster.rs b/wezterm-surface/src/cellcluster.rs
index 26b30e04..e235f078 100644
--- a/wezterm-surface/src/cellcluster.rs
+++ b/wezterm-surface/src/cellcluster.rs
@@ -45,6 +45,16 @@ impl CellCluster {
}
}
+ /// Estimated heap bytes owned by this cluster beyond its inline size.
+ /// Any heap held behind `attrs` (fat attributes) is not visible from
+ /// here and is not counted.
+ pub fn resident_heap_bytes(&self) -> usize {
+ self.text
+ .capacity()
+ .saturating_add(self.byte_to_cell_idx.capacity() * core::mem::size_of::<usize>())
+ .saturating_add(self.byte_to_cell_width.capacity())
+ }
+
/// Compute the list of CellClusters from a set of visible cells.
/// The input is typically the result of calling `Line::visible_cells()`.
pub fn make_cluster<'a>(