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:
@@ -142,34 +142,38 @@ run `psyterm --shutdown` on the remote host, for example through SSH.
|
||||
|
||||
## Controls
|
||||
|
||||
| Input | Action |
|
||||
| --- | --- |
|
||||
| Ctrl/Cmd+Shift+P | Open the command palette |
|
||||
| Click a tab | Switch the server's active tab |
|
||||
| `+` or Ctrl+Shift+T | Create a tab |
|
||||
| Ctrl+Shift+D or Alt+\ | Add a pane beside the focused pane |
|
||||
| Alt+Left / Right | Focus the adjacent pane, then adjacent tab at the edge |
|
||||
| Alt+Shift+[ / ] | Switch to the previous / next tab |
|
||||
| Alt+Shift+N or Alt+Shift+Right | Create a tab |
|
||||
| Alt+Shift+Up / Down | Insert a stacked pane above / below the current pane |
|
||||
| Alt+Up / Down | Expand the previous / next stacked pane |
|
||||
| Click a collapsed pane title | Expand and focus that pane |
|
||||
| Ctrl+Shift+Left / Right | Focus the previous / next pane |
|
||||
| Ctrl+Shift+W | Close the focused pane and its shell |
|
||||
| Ctrl+Shift+R | Edit the pane name |
|
||||
| Palette → Rename tab | Edit the selected tab's name |
|
||||
| Enter / Esc while renaming | Save / cancel the edit |
|
||||
| Save a blank name | Restore automatic pane/tab naming |
|
||||
| Window `×` | Detach this GUI; keep server sessions running |
|
||||
| Drag / double-click / triple-click | Select text / word / line |
|
||||
| Ctrl+Shift+C / V | Copy selection / paste with negotiated bracketed-paste mode |
|
||||
| Mouse wheel / touchpad | Scroll terminal history |
|
||||
| Shift+PageUp / PageDown | Scroll one page |
|
||||
| Shift+Home / End | Jump to oldest history / live screen |
|
||||
| Action | macOS | Linux |
|
||||
| --- | --- | --- |
|
||||
| Increase terminal text size | Cmd+Plus or Cmd+= | Ctrl+Plus or Ctrl+= |
|
||||
| Decrease terminal text size | Cmd+Minus | Ctrl+Minus |
|
||||
| Open or dismiss the command palette | Cmd+Shift+P | Ctrl+Shift+P |
|
||||
| Create a tab | Cmd+T | Ctrl+Shift+T |
|
||||
| Add a pane to the right | Cmd+D | Ctrl+Shift+D or Alt+\ |
|
||||
| Insert a stacked pane above / below | Option+Shift+Up / Cmd+Shift+D | Alt+Shift+Up / Down |
|
||||
| Focus the adjacent pane or tab | Cmd+Option+Left / Right | Alt+Left / Right |
|
||||
| Switch tabs | Cmd+Shift+[ / ] | Alt+Shift+[ / ] |
|
||||
| Focus the previous / next stacked pane | Cmd+Option+Up / Down | Alt+Up / Down |
|
||||
| Cycle through panes | Cmd+[ / ] | Ctrl+Shift+Left / Right |
|
||||
| Close the focused pane and its shell | Cmd+W | Ctrl+Shift+W |
|
||||
| Rename the focused pane | Cmd+Shift+R | Ctrl+Shift+R |
|
||||
| Copy selection / paste | Cmd+C / Cmd+V | Ctrl+Shift+C / Ctrl+Shift+V |
|
||||
| Quit the GUI and keep sessions running | Cmd+Q | Window `×` |
|
||||
| Scroll one page | Shift+PageUp / PageDown | Shift+PageUp / PageDown |
|
||||
| Jump to oldest history / live screen | Shift+Home / End | Shift+Home / End |
|
||||
|
||||
Navigation follows the `shared` bindings in `~/.config/zellij/config.kdl`, with
|
||||
Alt+\ from its default `locked` mode. Existing psyTerm shortcuts remain available;
|
||||
Zellij's modal Ctrl bindings are left to terminal programs.
|
||||
Click a tab to switch, `+` to create a tab, or a collapsed pane title to expand it.
|
||||
Drag, double-click, or triple-click to select text, a word, or a line. Scroll with
|
||||
the mouse wheel or touchpad. Closing the window detaches the GUI and keeps the
|
||||
server sessions running.
|
||||
|
||||
Choose **Rename tab** in the palette to edit the selected tab's name. When
|
||||
renaming a pane or tab, press Enter to save or Escape to cancel. Saving a blank
|
||||
name restores automatic naming.
|
||||
|
||||
Both platforms also support the Alt shortcuts from Zellij's `shared` map and
|
||||
Alt+\ from its `locked` map. On macOS, Alt is the Option key.
|
||||
Alt+Shift+N and Alt+Shift+Right also create a tab. Plain Ctrl shortcuts such
|
||||
as Ctrl+C and Ctrl+D reach the terminal.
|
||||
|
||||
The command palette searches command names and keywords as you type. Arrow keys
|
||||
or Tab select a result; Enter runs it or opens a submenu. Escape returns to the
|
||||
@@ -238,7 +242,9 @@ Neovide's MIT license and both sources are recorded in
|
||||
|
||||
Font preference is Hermit (including Hurmit Nerd Font variants), SF Mono,
|
||||
Noto Sans Mono, Iosevka, then another verified fixed-pitch family. Text uses
|
||||
15 logical pixels and a 20-pixel line height. Rendering supports ANSI/256
|
||||
15 logical pixels with a 20-pixel line height by default. The text-size shortcuts
|
||||
resize all terminals in the focused window, including panes opened there later.
|
||||
Each new window starts at the default size. Rendering supports ANSI/256
|
||||
colors, truecolor, bold/italic/dim, underline, reverse video, wide characters,
|
||||
and combining marks. Alacritty supplies terminal modes and 10,000 lines of
|
||||
scrollback by default.
|
||||
|
||||
+110
-1
@@ -1,14 +1,55 @@
|
||||
//! Application shortcuts, including the user's Zellij `locked`/`shared` map.
|
||||
//! Registry commands remain available even when they have no shortcut here.
|
||||
use gpui::Keystroke;
|
||||
use gpui::{Keystroke, Modifiers};
|
||||
|
||||
use crate::commands::CommandAction;
|
||||
|
||||
pub fn action_for_key(key: &Keystroke) -> Option<CommandAction> {
|
||||
let modifiers = key.modifiers;
|
||||
let name = key.key.to_lowercase();
|
||||
// The Command key on macOS or Control on Linux, optionally with Shift.
|
||||
let window_modifiers = Modifiers {
|
||||
shift: modifiers.shift,
|
||||
..Modifiers::secondary_key()
|
||||
};
|
||||
if modifiers == window_modifiers {
|
||||
match name.as_str() {
|
||||
// GPUI may fold Shift into the symbol. On XKB the keypad keys
|
||||
// have separate "add" and "subtract" names.
|
||||
"+" | "=" | "add" => return Some(CommandAction::IncreaseFontSize),
|
||||
"-" | "subtract" if !modifiers.shift => return Some(CommandAction::DecreaseFontSize),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
if modifiers.platform && !modifiers.control && !modifiers.function {
|
||||
use CommandAction::*;
|
||||
return Some(match (modifiers.alt, modifiers.shift, name.as_str()) {
|
||||
(false, false, "t") => NewTab,
|
||||
(false, false, "w") => ClosePane,
|
||||
(false, false, "c") => Copy,
|
||||
(false, false, "v") => Paste,
|
||||
(false, false, "d") => SplitPane,
|
||||
(false, true, "d") => StackBelow,
|
||||
(false, true, "r") => RenamePane,
|
||||
(false, true, "p") => TogglePalette,
|
||||
(false, false, "[") => PreviousPane,
|
||||
(false, false, "]") => NextPane,
|
||||
// GPUI can fold Shift into the brace on a punctuation key.
|
||||
(false, true, "[") | (false, _, "{") => PreviousTab,
|
||||
(false, true, "]") | (false, _, "}") => NextTab,
|
||||
(true, false, "left") => FocusLeft,
|
||||
(true, false, "right") => FocusRight,
|
||||
(true, false, "up") => FocusAbove,
|
||||
(true, false, "down") => FocusBelow,
|
||||
_ => return None,
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
if (modifiers.control || modifiers.platform) && modifiers.shift && !modifiers.alt {
|
||||
return Some(match name.as_str() {
|
||||
"p" => CommandAction::TogglePalette,
|
||||
"t" => CommandAction::NewTab,
|
||||
"d" => CommandAction::SplitPane,
|
||||
"w" => CommandAction::ClosePane,
|
||||
@@ -77,6 +118,15 @@ mod tests {
|
||||
Some(CommandAction::FocusRight)
|
||||
));
|
||||
assert!(matches!(action("alt-\\"), Some(CommandAction::SplitPane)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
fn linux_workspace_shortcuts_use_control_shift() {
|
||||
assert!(matches!(
|
||||
action("ctrl-shift-p"),
|
||||
Some(CommandAction::TogglePalette)
|
||||
));
|
||||
assert!(matches!(
|
||||
action("ctrl-shift-left"),
|
||||
Some(CommandAction::PreviousPane)
|
||||
@@ -84,6 +134,65 @@ mod tests {
|
||||
assert!(matches!(action("cmd-shift-t"), Some(CommandAction::NewTab)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "macos")]
|
||||
fn mac_shortcuts_leave_control_for_the_terminal() {
|
||||
use CommandAction::*;
|
||||
assert!(matches!(action("cmd-shift-p"), Some(TogglePalette)));
|
||||
assert!(matches!(action("cmd-shift-["), Some(PreviousTab)));
|
||||
assert!(matches!(action("cmd-{"), Some(PreviousTab)));
|
||||
assert!(matches!(action("cmd-}"), Some(NextTab)));
|
||||
for key in ["ctrl-c", "ctrl-v", "ctrl-w", "ctrl-shift-p", "ctrl-cmd-c"] {
|
||||
assert!(action(key).is_none(), "{key}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn text_size_shortcuts_use_platform_conventions() {
|
||||
use CommandAction::*;
|
||||
|
||||
for key in [
|
||||
"secondary-+",
|
||||
"secondary-=",
|
||||
"secondary-shift-+",
|
||||
"secondary-shift-=",
|
||||
"secondary-add",
|
||||
] {
|
||||
assert!(matches!(action(key), Some(IncreaseFontSize)), "{key}");
|
||||
}
|
||||
for key in ["secondary--", "secondary-subtract"] {
|
||||
assert!(matches!(action(key), Some(DecreaseFontSize)), "{key}");
|
||||
}
|
||||
for key in ["+", "=", "-", "alt-+", "ctrl-cmd-+", "secondary-fn--"] {
|
||||
assert!(action(key).is_none(), "{key}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn palette_lists_the_shortcut_that_dispatches_each_workspace_command() {
|
||||
use crate::commands::{PaletteItemKind, root_items};
|
||||
use std::mem::discriminant;
|
||||
|
||||
for item in root_items(None) {
|
||||
let (Some(hint), PaletteItemKind::Action(expected)) = (item.shortcut, &item.kind)
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
// Scrolling is dispatched by the pane according to the terminal mode.
|
||||
if matches!(expected, CommandAction::Scroll(_)) {
|
||||
continue;
|
||||
}
|
||||
let (modifiers, key) = match hint.strip_suffix("++") {
|
||||
Some(modifiers) => (modifiers, "+"),
|
||||
None => hint.rsplit_once('+').unwrap(),
|
||||
};
|
||||
let modifiers = modifiers.replace("Option", "Alt").replace('+', "-");
|
||||
let key = format!("{modifiers}-{key}").to_ascii_lowercase();
|
||||
let actual = action(&key).unwrap_or_else(|| panic!("unbound shortcut {hint}"));
|
||||
assert_eq!(discriminant(&actual), discriminant(expected), "{hint}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stacked_panes_use_the_requested_vertical_bindings() {
|
||||
assert!(matches!(
|
||||
|
||||
+41
-16
@@ -6,7 +6,10 @@ use crate::protocol::{ScrollKind, Snapshot};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum CommandAction {
|
||||
TogglePalette,
|
||||
NewTab,
|
||||
IncreaseFontSize,
|
||||
DecreaseFontSize,
|
||||
SplitPane,
|
||||
StackAbove,
|
||||
StackBelow,
|
||||
@@ -88,6 +91,14 @@ impl PaletteItem {
|
||||
}
|
||||
}
|
||||
|
||||
fn shortcut(mac: &'static str, linux: &'static str) -> Option<&'static str> {
|
||||
Some(if cfg!(target_os = "macos") {
|
||||
mac
|
||||
} else {
|
||||
linux
|
||||
})
|
||||
}
|
||||
|
||||
/// The complete command list. UI state affects availability, never discovery.
|
||||
pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
||||
use CommandAction::*;
|
||||
@@ -98,14 +109,14 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
||||
"new-tab",
|
||||
"New tab",
|
||||
"create shell terminal",
|
||||
Some("Ctrl+Shift+T"),
|
||||
shortcut("Cmd+T", "Ctrl+Shift+T"),
|
||||
NewTab,
|
||||
),
|
||||
PaletteItem::action(
|
||||
"split-pane",
|
||||
"Split pane right",
|
||||
"new create horizontal shell",
|
||||
Some("Ctrl+Shift+D"),
|
||||
shortcut("Cmd+D", "Ctrl+Shift+D"),
|
||||
SplitPane,
|
||||
)
|
||||
.available(pane),
|
||||
@@ -113,7 +124,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
||||
"close-pane",
|
||||
"Close pane",
|
||||
"exit shell terminate",
|
||||
Some("Ctrl+Shift+W"),
|
||||
shortcut("Cmd+W", "Ctrl+Shift+W"),
|
||||
ClosePane,
|
||||
)
|
||||
.available(pane),
|
||||
@@ -121,7 +132,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
||||
"rename-pane",
|
||||
"Rename pane",
|
||||
"name title label",
|
||||
Some("Ctrl+Shift+R"),
|
||||
shortcut("Cmd+Shift+R", "Ctrl+Shift+R"),
|
||||
RenamePane,
|
||||
)
|
||||
.available(pane),
|
||||
@@ -153,7 +164,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
||||
"previous-tab",
|
||||
"Previous tab",
|
||||
"switch navigate left",
|
||||
Some("Alt+Shift+["),
|
||||
shortcut("Cmd+Shift+[", "Alt+Shift+["),
|
||||
PreviousTab,
|
||||
)
|
||||
.available(tabs),
|
||||
@@ -161,7 +172,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
||||
"next-tab",
|
||||
"Next tab",
|
||||
"switch navigate right",
|
||||
Some("Alt+Shift+]"),
|
||||
shortcut("Cmd+Shift+]", "Alt+Shift+]"),
|
||||
NextTab,
|
||||
)
|
||||
.available(tabs),
|
||||
@@ -169,7 +180,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
||||
"previous-pane",
|
||||
"Previous pane",
|
||||
"switch focus cycle",
|
||||
Some("Ctrl+Shift+Left"),
|
||||
shortcut("Cmd+[", "Ctrl+Shift+Left"),
|
||||
PreviousPane,
|
||||
)
|
||||
.available(pane),
|
||||
@@ -177,7 +188,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
||||
"next-pane",
|
||||
"Next pane",
|
||||
"switch focus cycle",
|
||||
Some("Ctrl+Shift+Right"),
|
||||
shortcut("Cmd+]", "Ctrl+Shift+Right"),
|
||||
NextPane,
|
||||
)
|
||||
.available(pane),
|
||||
@@ -185,7 +196,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
||||
"focus-left",
|
||||
"Focus pane or tab left",
|
||||
"navigate previous horizontal",
|
||||
Some("Alt+Left"),
|
||||
shortcut("Cmd+Option+Left", "Alt+Left"),
|
||||
FocusLeft,
|
||||
)
|
||||
.available(pane),
|
||||
@@ -193,7 +204,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
||||
"focus-right",
|
||||
"Focus pane or tab right",
|
||||
"navigate next horizontal",
|
||||
Some("Alt+Right"),
|
||||
shortcut("Cmd+Option+Right", "Alt+Right"),
|
||||
FocusRight,
|
||||
)
|
||||
.available(pane),
|
||||
@@ -201,7 +212,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
||||
"copy",
|
||||
"Copy selection",
|
||||
"clipboard text",
|
||||
Some("Ctrl+Shift+C"),
|
||||
shortcut("Cmd+C", "Ctrl+Shift+C"),
|
||||
Copy,
|
||||
)
|
||||
.available(pane),
|
||||
@@ -209,10 +220,24 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
||||
"paste",
|
||||
"Paste",
|
||||
"clipboard text",
|
||||
Some("Ctrl+Shift+V"),
|
||||
shortcut("Cmd+V", "Ctrl+Shift+V"),
|
||||
Paste,
|
||||
)
|
||||
.available(pane),
|
||||
PaletteItem::action(
|
||||
"increase-font-size",
|
||||
"Increase text size",
|
||||
"zoom in larger terminal font window",
|
||||
shortcut("Cmd++", "Ctrl++"),
|
||||
IncreaseFontSize,
|
||||
),
|
||||
PaletteItem::action(
|
||||
"decrease-font-size",
|
||||
"Decrease text size",
|
||||
"zoom out smaller terminal font window",
|
||||
shortcut("Cmd+-", "Ctrl+-"),
|
||||
DecreaseFontSize,
|
||||
),
|
||||
PaletteItem::action(
|
||||
"history-page-up",
|
||||
"Scroll history up one page",
|
||||
@@ -258,7 +283,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
||||
"stack-above",
|
||||
"New stacked pane above",
|
||||
"create shell vertical up",
|
||||
Some("Alt+Shift+Up"),
|
||||
shortcut("Option+Shift+Up", "Alt+Shift+Up"),
|
||||
StackAbove,
|
||||
)
|
||||
.available(pane),
|
||||
@@ -266,7 +291,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
||||
"stack-below",
|
||||
"New stacked pane below",
|
||||
"create shell vertical down",
|
||||
Some("Alt+Shift+Down"),
|
||||
shortcut("Cmd+Shift+D", "Alt+Shift+Down"),
|
||||
StackBelow,
|
||||
)
|
||||
.available(pane),
|
||||
@@ -274,7 +299,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
||||
"focus-above",
|
||||
"Focus stacked pane above",
|
||||
"switch vertical up previous",
|
||||
Some("Alt+Up"),
|
||||
shortcut("Cmd+Option+Up", "Alt+Up"),
|
||||
FocusAbove,
|
||||
)
|
||||
.available(pane),
|
||||
@@ -282,7 +307,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
||||
"focus-below",
|
||||
"Focus stacked pane below",
|
||||
"switch vertical down next",
|
||||
Some("Alt+Down"),
|
||||
shortcut("Cmd+Option+Down", "Alt+Down"),
|
||||
FocusBelow,
|
||||
)
|
||||
.available(pane),
|
||||
|
||||
+37
-2
@@ -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> {
|
||||
|
||||
+65
-45
@@ -10,14 +10,11 @@ use alacritty_terminal::{
|
||||
vte::ansi::CursorShape,
|
||||
};
|
||||
use gpui::{
|
||||
App, Bounds, Font, FontFeatures, Hsla, Pixels, Point, ShapedLine, TextRun, Window, fill, point,
|
||||
px, rgb, size,
|
||||
App, Bounds, FontFeatures, Hsla, Pixels, Point, ShapedLine, TextRun, Window, fill, point, px,
|
||||
rgb, size,
|
||||
};
|
||||
|
||||
use crate::colors;
|
||||
|
||||
pub const FONT_SIZE: f32 = 15.;
|
||||
pub const LINE_HEIGHT: f32 = 20.;
|
||||
use crate::{colors, fonts::TerminalFont};
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct RenderCell {
|
||||
@@ -27,11 +24,9 @@ pub struct RenderCell {
|
||||
pub cursor: CursorShape,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Renderer {
|
||||
pub font: TerminalFont,
|
||||
rows: Vec<CachedRow>,
|
||||
font: Option<Font>,
|
||||
cell_width: f32,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
@@ -85,26 +80,24 @@ struct TextStyle {
|
||||
}
|
||||
|
||||
impl Renderer {
|
||||
pub fn prepare(
|
||||
&mut self,
|
||||
rows: Vec<Vec<RenderCell>>,
|
||||
font: &Font,
|
||||
cell_width: f32,
|
||||
window: &mut Window,
|
||||
) {
|
||||
let metrics_changed = self.font.as_ref() != Some(font) || self.cell_width != cell_width;
|
||||
self.font = Some(font.clone());
|
||||
self.cell_width = cell_width;
|
||||
pub fn new(font: TerminalFont) -> Self {
|
||||
Self {
|
||||
font,
|
||||
rows: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn prepare(&mut self, rows: Vec<Vec<RenderCell>>, window: &mut Window) {
|
||||
self.rows.resize_with(rows.len(), CachedRow::default);
|
||||
for (cached, cells) in self.rows.iter_mut().zip(rows) {
|
||||
if !metrics_changed && cached.cells == cells {
|
||||
if cached.cells == cells {
|
||||
continue;
|
||||
}
|
||||
let (backgrounds, decorations, cursors) = assemble_quads(&cells);
|
||||
let (backgrounds, decorations, cursors) = assemble_quads(&cells, self.font.line_height);
|
||||
let text = assemble_text(&cells)
|
||||
.into_iter()
|
||||
.map(|segment| {
|
||||
let mut face = font.clone();
|
||||
let mut face = self.font.face.clone();
|
||||
if segment.bold {
|
||||
face = face.bold();
|
||||
}
|
||||
@@ -137,11 +130,11 @@ impl Renderer {
|
||||
unicode_color,
|
||||
line: window.text_system().shape_line(
|
||||
segment.text.into(),
|
||||
px(FONT_SIZE),
|
||||
px(self.font.size),
|
||||
&runs,
|
||||
// GPUI applies forced widths per glyph, so this
|
||||
// is valid only for non-ligature ASCII segments.
|
||||
segment.ascii.then_some(px(cell_width)),
|
||||
segment.ascii.then_some(px(self.font.cell_width)),
|
||||
),
|
||||
}
|
||||
})
|
||||
@@ -173,8 +166,8 @@ impl Renderer {
|
||||
.map(|row| row.cells.len())
|
||||
.max()
|
||||
.unwrap_or(0) as f32
|
||||
* self.cell_width),
|
||||
px(self.rows.len() as f32 * LINE_HEIGHT),
|
||||
* self.font.cell_width),
|
||||
px(self.rows.len() as f32 * self.font.line_height),
|
||||
),
|
||||
);
|
||||
// Non-overlapping backgrounds share one draw order. This avoids a
|
||||
@@ -186,10 +179,13 @@ impl Renderer {
|
||||
Bounds::new(
|
||||
origin
|
||||
+ point(
|
||||
px(span.column as f32 * self.cell_width),
|
||||
px(row_index as f32 * LINE_HEIGHT),
|
||||
px(span.column as f32 * self.font.cell_width),
|
||||
px(row_index as f32 * self.font.line_height),
|
||||
),
|
||||
size(px(span.columns as f32 * self.cell_width), px(LINE_HEIGHT)),
|
||||
size(
|
||||
px(span.columns as f32 * self.font.cell_width),
|
||||
px(self.font.line_height),
|
||||
),
|
||||
),
|
||||
span.color,
|
||||
));
|
||||
@@ -204,10 +200,13 @@ impl Renderer {
|
||||
}
|
||||
let position = origin
|
||||
+ point(
|
||||
px(text.column as f32 * self.cell_width),
|
||||
px(row_index as f32 * LINE_HEIGHT),
|
||||
px(text.column as f32 * self.font.cell_width),
|
||||
px(row_index as f32 * self.font.line_height),
|
||||
);
|
||||
if let Err(error) = text.line.paint(position, px(LINE_HEIGHT), window, cx) {
|
||||
if let Err(error) = text
|
||||
.line
|
||||
.paint(position, px(self.font.line_height), window, cx)
|
||||
{
|
||||
log::debug!("terminal text paint: {error}");
|
||||
}
|
||||
}
|
||||
@@ -223,11 +222,11 @@ impl Renderer {
|
||||
};
|
||||
let line = &text.line;
|
||||
let baseline =
|
||||
(px(LINE_HEIGHT) - line.ascent - line.descent) / 2. + line.ascent;
|
||||
(px(self.font.line_height) - line.ascent - line.descent) / 2. + line.ascent;
|
||||
let position = origin
|
||||
+ point(
|
||||
px(text.column as f32 * self.cell_width),
|
||||
px(row_index as f32 * LINE_HEIGHT) + baseline,
|
||||
px(text.column as f32 * self.font.cell_width),
|
||||
px(row_index as f32 * self.font.line_height) + baseline,
|
||||
);
|
||||
for run in &line.runs {
|
||||
for glyph in &run.glyphs {
|
||||
@@ -287,13 +286,13 @@ impl Renderer {
|
||||
Bounds::new(
|
||||
origin
|
||||
+ point(
|
||||
px(span.column as f32 * self.cell_width),
|
||||
px(row as f32 * LINE_HEIGHT + decoration.y),
|
||||
px(span.column as f32 * self.font.cell_width),
|
||||
px(row as f32 * self.font.line_height + decoration.y),
|
||||
),
|
||||
size(
|
||||
px(decoration
|
||||
.width
|
||||
.unwrap_or(span.columns as f32 * self.cell_width)),
|
||||
.unwrap_or(span.columns as f32 * self.font.cell_width)),
|
||||
px(decoration.height),
|
||||
),
|
||||
),
|
||||
@@ -302,7 +301,10 @@ impl Renderer {
|
||||
}
|
||||
}
|
||||
|
||||
fn assemble_quads(cells: &[RenderCell]) -> (Vec<Span>, Vec<Decoration>, Vec<Decoration>) {
|
||||
fn assemble_quads(
|
||||
cells: &[RenderCell],
|
||||
line_height: f32,
|
||||
) -> (Vec<Span>, Vec<Decoration>, Vec<Decoration>) {
|
||||
let mut backgrounds: Vec<Span> = Vec::new();
|
||||
let mut decorations: Vec<Decoration> = Vec::new();
|
||||
let mut cursors = Vec::new();
|
||||
@@ -326,7 +328,7 @@ fn assemble_quads(cells: &[RenderCell]) -> (Vec<Span>, Vec<Decoration>, Vec<Deco
|
||||
column,
|
||||
columns,
|
||||
cell.foreground,
|
||||
LINE_HEIGHT - 2.,
|
||||
line_height - 2.,
|
||||
);
|
||||
}
|
||||
if flags.contains(Flags::STRIKEOUT) {
|
||||
@@ -335,13 +337,13 @@ fn assemble_quads(cells: &[RenderCell]) -> (Vec<Span>, Vec<Decoration>, Vec<Deco
|
||||
column,
|
||||
columns,
|
||||
cell.foreground,
|
||||
LINE_HEIGHT / 2.,
|
||||
line_height / 2.,
|
||||
);
|
||||
}
|
||||
}
|
||||
let (y, height, width) = match cell.cursor {
|
||||
CursorShape::Beam => (0., LINE_HEIGHT, Some(2.)),
|
||||
CursorShape::Underline => (LINE_HEIGHT - 2., 2., None),
|
||||
CursorShape::Beam => (0., line_height, Some(2.)),
|
||||
CursorShape::Underline => (line_height - 2., 2., None),
|
||||
_ => continue,
|
||||
};
|
||||
cursors.push(Decoration {
|
||||
@@ -506,7 +508,7 @@ mod tests {
|
||||
fn blank_screen_has_no_text_or_background_work() {
|
||||
let cells = vec![cell(' '); 250];
|
||||
assert!(assemble_text(&cells).is_empty());
|
||||
let (backgrounds, decorations, cursors) = assemble_quads(&cells);
|
||||
let (backgrounds, decorations, cursors) = assemble_quads(&cells, 20.);
|
||||
assert!(backgrounds.is_empty() && decorations.is_empty() && cursors.is_empty());
|
||||
}
|
||||
|
||||
@@ -560,6 +562,24 @@ mod tests {
|
||||
assert!(!text[1].ascii && !text[2].ascii);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn decorations_and_cursors_follow_the_terminal_line_height() {
|
||||
let mut cells = vec![cell('a'), cell('b')];
|
||||
cells[0]
|
||||
.cell
|
||||
.flags
|
||||
.insert(Flags::UNDERLINE | Flags::STRIKEOUT);
|
||||
cells[0].cursor = CursorShape::Underline;
|
||||
cells[1].cursor = CursorShape::Beam;
|
||||
for height in [8., 20., 96.] {
|
||||
let (_, decorations, cursors) = assemble_quads(&cells, height);
|
||||
assert_eq!(decorations[0].y, height - 2.);
|
||||
assert_eq!(decorations[1].y, height / 2.);
|
||||
assert_eq!(cursors[0].y + cursors[0].height, height);
|
||||
assert_eq!(cursors[1].height, height);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn backgrounds_and_decorations_merge_without_painting_blank_defaults() {
|
||||
let mut cells = vec![cell(' '); 10];
|
||||
@@ -567,7 +587,7 @@ mod tests {
|
||||
c.background = rgb(0x123456).into();
|
||||
c.cell.flags.insert(Flags::UNDERLINE | Flags::STRIKEOUT);
|
||||
}
|
||||
let (backgrounds, decorations, _) = assemble_quads(&cells);
|
||||
let (backgrounds, decorations, _) = assemble_quads(&cells, 20.);
|
||||
assert_eq!(backgrounds.len(), 1);
|
||||
assert_eq!((backgrounds[0].column, backgrounds[0].columns), (2, 5));
|
||||
assert_eq!(decorations.len(), 2);
|
||||
|
||||
+92
-54
@@ -5,6 +5,7 @@ use crate::{
|
||||
colors,
|
||||
commands::{self, CommandAction},
|
||||
cursor::CursorAnimator,
|
||||
fonts::{self, TerminalFont},
|
||||
input,
|
||||
label::middle_label,
|
||||
palette::CommandPalette,
|
||||
@@ -13,7 +14,7 @@ use crate::{
|
||||
ClientMessage, Direction, PaneSnapshot, ScrollKind, SelectionCommand, SelectionKind,
|
||||
SelectionSide, Snapshot, StackPaneInfo, VerticalDirection,
|
||||
},
|
||||
render::{FONT_SIZE, LINE_HEIGHT, RenderCell, Renderer},
|
||||
render::{RenderCell, Renderer},
|
||||
transition::Slide,
|
||||
};
|
||||
use alacritty_terminal::{
|
||||
@@ -38,6 +39,7 @@ struct TabRename {
|
||||
pub struct Workspace {
|
||||
client: Client,
|
||||
connection: SharedString,
|
||||
font: TerminalFont,
|
||||
snapshot: Option<Arc<Snapshot>>,
|
||||
panes: HashMap<u64, Entity<TerminalPane>>,
|
||||
error: Option<String>,
|
||||
@@ -157,28 +159,25 @@ impl Workspace {
|
||||
}
|
||||
|
||||
fn key_down(&mut self, event: &KeyDownEvent, window: &mut Window, cx: &mut Context<Self>) {
|
||||
let key = &event.keystroke;
|
||||
let command = (key.modifiers.control || key.modifiers.platform)
|
||||
&& key.modifiers.shift
|
||||
&& !key.modifiers.alt;
|
||||
if command && key.key.eq_ignore_ascii_case("p") {
|
||||
self.open_palette(window, cx);
|
||||
cx.stop_propagation();
|
||||
let Some(action) = crate::bindings::action_for_key(&event.keystroke) else {
|
||||
return;
|
||||
}
|
||||
if self.palette.is_some()
|
||||
};
|
||||
// Window commands remain available while a text field has focus.
|
||||
if !matches!(
|
||||
action,
|
||||
CommandAction::TogglePalette
|
||||
| CommandAction::IncreaseFontSize
|
||||
| CommandAction::DecreaseFontSize
|
||||
) && (self.palette.is_some()
|
||||
|| self.tab_rename.is_some()
|
||||
|| self
|
||||
.focused_pane()
|
||||
.is_some_and(|pane| pane.read(cx).rename.is_some())
|
||||
.is_some_and(|pane| pane.read(cx).rename.is_some()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
let action = crate::bindings::action_for_key(key);
|
||||
if let Some(action) = action {
|
||||
self.execute(action, window, cx);
|
||||
cx.stop_propagation();
|
||||
}
|
||||
self.execute(action, window, cx);
|
||||
cx.stop_propagation();
|
||||
}
|
||||
|
||||
fn execute(&mut self, action: CommandAction, window: &mut Window, cx: &mut Context<Self>) {
|
||||
@@ -186,6 +185,28 @@ impl Workspace {
|
||||
let pane = self.focused_pane();
|
||||
let pane_id = pane.as_ref().map(|pane| pane.read(cx).data().id);
|
||||
let message = match action {
|
||||
TogglePalette => {
|
||||
self.open_palette(window, cx);
|
||||
None
|
||||
}
|
||||
IncreaseFontSize | DecreaseFontSize => {
|
||||
let delta = if matches!(action, IncreaseFontSize) {
|
||||
1.
|
||||
} else {
|
||||
-1.
|
||||
};
|
||||
if self.font.adjust_size(delta, window.text_system()) {
|
||||
for pane in self.panes.values().chain(self.outgoing.values()) {
|
||||
pane.update(cx, |pane, cx| {
|
||||
pane.renderer = Renderer::new(self.font.clone());
|
||||
pane.prepared_revision = None;
|
||||
pane.requested_size = None;
|
||||
cx.notify();
|
||||
});
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
NewTab => Some(ClientMessage::NewTab { cwd: None }),
|
||||
SplitPane => pane_id.map(|pane| ClientMessage::Split { pane, cwd: None }),
|
||||
StackAbove | StackBelow => Some(ClientMessage::NewStackPane {
|
||||
@@ -278,6 +299,9 @@ impl Workspace {
|
||||
) -> Self {
|
||||
let focus = cx.focus_handle();
|
||||
window.focus(&focus);
|
||||
// Scene transitions rebuild pane views. Keep system font discovery and
|
||||
// cell measurement outside that path, once per workspace.
|
||||
let font = fonts::terminal_font(window.text_system());
|
||||
let task = cx.spawn_in(window, async move |view, cx| {
|
||||
while let Some(update) = updates.recv().await {
|
||||
if cx
|
||||
@@ -374,10 +398,13 @@ impl Workspace {
|
||||
frame,
|
||||
index,
|
||||
active == Some(data.id),
|
||||
focus_allowed,
|
||||
view.font.clone(),
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
if pane.active && focus_allowed {
|
||||
window.focus(&pane.focus);
|
||||
}
|
||||
pane.transitioning = view.transition.is_some();
|
||||
pane
|
||||
});
|
||||
@@ -417,6 +444,7 @@ impl Workspace {
|
||||
Self {
|
||||
client,
|
||||
connection,
|
||||
font,
|
||||
snapshot: None,
|
||||
panes: HashMap::new(),
|
||||
error: None,
|
||||
@@ -703,9 +731,7 @@ struct TerminalPane {
|
||||
read_only: bool,
|
||||
transitioning: bool,
|
||||
focus: FocusHandle,
|
||||
font: Font,
|
||||
bounds: Bounds<Pixels>,
|
||||
cell_width: f32,
|
||||
selecting: bool,
|
||||
scroll_remainder: f32,
|
||||
preedit: String,
|
||||
@@ -725,23 +751,17 @@ impl TerminalPane {
|
||||
snapshot: Arc<Snapshot>,
|
||||
index: usize,
|
||||
active: bool,
|
||||
focus_allowed: bool,
|
||||
font: TerminalFont,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Self {
|
||||
let font = crate::fonts::terminal_font(window.text_system());
|
||||
let font_id = window.text_system().resolve_font(&font);
|
||||
let cell_width = window
|
||||
.text_system()
|
||||
.advance(font_id, px(FONT_SIZE), 'M')
|
||||
.map(|s| f32::from(s.width))
|
||||
.unwrap_or(9.)
|
||||
.max(1.);
|
||||
let focus = cx.focus_handle();
|
||||
if active && focus_allowed {
|
||||
window.focus(&focus);
|
||||
}
|
||||
let activation = cx.observe_window_activation(window, |pane, _, cx| {
|
||||
let activation = cx.observe_window_activation(window, |pane, window, cx| {
|
||||
if window.is_window_active() {
|
||||
// Each attached window has its own zoom and viewport. The focused
|
||||
// window sets the shared PTY dimensions.
|
||||
pane.requested_size = None;
|
||||
}
|
||||
pane.blink_timer = None;
|
||||
cx.notify();
|
||||
});
|
||||
@@ -753,15 +773,13 @@ impl TerminalPane {
|
||||
read_only: false,
|
||||
transitioning: false,
|
||||
focus,
|
||||
font,
|
||||
bounds: Bounds::default(),
|
||||
cell_width,
|
||||
selecting: false,
|
||||
scroll_remainder: 0.,
|
||||
preedit: String::new(),
|
||||
cursor_bounds: Bounds::default(),
|
||||
cursor: CursorAnimator::new(),
|
||||
renderer: Renderer::default(),
|
||||
renderer: Renderer::new(font),
|
||||
rename: None,
|
||||
prepared_revision: None,
|
||||
requested_size: None,
|
||||
@@ -916,9 +934,11 @@ impl TerminalPane {
|
||||
}
|
||||
}
|
||||
fn grid_point(&self, position: Point<Pixels>) -> (u16, u16, SelectionSide) {
|
||||
let x = ((f32::from(position.x - self.bounds.left()) - PADDING).max(0.) / self.cell_width)
|
||||
let x = ((f32::from(position.x - self.bounds.left()) - PADDING).max(0.)
|
||||
/ self.renderer.font.cell_width)
|
||||
.min(f32::from(self.data().columns - 1));
|
||||
let y = ((f32::from(position.y - self.bounds.top()) - PADDING).max(0.) / LINE_HEIGHT)
|
||||
let y = ((f32::from(position.y - self.bounds.top()) - PADDING).max(0.)
|
||||
/ self.renderer.font.line_height)
|
||||
.min(f32::from(self.data().lines - 1));
|
||||
(
|
||||
x as u16,
|
||||
@@ -970,7 +990,7 @@ impl TerminalPane {
|
||||
}
|
||||
self.scroll_remainder += match event.delta {
|
||||
ScrollDelta::Lines(d) => d.y * 3.,
|
||||
ScrollDelta::Pixels(d) => f32::from(d.y) / LINE_HEIGHT,
|
||||
ScrollDelta::Pixels(d) => f32::from(d.y) / self.renderer.font.line_height,
|
||||
};
|
||||
let lines = self.scroll_remainder.trunc() as i32;
|
||||
self.scroll_remainder -= lines as f32;
|
||||
@@ -996,20 +1016,24 @@ impl TerminalPane {
|
||||
}
|
||||
}
|
||||
fn prepare(&mut self, bounds: Bounds<Pixels>, window: &mut Window) {
|
||||
let columns = ((f32::from(bounds.size.width) - 2. * PADDING) / self.cell_width)
|
||||
let font = &self.renderer.font;
|
||||
let columns = ((f32::from(bounds.size.width) - 2. * PADDING) / font.cell_width)
|
||||
.floor()
|
||||
.clamp(2., 1000.) as u16;
|
||||
let lines = ((f32::from(bounds.size.height) - 2. * PADDING) / LINE_HEIGHT)
|
||||
let lines = ((f32::from(bounds.size.height) - 2. * PADDING) / font.line_height)
|
||||
.floor()
|
||||
.clamp(1., 500.) as u16;
|
||||
if !self.read_only && self.requested_size != Some((columns, lines)) {
|
||||
if !self.read_only
|
||||
&& window.is_window_active()
|
||||
&& self.requested_size != Some((columns, lines))
|
||||
{
|
||||
self.requested_size = Some((columns, lines));
|
||||
self.command(ClientMessage::Resize {
|
||||
pane: self.data().id,
|
||||
columns,
|
||||
lines,
|
||||
cell_width: self.cell_width.round() as u16,
|
||||
cell_height: LINE_HEIGHT as u16,
|
||||
cell_width: font.cell_width.round() as u16,
|
||||
cell_height: font.line_height as u16,
|
||||
});
|
||||
}
|
||||
let prepare_rows = self.prepared_revision != Some(self.snapshot.revision)
|
||||
@@ -1038,12 +1062,12 @@ impl TerminalPane {
|
||||
let cursor_bounds = Bounds::new(
|
||||
bounds.origin
|
||||
+ point(
|
||||
px(PADDING + f32::from(cursor.column) * self.cell_width),
|
||||
px(PADDING + cursor.row as f32 * LINE_HEIGHT),
|
||||
px(PADDING + f32::from(cursor.column) * font.cell_width),
|
||||
px(PADDING + cursor.row as f32 * font.line_height),
|
||||
),
|
||||
size(
|
||||
px(self.cell_width * if wide { 2. } else { 1. }),
|
||||
px(LINE_HEIGHT),
|
||||
px(font.cell_width * if wide { 2. } else { 1. }),
|
||||
px(font.line_height),
|
||||
),
|
||||
);
|
||||
let mut cursor_color = colors::resolve(Color::Named(NamedColor::Cursor), &palette);
|
||||
@@ -1087,8 +1111,7 @@ impl TerminalPane {
|
||||
.collect()
|
||||
})
|
||||
.collect();
|
||||
self.renderer
|
||||
.prepare(rows, &self.font, self.cell_width, window);
|
||||
self.renderer.prepare(rows, window);
|
||||
self.prepared_revision = Some(self.snapshot.revision);
|
||||
log::debug!(target:"psyterm::timing","prepare_us={}",started.elapsed().as_micros());
|
||||
}
|
||||
@@ -1150,11 +1173,26 @@ impl Render for TerminalPane {
|
||||
}
|
||||
});
|
||||
if !pane.preedit.is_empty() {
|
||||
let run=TextRun{len:pane.preedit.len(),font:pane.font.clone(),color:rgb(chrome::TEXT).into(),background_color:Some(rgb(chrome::TERMINAL_BACKGROUND).into()),
|
||||
underline:Some(UnderlineStyle{thickness:px(1.),color:None,wavy:false}),strikethrough:None};
|
||||
let shaped=window.text_system().shape_line(pane.preedit.clone().into(),px(FONT_SIZE),&[run],None);
|
||||
let _=shaped.paint_background(pane.cursor_bounds.origin,px(LINE_HEIGHT),window,cx);
|
||||
let _=shaped.paint(pane.cursor_bounds.origin,px(LINE_HEIGHT),window,cx);
|
||||
let font = &pane.renderer.font;
|
||||
let run = TextRun {
|
||||
len: pane.preedit.len(),
|
||||
font: font.face.clone(),
|
||||
color: rgb(chrome::TEXT).into(),
|
||||
background_color: Some(rgb(chrome::TERMINAL_BACKGROUND).into()),
|
||||
underline: Some(UnderlineStyle {
|
||||
thickness: px(1.),
|
||||
color: None,
|
||||
wavy: false,
|
||||
}),
|
||||
strikethrough: None,
|
||||
};
|
||||
let line = window.text_system().shape_line(
|
||||
pane.preedit.clone().into(), px(font.size), &[run], None,
|
||||
);
|
||||
let origin = pane.cursor_bounds.origin;
|
||||
let height = px(font.line_height);
|
||||
let _ = line.paint_background(origin, height, window, cx);
|
||||
let _ = line.paint(origin, height, window, cx);
|
||||
}
|
||||
});
|
||||
pane.schedule_cursor(delay,window,cx);
|
||||
|
||||
Reference in New Issue
Block a user