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
|
## Controls
|
||||||
|
|
||||||
| Input | Action |
|
| Action | macOS | Linux |
|
||||||
| --- | --- |
|
| --- | --- | --- |
|
||||||
| Ctrl/Cmd+Shift+P | Open the command palette |
|
| Increase terminal text size | Cmd+Plus or Cmd+= | Ctrl+Plus or Ctrl+= |
|
||||||
| Click a tab | Switch the server's active tab |
|
| Decrease terminal text size | Cmd+Minus | Ctrl+Minus |
|
||||||
| `+` or Ctrl+Shift+T | Create a tab |
|
| Open or dismiss the command palette | Cmd+Shift+P | Ctrl+Shift+P |
|
||||||
| Ctrl+Shift+D or Alt+\ | Add a pane beside the focused pane |
|
| Create a tab | Cmd+T | Ctrl+Shift+T |
|
||||||
| Alt+Left / Right | Focus the adjacent pane, then adjacent tab at the edge |
|
| Add a pane to the right | Cmd+D | Ctrl+Shift+D or Alt+\ |
|
||||||
| Alt+Shift+[ / ] | Switch to the previous / next tab |
|
| Insert a stacked pane above / below | Option+Shift+Up / Cmd+Shift+D | Alt+Shift+Up / Down |
|
||||||
| Alt+Shift+N or Alt+Shift+Right | Create a tab |
|
| Focus the adjacent pane or tab | Cmd+Option+Left / Right | Alt+Left / Right |
|
||||||
| Alt+Shift+Up / Down | Insert a stacked pane above / below the current pane |
|
| Switch tabs | Cmd+Shift+[ / ] | Alt+Shift+[ / ] |
|
||||||
| Alt+Up / Down | Expand the previous / next stacked pane |
|
| Focus the previous / next stacked pane | Cmd+Option+Up / Down | Alt+Up / Down |
|
||||||
| Click a collapsed pane title | Expand and focus that pane |
|
| Cycle through panes | Cmd+[ / ] | Ctrl+Shift+Left / Right |
|
||||||
| Ctrl+Shift+Left / Right | Focus the previous / next pane |
|
| Close the focused pane and its shell | Cmd+W | Ctrl+Shift+W |
|
||||||
| Ctrl+Shift+W | Close the focused pane and its shell |
|
| Rename the focused pane | Cmd+Shift+R | Ctrl+Shift+R |
|
||||||
| Ctrl+Shift+R | Edit the pane name |
|
| Copy selection / paste | Cmd+C / Cmd+V | Ctrl+Shift+C / Ctrl+Shift+V |
|
||||||
| Palette → Rename tab | Edit the selected tab's name |
|
| Quit the GUI and keep sessions running | Cmd+Q | Window `×` |
|
||||||
| Enter / Esc while renaming | Save / cancel the edit |
|
| Scroll one page | Shift+PageUp / PageDown | Shift+PageUp / PageDown |
|
||||||
| Save a blank name | Restore automatic pane/tab naming |
|
| Jump to oldest history / live screen | Shift+Home / End | Shift+Home / End |
|
||||||
| 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 |
|
|
||||||
|
|
||||||
Navigation follows the `shared` bindings in `~/.config/zellij/config.kdl`, with
|
Click a tab to switch, `+` to create a tab, or a collapsed pane title to expand it.
|
||||||
Alt+\ from its default `locked` mode. Existing psyTerm shortcuts remain available;
|
Drag, double-click, or triple-click to select text, a word, or a line. Scroll with
|
||||||
Zellij's modal Ctrl bindings are left to terminal programs.
|
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
|
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
|
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,
|
Font preference is Hermit (including Hurmit Nerd Font variants), SF Mono,
|
||||||
Noto Sans Mono, Iosevka, then another verified fixed-pitch family. Text uses
|
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,
|
colors, truecolor, bold/italic/dim, underline, reverse video, wide characters,
|
||||||
and combining marks. Alacritty supplies terminal modes and 10,000 lines of
|
and combining marks. Alacritty supplies terminal modes and 10,000 lines of
|
||||||
scrollback by default.
|
scrollback by default.
|
||||||
|
|||||||
+110
-1
@@ -1,14 +1,55 @@
|
|||||||
//! Application shortcuts, including the user's Zellij `locked`/`shared` map.
|
//! Application shortcuts, including the user's Zellij `locked`/`shared` map.
|
||||||
//! Registry commands remain available even when they have no shortcut here.
|
//! Registry commands remain available even when they have no shortcut here.
|
||||||
use gpui::Keystroke;
|
use gpui::{Keystroke, Modifiers};
|
||||||
|
|
||||||
use crate::commands::CommandAction;
|
use crate::commands::CommandAction;
|
||||||
|
|
||||||
pub fn action_for_key(key: &Keystroke) -> Option<CommandAction> {
|
pub fn action_for_key(key: &Keystroke) -> Option<CommandAction> {
|
||||||
let modifiers = key.modifiers;
|
let modifiers = key.modifiers;
|
||||||
let name = key.key.to_lowercase();
|
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 {
|
if (modifiers.control || modifiers.platform) && modifiers.shift && !modifiers.alt {
|
||||||
return Some(match name.as_str() {
|
return Some(match name.as_str() {
|
||||||
|
"p" => CommandAction::TogglePalette,
|
||||||
"t" => CommandAction::NewTab,
|
"t" => CommandAction::NewTab,
|
||||||
"d" => CommandAction::SplitPane,
|
"d" => CommandAction::SplitPane,
|
||||||
"w" => CommandAction::ClosePane,
|
"w" => CommandAction::ClosePane,
|
||||||
@@ -77,6 +118,15 @@ mod tests {
|
|||||||
Some(CommandAction::FocusRight)
|
Some(CommandAction::FocusRight)
|
||||||
));
|
));
|
||||||
assert!(matches!(action("alt-\\"), Some(CommandAction::SplitPane)));
|
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!(
|
assert!(matches!(
|
||||||
action("ctrl-shift-left"),
|
action("ctrl-shift-left"),
|
||||||
Some(CommandAction::PreviousPane)
|
Some(CommandAction::PreviousPane)
|
||||||
@@ -84,6 +134,65 @@ mod tests {
|
|||||||
assert!(matches!(action("cmd-shift-t"), Some(CommandAction::NewTab)));
|
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]
|
#[test]
|
||||||
fn stacked_panes_use_the_requested_vertical_bindings() {
|
fn stacked_panes_use_the_requested_vertical_bindings() {
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
|
|||||||
+41
-16
@@ -6,7 +6,10 @@ use crate::protocol::{ScrollKind, Snapshot};
|
|||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum CommandAction {
|
pub enum CommandAction {
|
||||||
|
TogglePalette,
|
||||||
NewTab,
|
NewTab,
|
||||||
|
IncreaseFontSize,
|
||||||
|
DecreaseFontSize,
|
||||||
SplitPane,
|
SplitPane,
|
||||||
StackAbove,
|
StackAbove,
|
||||||
StackBelow,
|
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.
|
/// The complete command list. UI state affects availability, never discovery.
|
||||||
pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
||||||
use CommandAction::*;
|
use CommandAction::*;
|
||||||
@@ -98,14 +109,14 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
|||||||
"new-tab",
|
"new-tab",
|
||||||
"New tab",
|
"New tab",
|
||||||
"create shell terminal",
|
"create shell terminal",
|
||||||
Some("Ctrl+Shift+T"),
|
shortcut("Cmd+T", "Ctrl+Shift+T"),
|
||||||
NewTab,
|
NewTab,
|
||||||
),
|
),
|
||||||
PaletteItem::action(
|
PaletteItem::action(
|
||||||
"split-pane",
|
"split-pane",
|
||||||
"Split pane right",
|
"Split pane right",
|
||||||
"new create horizontal shell",
|
"new create horizontal shell",
|
||||||
Some("Ctrl+Shift+D"),
|
shortcut("Cmd+D", "Ctrl+Shift+D"),
|
||||||
SplitPane,
|
SplitPane,
|
||||||
)
|
)
|
||||||
.available(pane),
|
.available(pane),
|
||||||
@@ -113,7 +124,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
|||||||
"close-pane",
|
"close-pane",
|
||||||
"Close pane",
|
"Close pane",
|
||||||
"exit shell terminate",
|
"exit shell terminate",
|
||||||
Some("Ctrl+Shift+W"),
|
shortcut("Cmd+W", "Ctrl+Shift+W"),
|
||||||
ClosePane,
|
ClosePane,
|
||||||
)
|
)
|
||||||
.available(pane),
|
.available(pane),
|
||||||
@@ -121,7 +132,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
|||||||
"rename-pane",
|
"rename-pane",
|
||||||
"Rename pane",
|
"Rename pane",
|
||||||
"name title label",
|
"name title label",
|
||||||
Some("Ctrl+Shift+R"),
|
shortcut("Cmd+Shift+R", "Ctrl+Shift+R"),
|
||||||
RenamePane,
|
RenamePane,
|
||||||
)
|
)
|
||||||
.available(pane),
|
.available(pane),
|
||||||
@@ -153,7 +164,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
|||||||
"previous-tab",
|
"previous-tab",
|
||||||
"Previous tab",
|
"Previous tab",
|
||||||
"switch navigate left",
|
"switch navigate left",
|
||||||
Some("Alt+Shift+["),
|
shortcut("Cmd+Shift+[", "Alt+Shift+["),
|
||||||
PreviousTab,
|
PreviousTab,
|
||||||
)
|
)
|
||||||
.available(tabs),
|
.available(tabs),
|
||||||
@@ -161,7 +172,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
|||||||
"next-tab",
|
"next-tab",
|
||||||
"Next tab",
|
"Next tab",
|
||||||
"switch navigate right",
|
"switch navigate right",
|
||||||
Some("Alt+Shift+]"),
|
shortcut("Cmd+Shift+]", "Alt+Shift+]"),
|
||||||
NextTab,
|
NextTab,
|
||||||
)
|
)
|
||||||
.available(tabs),
|
.available(tabs),
|
||||||
@@ -169,7 +180,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
|||||||
"previous-pane",
|
"previous-pane",
|
||||||
"Previous pane",
|
"Previous pane",
|
||||||
"switch focus cycle",
|
"switch focus cycle",
|
||||||
Some("Ctrl+Shift+Left"),
|
shortcut("Cmd+[", "Ctrl+Shift+Left"),
|
||||||
PreviousPane,
|
PreviousPane,
|
||||||
)
|
)
|
||||||
.available(pane),
|
.available(pane),
|
||||||
@@ -177,7 +188,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
|||||||
"next-pane",
|
"next-pane",
|
||||||
"Next pane",
|
"Next pane",
|
||||||
"switch focus cycle",
|
"switch focus cycle",
|
||||||
Some("Ctrl+Shift+Right"),
|
shortcut("Cmd+]", "Ctrl+Shift+Right"),
|
||||||
NextPane,
|
NextPane,
|
||||||
)
|
)
|
||||||
.available(pane),
|
.available(pane),
|
||||||
@@ -185,7 +196,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
|||||||
"focus-left",
|
"focus-left",
|
||||||
"Focus pane or tab left",
|
"Focus pane or tab left",
|
||||||
"navigate previous horizontal",
|
"navigate previous horizontal",
|
||||||
Some("Alt+Left"),
|
shortcut("Cmd+Option+Left", "Alt+Left"),
|
||||||
FocusLeft,
|
FocusLeft,
|
||||||
)
|
)
|
||||||
.available(pane),
|
.available(pane),
|
||||||
@@ -193,7 +204,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
|||||||
"focus-right",
|
"focus-right",
|
||||||
"Focus pane or tab right",
|
"Focus pane or tab right",
|
||||||
"navigate next horizontal",
|
"navigate next horizontal",
|
||||||
Some("Alt+Right"),
|
shortcut("Cmd+Option+Right", "Alt+Right"),
|
||||||
FocusRight,
|
FocusRight,
|
||||||
)
|
)
|
||||||
.available(pane),
|
.available(pane),
|
||||||
@@ -201,7 +212,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
|||||||
"copy",
|
"copy",
|
||||||
"Copy selection",
|
"Copy selection",
|
||||||
"clipboard text",
|
"clipboard text",
|
||||||
Some("Ctrl+Shift+C"),
|
shortcut("Cmd+C", "Ctrl+Shift+C"),
|
||||||
Copy,
|
Copy,
|
||||||
)
|
)
|
||||||
.available(pane),
|
.available(pane),
|
||||||
@@ -209,10 +220,24 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
|||||||
"paste",
|
"paste",
|
||||||
"Paste",
|
"Paste",
|
||||||
"clipboard text",
|
"clipboard text",
|
||||||
Some("Ctrl+Shift+V"),
|
shortcut("Cmd+V", "Ctrl+Shift+V"),
|
||||||
Paste,
|
Paste,
|
||||||
)
|
)
|
||||||
.available(pane),
|
.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(
|
PaletteItem::action(
|
||||||
"history-page-up",
|
"history-page-up",
|
||||||
"Scroll history up one page",
|
"Scroll history up one page",
|
||||||
@@ -258,7 +283,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
|||||||
"stack-above",
|
"stack-above",
|
||||||
"New stacked pane above",
|
"New stacked pane above",
|
||||||
"create shell vertical up",
|
"create shell vertical up",
|
||||||
Some("Alt+Shift+Up"),
|
shortcut("Option+Shift+Up", "Alt+Shift+Up"),
|
||||||
StackAbove,
|
StackAbove,
|
||||||
)
|
)
|
||||||
.available(pane),
|
.available(pane),
|
||||||
@@ -266,7 +291,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
|||||||
"stack-below",
|
"stack-below",
|
||||||
"New stacked pane below",
|
"New stacked pane below",
|
||||||
"create shell vertical down",
|
"create shell vertical down",
|
||||||
Some("Alt+Shift+Down"),
|
shortcut("Cmd+Shift+D", "Alt+Shift+Down"),
|
||||||
StackBelow,
|
StackBelow,
|
||||||
)
|
)
|
||||||
.available(pane),
|
.available(pane),
|
||||||
@@ -274,7 +299,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
|||||||
"focus-above",
|
"focus-above",
|
||||||
"Focus stacked pane above",
|
"Focus stacked pane above",
|
||||||
"switch vertical up previous",
|
"switch vertical up previous",
|
||||||
Some("Alt+Up"),
|
shortcut("Cmd+Option+Up", "Alt+Up"),
|
||||||
FocusAbove,
|
FocusAbove,
|
||||||
)
|
)
|
||||||
.available(pane),
|
.available(pane),
|
||||||
@@ -282,7 +307,7 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
|||||||
"focus-below",
|
"focus-below",
|
||||||
"Focus stacked pane below",
|
"Focus stacked pane below",
|
||||||
"switch vertical down next",
|
"switch vertical down next",
|
||||||
Some("Alt+Down"),
|
shortcut("Cmd+Option+Down", "Alt+Down"),
|
||||||
FocusBelow,
|
FocusBelow,
|
||||||
)
|
)
|
||||||
.available(pane),
|
.available(pane),
|
||||||
|
|||||||
+37
-2
@@ -15,13 +15,48 @@ const PREFERRED: &[&str] = &[
|
|||||||
"Iosevka Term",
|
"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 families = text_system.all_font_names();
|
||||||
let family = select_family(&families, |family| is_monospace(text_system, family)).expect(
|
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",
|
"No usable monospace font found; install Hermit, Noto Sans Mono, or DejaVu Sans Mono",
|
||||||
);
|
);
|
||||||
log::info!("Terminal font: {family}");
|
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> {
|
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,
|
vte::ansi::CursorShape,
|
||||||
};
|
};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
App, Bounds, Font, FontFeatures, Hsla, Pixels, Point, ShapedLine, TextRun, Window, fill, point,
|
App, Bounds, FontFeatures, Hsla, Pixels, Point, ShapedLine, TextRun, Window, fill, point, px,
|
||||||
px, rgb, size,
|
rgb, size,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::colors;
|
use crate::{colors, fonts::TerminalFont};
|
||||||
|
|
||||||
pub const FONT_SIZE: f32 = 15.;
|
|
||||||
pub const LINE_HEIGHT: f32 = 20.;
|
|
||||||
|
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub struct RenderCell {
|
pub struct RenderCell {
|
||||||
@@ -27,11 +24,9 @@ pub struct RenderCell {
|
|||||||
pub cursor: CursorShape,
|
pub cursor: CursorShape,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct Renderer {
|
pub struct Renderer {
|
||||||
|
pub font: TerminalFont,
|
||||||
rows: Vec<CachedRow>,
|
rows: Vec<CachedRow>,
|
||||||
font: Option<Font>,
|
|
||||||
cell_width: f32,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@@ -85,26 +80,24 @@ struct TextStyle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Renderer {
|
impl Renderer {
|
||||||
pub fn prepare(
|
pub fn new(font: TerminalFont) -> Self {
|
||||||
&mut self,
|
Self {
|
||||||
rows: Vec<Vec<RenderCell>>,
|
font,
|
||||||
font: &Font,
|
rows: Vec::new(),
|
||||||
cell_width: f32,
|
}
|
||||||
window: &mut Window,
|
}
|
||||||
) {
|
|
||||||
let metrics_changed = self.font.as_ref() != Some(font) || self.cell_width != cell_width;
|
pub fn prepare(&mut self, rows: Vec<Vec<RenderCell>>, window: &mut Window) {
|
||||||
self.font = Some(font.clone());
|
|
||||||
self.cell_width = cell_width;
|
|
||||||
self.rows.resize_with(rows.len(), CachedRow::default);
|
self.rows.resize_with(rows.len(), CachedRow::default);
|
||||||
for (cached, cells) in self.rows.iter_mut().zip(rows) {
|
for (cached, cells) in self.rows.iter_mut().zip(rows) {
|
||||||
if !metrics_changed && cached.cells == cells {
|
if cached.cells == cells {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let (backgrounds, decorations, cursors) = assemble_quads(&cells);
|
let (backgrounds, decorations, cursors) = assemble_quads(&cells, self.font.line_height);
|
||||||
let text = assemble_text(&cells)
|
let text = assemble_text(&cells)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|segment| {
|
.map(|segment| {
|
||||||
let mut face = font.clone();
|
let mut face = self.font.face.clone();
|
||||||
if segment.bold {
|
if segment.bold {
|
||||||
face = face.bold();
|
face = face.bold();
|
||||||
}
|
}
|
||||||
@@ -137,11 +130,11 @@ impl Renderer {
|
|||||||
unicode_color,
|
unicode_color,
|
||||||
line: window.text_system().shape_line(
|
line: window.text_system().shape_line(
|
||||||
segment.text.into(),
|
segment.text.into(),
|
||||||
px(FONT_SIZE),
|
px(self.font.size),
|
||||||
&runs,
|
&runs,
|
||||||
// GPUI applies forced widths per glyph, so this
|
// GPUI applies forced widths per glyph, so this
|
||||||
// is valid only for non-ligature ASCII segments.
|
// 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())
|
.map(|row| row.cells.len())
|
||||||
.max()
|
.max()
|
||||||
.unwrap_or(0) as f32
|
.unwrap_or(0) as f32
|
||||||
* self.cell_width),
|
* self.font.cell_width),
|
||||||
px(self.rows.len() as f32 * LINE_HEIGHT),
|
px(self.rows.len() as f32 * self.font.line_height),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
// Non-overlapping backgrounds share one draw order. This avoids a
|
// Non-overlapping backgrounds share one draw order. This avoids a
|
||||||
@@ -186,10 +179,13 @@ impl Renderer {
|
|||||||
Bounds::new(
|
Bounds::new(
|
||||||
origin
|
origin
|
||||||
+ point(
|
+ point(
|
||||||
px(span.column as f32 * self.cell_width),
|
px(span.column as f32 * self.font.cell_width),
|
||||||
px(row_index as f32 * LINE_HEIGHT),
|
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,
|
span.color,
|
||||||
));
|
));
|
||||||
@@ -204,10 +200,13 @@ impl Renderer {
|
|||||||
}
|
}
|
||||||
let position = origin
|
let position = origin
|
||||||
+ point(
|
+ point(
|
||||||
px(text.column as f32 * self.cell_width),
|
px(text.column as f32 * self.font.cell_width),
|
||||||
px(row_index as f32 * LINE_HEIGHT),
|
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}");
|
log::debug!("terminal text paint: {error}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -223,11 +222,11 @@ impl Renderer {
|
|||||||
};
|
};
|
||||||
let line = &text.line;
|
let line = &text.line;
|
||||||
let baseline =
|
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
|
let position = origin
|
||||||
+ point(
|
+ point(
|
||||||
px(text.column as f32 * self.cell_width),
|
px(text.column as f32 * self.font.cell_width),
|
||||||
px(row_index as f32 * LINE_HEIGHT) + baseline,
|
px(row_index as f32 * self.font.line_height) + baseline,
|
||||||
);
|
);
|
||||||
for run in &line.runs {
|
for run in &line.runs {
|
||||||
for glyph in &run.glyphs {
|
for glyph in &run.glyphs {
|
||||||
@@ -287,13 +286,13 @@ impl Renderer {
|
|||||||
Bounds::new(
|
Bounds::new(
|
||||||
origin
|
origin
|
||||||
+ point(
|
+ point(
|
||||||
px(span.column as f32 * self.cell_width),
|
px(span.column as f32 * self.font.cell_width),
|
||||||
px(row as f32 * LINE_HEIGHT + decoration.y),
|
px(row as f32 * self.font.line_height + decoration.y),
|
||||||
),
|
),
|
||||||
size(
|
size(
|
||||||
px(decoration
|
px(decoration
|
||||||
.width
|
.width
|
||||||
.unwrap_or(span.columns as f32 * self.cell_width)),
|
.unwrap_or(span.columns as f32 * self.font.cell_width)),
|
||||||
px(decoration.height),
|
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 backgrounds: Vec<Span> = Vec::new();
|
||||||
let mut decorations: Vec<Decoration> = Vec::new();
|
let mut decorations: Vec<Decoration> = Vec::new();
|
||||||
let mut cursors = Vec::new();
|
let mut cursors = Vec::new();
|
||||||
@@ -326,7 +328,7 @@ fn assemble_quads(cells: &[RenderCell]) -> (Vec<Span>, Vec<Decoration>, Vec<Deco
|
|||||||
column,
|
column,
|
||||||
columns,
|
columns,
|
||||||
cell.foreground,
|
cell.foreground,
|
||||||
LINE_HEIGHT - 2.,
|
line_height - 2.,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if flags.contains(Flags::STRIKEOUT) {
|
if flags.contains(Flags::STRIKEOUT) {
|
||||||
@@ -335,13 +337,13 @@ fn assemble_quads(cells: &[RenderCell]) -> (Vec<Span>, Vec<Decoration>, Vec<Deco
|
|||||||
column,
|
column,
|
||||||
columns,
|
columns,
|
||||||
cell.foreground,
|
cell.foreground,
|
||||||
LINE_HEIGHT / 2.,
|
line_height / 2.,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let (y, height, width) = match cell.cursor {
|
let (y, height, width) = match cell.cursor {
|
||||||
CursorShape::Beam => (0., LINE_HEIGHT, Some(2.)),
|
CursorShape::Beam => (0., line_height, Some(2.)),
|
||||||
CursorShape::Underline => (LINE_HEIGHT - 2., 2., None),
|
CursorShape::Underline => (line_height - 2., 2., None),
|
||||||
_ => continue,
|
_ => continue,
|
||||||
};
|
};
|
||||||
cursors.push(Decoration {
|
cursors.push(Decoration {
|
||||||
@@ -506,7 +508,7 @@ mod tests {
|
|||||||
fn blank_screen_has_no_text_or_background_work() {
|
fn blank_screen_has_no_text_or_background_work() {
|
||||||
let cells = vec![cell(' '); 250];
|
let cells = vec![cell(' '); 250];
|
||||||
assert!(assemble_text(&cells).is_empty());
|
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());
|
assert!(backgrounds.is_empty() && decorations.is_empty() && cursors.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -560,6 +562,24 @@ mod tests {
|
|||||||
assert!(!text[1].ascii && !text[2].ascii);
|
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]
|
#[test]
|
||||||
fn backgrounds_and_decorations_merge_without_painting_blank_defaults() {
|
fn backgrounds_and_decorations_merge_without_painting_blank_defaults() {
|
||||||
let mut cells = vec![cell(' '); 10];
|
let mut cells = vec![cell(' '); 10];
|
||||||
@@ -567,7 +587,7 @@ mod tests {
|
|||||||
c.background = rgb(0x123456).into();
|
c.background = rgb(0x123456).into();
|
||||||
c.cell.flags.insert(Flags::UNDERLINE | Flags::STRIKEOUT);
|
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.len(), 1);
|
||||||
assert_eq!((backgrounds[0].column, backgrounds[0].columns), (2, 5));
|
assert_eq!((backgrounds[0].column, backgrounds[0].columns), (2, 5));
|
||||||
assert_eq!(decorations.len(), 2);
|
assert_eq!(decorations.len(), 2);
|
||||||
|
|||||||
+92
-54
@@ -5,6 +5,7 @@ use crate::{
|
|||||||
colors,
|
colors,
|
||||||
commands::{self, CommandAction},
|
commands::{self, CommandAction},
|
||||||
cursor::CursorAnimator,
|
cursor::CursorAnimator,
|
||||||
|
fonts::{self, TerminalFont},
|
||||||
input,
|
input,
|
||||||
label::middle_label,
|
label::middle_label,
|
||||||
palette::CommandPalette,
|
palette::CommandPalette,
|
||||||
@@ -13,7 +14,7 @@ use crate::{
|
|||||||
ClientMessage, Direction, PaneSnapshot, ScrollKind, SelectionCommand, SelectionKind,
|
ClientMessage, Direction, PaneSnapshot, ScrollKind, SelectionCommand, SelectionKind,
|
||||||
SelectionSide, Snapshot, StackPaneInfo, VerticalDirection,
|
SelectionSide, Snapshot, StackPaneInfo, VerticalDirection,
|
||||||
},
|
},
|
||||||
render::{FONT_SIZE, LINE_HEIGHT, RenderCell, Renderer},
|
render::{RenderCell, Renderer},
|
||||||
transition::Slide,
|
transition::Slide,
|
||||||
};
|
};
|
||||||
use alacritty_terminal::{
|
use alacritty_terminal::{
|
||||||
@@ -38,6 +39,7 @@ struct TabRename {
|
|||||||
pub struct Workspace {
|
pub struct Workspace {
|
||||||
client: Client,
|
client: Client,
|
||||||
connection: SharedString,
|
connection: SharedString,
|
||||||
|
font: TerminalFont,
|
||||||
snapshot: Option<Arc<Snapshot>>,
|
snapshot: Option<Arc<Snapshot>>,
|
||||||
panes: HashMap<u64, Entity<TerminalPane>>,
|
panes: HashMap<u64, Entity<TerminalPane>>,
|
||||||
error: Option<String>,
|
error: Option<String>,
|
||||||
@@ -157,28 +159,25 @@ impl Workspace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn key_down(&mut self, event: &KeyDownEvent, window: &mut Window, cx: &mut Context<Self>) {
|
fn key_down(&mut self, event: &KeyDownEvent, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
let key = &event.keystroke;
|
let Some(action) = crate::bindings::action_for_key(&event.keystroke) else {
|
||||||
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();
|
|
||||||
return;
|
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.tab_rename.is_some()
|
||||||
|| self
|
|| self
|
||||||
.focused_pane()
|
.focused_pane()
|
||||||
.is_some_and(|pane| pane.read(cx).rename.is_some())
|
.is_some_and(|pane| pane.read(cx).rename.is_some()))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let action = crate::bindings::action_for_key(key);
|
self.execute(action, window, cx);
|
||||||
if let Some(action) = action {
|
cx.stop_propagation();
|
||||||
self.execute(action, window, cx);
|
|
||||||
cx.stop_propagation();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn execute(&mut self, action: CommandAction, window: &mut Window, cx: &mut Context<Self>) {
|
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 = self.focused_pane();
|
||||||
let pane_id = pane.as_ref().map(|pane| pane.read(cx).data().id);
|
let pane_id = pane.as_ref().map(|pane| pane.read(cx).data().id);
|
||||||
let message = match action {
|
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 }),
|
NewTab => Some(ClientMessage::NewTab { cwd: None }),
|
||||||
SplitPane => pane_id.map(|pane| ClientMessage::Split { pane, cwd: None }),
|
SplitPane => pane_id.map(|pane| ClientMessage::Split { pane, cwd: None }),
|
||||||
StackAbove | StackBelow => Some(ClientMessage::NewStackPane {
|
StackAbove | StackBelow => Some(ClientMessage::NewStackPane {
|
||||||
@@ -278,6 +299,9 @@ impl Workspace {
|
|||||||
) -> Self {
|
) -> Self {
|
||||||
let focus = cx.focus_handle();
|
let focus = cx.focus_handle();
|
||||||
window.focus(&focus);
|
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| {
|
let task = cx.spawn_in(window, async move |view, cx| {
|
||||||
while let Some(update) = updates.recv().await {
|
while let Some(update) = updates.recv().await {
|
||||||
if cx
|
if cx
|
||||||
@@ -374,10 +398,13 @@ impl Workspace {
|
|||||||
frame,
|
frame,
|
||||||
index,
|
index,
|
||||||
active == Some(data.id),
|
active == Some(data.id),
|
||||||
focus_allowed,
|
view.font.clone(),
|
||||||
window,
|
window,
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
|
if pane.active && focus_allowed {
|
||||||
|
window.focus(&pane.focus);
|
||||||
|
}
|
||||||
pane.transitioning = view.transition.is_some();
|
pane.transitioning = view.transition.is_some();
|
||||||
pane
|
pane
|
||||||
});
|
});
|
||||||
@@ -417,6 +444,7 @@ impl Workspace {
|
|||||||
Self {
|
Self {
|
||||||
client,
|
client,
|
||||||
connection,
|
connection,
|
||||||
|
font,
|
||||||
snapshot: None,
|
snapshot: None,
|
||||||
panes: HashMap::new(),
|
panes: HashMap::new(),
|
||||||
error: None,
|
error: None,
|
||||||
@@ -703,9 +731,7 @@ struct TerminalPane {
|
|||||||
read_only: bool,
|
read_only: bool,
|
||||||
transitioning: bool,
|
transitioning: bool,
|
||||||
focus: FocusHandle,
|
focus: FocusHandle,
|
||||||
font: Font,
|
|
||||||
bounds: Bounds<Pixels>,
|
bounds: Bounds<Pixels>,
|
||||||
cell_width: f32,
|
|
||||||
selecting: bool,
|
selecting: bool,
|
||||||
scroll_remainder: f32,
|
scroll_remainder: f32,
|
||||||
preedit: String,
|
preedit: String,
|
||||||
@@ -725,23 +751,17 @@ impl TerminalPane {
|
|||||||
snapshot: Arc<Snapshot>,
|
snapshot: Arc<Snapshot>,
|
||||||
index: usize,
|
index: usize,
|
||||||
active: bool,
|
active: bool,
|
||||||
focus_allowed: bool,
|
font: TerminalFont,
|
||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) -> 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();
|
let focus = cx.focus_handle();
|
||||||
if active && focus_allowed {
|
let activation = cx.observe_window_activation(window, |pane, window, cx| {
|
||||||
window.focus(&focus);
|
if window.is_window_active() {
|
||||||
}
|
// Each attached window has its own zoom and viewport. The focused
|
||||||
let activation = cx.observe_window_activation(window, |pane, _, cx| {
|
// window sets the shared PTY dimensions.
|
||||||
|
pane.requested_size = None;
|
||||||
|
}
|
||||||
pane.blink_timer = None;
|
pane.blink_timer = None;
|
||||||
cx.notify();
|
cx.notify();
|
||||||
});
|
});
|
||||||
@@ -753,15 +773,13 @@ impl TerminalPane {
|
|||||||
read_only: false,
|
read_only: false,
|
||||||
transitioning: false,
|
transitioning: false,
|
||||||
focus,
|
focus,
|
||||||
font,
|
|
||||||
bounds: Bounds::default(),
|
bounds: Bounds::default(),
|
||||||
cell_width,
|
|
||||||
selecting: false,
|
selecting: false,
|
||||||
scroll_remainder: 0.,
|
scroll_remainder: 0.,
|
||||||
preedit: String::new(),
|
preedit: String::new(),
|
||||||
cursor_bounds: Bounds::default(),
|
cursor_bounds: Bounds::default(),
|
||||||
cursor: CursorAnimator::new(),
|
cursor: CursorAnimator::new(),
|
||||||
renderer: Renderer::default(),
|
renderer: Renderer::new(font),
|
||||||
rename: None,
|
rename: None,
|
||||||
prepared_revision: None,
|
prepared_revision: None,
|
||||||
requested_size: None,
|
requested_size: None,
|
||||||
@@ -916,9 +934,11 @@ impl TerminalPane {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn grid_point(&self, position: Point<Pixels>) -> (u16, u16, SelectionSide) {
|
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));
|
.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));
|
.min(f32::from(self.data().lines - 1));
|
||||||
(
|
(
|
||||||
x as u16,
|
x as u16,
|
||||||
@@ -970,7 +990,7 @@ impl TerminalPane {
|
|||||||
}
|
}
|
||||||
self.scroll_remainder += match event.delta {
|
self.scroll_remainder += match event.delta {
|
||||||
ScrollDelta::Lines(d) => d.y * 3.,
|
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;
|
let lines = self.scroll_remainder.trunc() as i32;
|
||||||
self.scroll_remainder -= lines as f32;
|
self.scroll_remainder -= lines as f32;
|
||||||
@@ -996,20 +1016,24 @@ impl TerminalPane {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn prepare(&mut self, bounds: Bounds<Pixels>, window: &mut Window) {
|
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()
|
.floor()
|
||||||
.clamp(2., 1000.) as u16;
|
.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()
|
.floor()
|
||||||
.clamp(1., 500.) as u16;
|
.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.requested_size = Some((columns, lines));
|
||||||
self.command(ClientMessage::Resize {
|
self.command(ClientMessage::Resize {
|
||||||
pane: self.data().id,
|
pane: self.data().id,
|
||||||
columns,
|
columns,
|
||||||
lines,
|
lines,
|
||||||
cell_width: self.cell_width.round() as u16,
|
cell_width: font.cell_width.round() as u16,
|
||||||
cell_height: LINE_HEIGHT as u16,
|
cell_height: font.line_height as u16,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
let prepare_rows = self.prepared_revision != Some(self.snapshot.revision)
|
let prepare_rows = self.prepared_revision != Some(self.snapshot.revision)
|
||||||
@@ -1038,12 +1062,12 @@ impl TerminalPane {
|
|||||||
let cursor_bounds = Bounds::new(
|
let cursor_bounds = Bounds::new(
|
||||||
bounds.origin
|
bounds.origin
|
||||||
+ point(
|
+ point(
|
||||||
px(PADDING + f32::from(cursor.column) * self.cell_width),
|
px(PADDING + f32::from(cursor.column) * font.cell_width),
|
||||||
px(PADDING + cursor.row as f32 * LINE_HEIGHT),
|
px(PADDING + cursor.row as f32 * font.line_height),
|
||||||
),
|
),
|
||||||
size(
|
size(
|
||||||
px(self.cell_width * if wide { 2. } else { 1. }),
|
px(font.cell_width * if wide { 2. } else { 1. }),
|
||||||
px(LINE_HEIGHT),
|
px(font.line_height),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
let mut cursor_color = colors::resolve(Color::Named(NamedColor::Cursor), &palette);
|
let mut cursor_color = colors::resolve(Color::Named(NamedColor::Cursor), &palette);
|
||||||
@@ -1087,8 +1111,7 @@ impl TerminalPane {
|
|||||||
.collect()
|
.collect()
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
self.renderer
|
self.renderer.prepare(rows, window);
|
||||||
.prepare(rows, &self.font, self.cell_width, window);
|
|
||||||
self.prepared_revision = Some(self.snapshot.revision);
|
self.prepared_revision = Some(self.snapshot.revision);
|
||||||
log::debug!(target:"psyterm::timing","prepare_us={}",started.elapsed().as_micros());
|
log::debug!(target:"psyterm::timing","prepare_us={}",started.elapsed().as_micros());
|
||||||
}
|
}
|
||||||
@@ -1150,11 +1173,26 @@ impl Render for TerminalPane {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if !pane.preedit.is_empty() {
|
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()),
|
let font = &pane.renderer.font;
|
||||||
underline:Some(UnderlineStyle{thickness:px(1.),color:None,wavy:false}),strikethrough:None};
|
let run = TextRun {
|
||||||
let shaped=window.text_system().shape_line(pane.preedit.clone().into(),px(FONT_SIZE),&[run],None);
|
len: pane.preedit.len(),
|
||||||
let _=shaped.paint_background(pane.cursor_bounds.origin,px(LINE_HEIGHT),window,cx);
|
font: font.face.clone(),
|
||||||
let _=shaped.paint(pane.cursor_bounds.origin,px(LINE_HEIGHT),window,cx);
|
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);
|
pane.schedule_cursor(delay,window,cx);
|
||||||
|
|||||||
Reference in New Issue
Block a user