Use platform shortcuts and scale terminal text per window

Cache font metrics across pane and tab switches. Resize text, cursors, and PTY grids together, using the active window’s font size when multiple windows share a shell.
This commit is contained in:
James Magahern
2026-11-17 14:49:35 -08:00
parent 12ba7abdd2
commit 10fa542937
6 changed files with 379 additions and 146 deletions
+37 -2
View File
@@ -15,13 +15,48 @@ const PREFERRED: &[&str] = &[
"Iosevka Term",
];
pub fn terminal_font(text_system: &TextSystem) -> Font {
const DEFAULT_SIZE: f32 = 15.;
#[derive(Clone)]
pub struct TerminalFont {
pub face: Font,
pub size: f32,
pub cell_width: f32,
pub line_height: f32,
}
impl TerminalFont {
fn new(face: Font, size: f32, text_system: &TextSystem) -> Self {
let cell_width = text_system
.advance(text_system.resolve_font(&face), px(size), 'M')
.map(|advance| f32::from(advance.width))
.unwrap_or(size * 0.6)
.max(1.);
Self {
face,
size,
cell_width,
line_height: (size * 4. / 3.).round(),
}
}
pub fn adjust_size(&mut self, delta: f32, text_system: &TextSystem) -> bool {
let size = (self.size + delta).clamp(6., 72.);
if size == self.size {
return false;
}
*self = Self::new(self.face.clone(), size, text_system);
true
}
}
pub fn terminal_font(text_system: &TextSystem) -> TerminalFont {
let families = text_system.all_font_names();
let family = select_family(&families, |family| is_monospace(text_system, family)).expect(
"No usable monospace font found; install Hermit, Noto Sans Mono, or DejaVu Sans Mono",
);
log::info!("Terminal font: {family}");
font(family.to_owned())
TerminalFont::new(font(family.to_owned()), DEFAULT_SIZE, text_system)
}
fn select_family(families: &[String], mut is_monospace: impl FnMut(&str) -> bool) -> Option<&str> {