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.

feat(gui): number threads while Cmd is held and fade long titles

RoversX828e0133bef1
diff --git a/config/src/keyassignment.rs b/config/src/keyassignment.rs
index 6da60208..3a810ece 100644
--- a/config/src/keyassignment.rs
+++ b/config/src/keyassignment.rs
@@ -676,6 +676,9 @@ pub enum KeyAssignment {
space_id: String,
thread_id: String,
},
+ /// Open the thread on the sidebar's row of this number, from 0, counting
+ /// only the rows with a thread on them.
+ ActivateWorkspaceThreadByIndex(usize),
ActivateWindow(usize),
ActivateWindowRelative(isize),
ActivateWindowRelativeNoWrap(isize),
diff --git a/docs/config/default-keys.md b/docs/config/default-keys.md
index 9f36cba8..bc14f944 100644
--- a/docs/config/default-keys.md
+++ b/docs/config/default-keys.md
@@ -35,25 +35,34 @@ in a form that you can copy and paste into your own configuration.
| `CTRL+SHIFT` | `t` | `SpawnTab="CurrentPaneDomain"` |
| `SUPER+SHIFT` | `T` | `SpawnTab="DefaultDomain"` |
| `SUPER` | `w` | `CloseCurrentTab{confirm=true}` |
-| `SUPER` | `1` | `ActivateTab=0` |
-| `SUPER` | `2` | `ActivateTab=1` |
-| `SUPER` | `3` | `ActivateTab=2` |
-| `SUPER` | `4` | `ActivateTab=3` |
-| `SUPER` | `5` | `ActivateTab=4` |
-| `SUPER` | `6` | `ActivateTab=5` |
-| `SUPER` | `7` | `ActivateTab=6` |
-| `SUPER` | `8` | `ActivateTab=7` |
-| `SUPER` | `9` | `ActivateTab=-1` |
+| `SUPER` | `1` | `ActivateWorkspaceThreadByIndex=0` |
+| `SUPER` | `2` | `ActivateWorkspaceThreadByIndex=1` |
+| `SUPER` | `3` | `ActivateWorkspaceThreadByIndex=2` |
+| `SUPER` | `4` | `ActivateWorkspaceThreadByIndex=3` |
+| `SUPER` | `5` | `ActivateWorkspaceThreadByIndex=4` |
+| `SUPER` | `6` | `ActivateWorkspaceThreadByIndex=5` |
+| `SUPER` | `7` | `ActivateWorkspaceThreadByIndex=6` |
+| `SUPER` | `8` | `ActivateWorkspaceThreadByIndex=7` |
+| `SUPER` | `9` | `ActivateWorkspaceThreadByIndex=8` |
| `CTRL+SHIFT` | `w` | `CloseCurrentTab{confirm=true}` |
-| `CTRL+SHIFT` | `1` | `ActivateTab=0` |
-| `CTRL+SHIFT` | `2` | `ActivateTab=1` |
-| `CTRL+SHIFT` | `3` | `ActivateTab=2` |
-| `CTRL+SHIFT` | `4` | `ActivateTab=3` |
-| `CTRL+SHIFT` | `5` | `ActivateTab=4` |
-| `CTRL+SHIFT` | `6` | `ActivateTab=5` |
-| `CTRL+SHIFT` | `7` | `ActivateTab=6` |
-| `CTRL+SHIFT` | `8` | `ActivateTab=7` |
-| `CTRL+SHIFT` | `9` | `ActivateTab=-1` |
+| `CTRL+SHIFT` | `1` | `ActivateWorkspaceThreadByIndex=0` |
+| `CTRL+SHIFT` | `2` | `ActivateWorkspaceThreadByIndex=1` |
+| `CTRL+SHIFT` | `3` | `ActivateWorkspaceThreadByIndex=2` |
+| `CTRL+SHIFT` | `4` | `ActivateWorkspaceThreadByIndex=3` |
+| `CTRL+SHIFT` | `5` | `ActivateWorkspaceThreadByIndex=4` |
+| `CTRL+SHIFT` | `6` | `ActivateWorkspaceThreadByIndex=5` |
+| `CTRL+SHIFT` | `7` | `ActivateWorkspaceThreadByIndex=6` |
+| `CTRL+SHIFT` | `8` | `ActivateWorkspaceThreadByIndex=7` |
+| `CTRL+SHIFT` | `9` | `ActivateWorkspaceThreadByIndex=8` |
+| `CTRL` | `1` | `ActivateTab=0` |
+| `CTRL` | `2` | `ActivateTab=1` |
+| `CTRL` | `3` | `ActivateTab=2` |
+| `CTRL` | `4` | `ActivateTab=3` |
+| `CTRL` | `5` | `ActivateTab=4` |
+| `CTRL` | `6` | `ActivateTab=5` |
+| `CTRL` | `7` | `ActivateTab=6` |
+| `CTRL` | `8` | `ActivateTab=7` |
+| `CTRL` | `9` | `ActivateTab=-1` |
| `SUPER+SHIFT` | `[` | `ActivateTabRelative=-1` |
| `CTRL+SHIFT` | `Tab` | `ActivateTabRelative=-1` |
| `CTRL` | `PageUp` | `ActivateTabRelative=-1` |
@@ -88,6 +97,8 @@ in a form that you can copy and paste into your own configuration.
| `CTRL+SHIFT` | `DownArrow` | `ActivatePaneDirection="Down"` |
| `CTRL+SHIFT` | `Z` | `TogglePaneZoomState` |
+`CTRL` with a digit goes to `ActivateTab`, so those keys do not reach the program in the terminal: Ctrl-6 in vim, say, or Ctrl-7 as undo in Emacs and readline. Bind one to [DisableDefaultAssignment](lua/keyassignment/DisableDefaultAssignment.md) to hand it back.
+
If you don't want the default assignments to be registered, you can
disable all of them with this configuration; if you chose to do this,
you must explicitly register every binding.
diff --git a/thinkterm-i18n/i18n/de-DE.ftl b/thinkterm-i18n/i18n/de-DE.ftl
index 87763280..c801e846 100644
--- a/thinkterm-i18n/i18n/de-DE.ftl
+++ b/thinkterm-i18n/i18n/de-DE.ftl
@@ -1646,6 +1646,7 @@ command-detach-domain = Domain { $name } trennen
command-switch-to-workspace = Zu Workspace { $name } wechseln
command-move-spaces = { $n } Spaces weiter
command-activate-tab = Tab { $n } aktivieren
+command-activate-thread = Thread { $n } aktivieren
command-activate-window = Fenster { $n } aktivieren
command-resize-pane-left = Bereich um { $n } Zelle(n) nach links anpassen
command-resize-pane-right = Bereich um { $n } Zelle(n) nach rechts anpassen
@@ -1673,6 +1674,7 @@ menu-bar-resize-pane = Bereichsgröße ändern
menu-bar-rotate-pane = Bereiche rotieren
menu-bar-select-pane = Bereich wählen
menu-bar-select-tab = Tab wählen
+menu-bar-select-thread = Thread wählen
menu-bar-select-window = Fenster wählen
menu-bar-workspace = Workspace
menu-bar-about = Über ThinkTerm
diff --git a/thinkterm-i18n/i18n/en-US.ftl b/thinkterm-i18n/i18n/en-US.ftl
index 841f8332..dd54f0c1 100644
--- a/thinkterm-i18n/i18n/en-US.ftl
+++ b/thinkterm-i18n/i18n/en-US.ftl
@@ -1646,6 +1646,7 @@ command-detach-domain = Detach Domain { $name }
command-switch-to-workspace = Switch to workspace { $name }
command-move-spaces = Move { $n } Spaces
command-activate-tab = Activate { $ordinal } Tab
+command-activate-thread = Activate { $ordinal } Thread
command-activate-window = Activate { $ordinal } Window
command-resize-pane-left = Resize Pane { $n } cell(s) to the Left
command-resize-pane-right = Resize Pane { $n } cell(s) to the Right
@@ -1673,6 +1674,7 @@ menu-bar-resize-pane = Resize Pane
menu-bar-rotate-pane = Rotate Pane
menu-bar-select-pane = Select Pane
menu-bar-select-tab = Select Tab
+menu-bar-select-thread = Select Thread
menu-bar-select-window = Select Window
menu-bar-workspace = Workspace
menu-bar-about = About ThinkTerm
diff --git a/thinkterm-i18n/i18n/fr-FR.ftl b/thinkterm-i18n/i18n/fr-FR.ftl
index 3e672cc6..aa9d4a33 100644
--- a/thinkterm-i18n/i18n/fr-FR.ftl
+++ b/thinkterm-i18n/i18n/fr-FR.ftl
@@ -1640,6 +1640,7 @@ command-detach-domain = Détacher le domaine { $name }
command-switch-to-workspace = Passer à l’espace de travail { $name }
command-move-spaces = Avancer de { $n } espaces
command-activate-tab = Activer l’onglet { $n }
+command-activate-thread = Activer la session { $n }
command-activate-window = Activer la fenêtre { $n }
command-resize-pane-left = Redimensionner le volet de { $n } cellule(s) vers la gauche
command-resize-pane-right = Redimensionner le volet de { $n } cellule(s) vers la droite
@@ -1667,6 +1668,7 @@ menu-bar-resize-pane = Redimensionner le volet
menu-bar-rotate-pane = Faire pivoter les volets
menu-bar-select-pane = Choisir un volet
menu-bar-select-tab = Choisir un onglet
+menu-bar-select-thread = Choisir une session
menu-bar-select-window = Choisir une fenêtre
menu-bar-workspace = Espace de travail
menu-bar-about = À propos de ThinkTerm
diff --git a/thinkterm-i18n/i18n/ja-JP.ftl b/thinkterm-i18n/i18n/ja-JP.ftl
index bd66ad04..eef8a467 100644
--- a/thinkterm-i18n/i18n/ja-JP.ftl
+++ b/thinkterm-i18n/i18n/ja-JP.ftl
@@ -1594,6 +1594,7 @@ command-detach-domain = ドメイン { $name } を切断
command-switch-to-workspace = ワークスペース { $name } に切り替え
command-move-spaces = スペースを { $n } 個移動
command-activate-tab = { $n } 番目のタブに切り替え
+command-activate-thread = { $n } 番目のセッションに切り替え
command-activate-window = { $n } 番目のウインドウに切り替え
command-resize-pane-left = ペインのサイズを左へ { $n } セル変更
command-resize-pane-right = ペインのサイズを右へ { $n } セル変更
@@ -1621,6 +1622,7 @@ menu-bar-resize-pane = ペインのサイズ変更
menu-bar-rotate-pane = ペインを回転
menu-bar-select-pane = ペインを選択
menu-bar-select-tab = タブを選択
+menu-bar-select-thread = セッションを選択
menu-bar-select-window = ウインドウを選択
menu-bar-workspace = ワークスペース
menu-bar-about = ThinkTerm について
diff --git a/thinkterm-i18n/i18n/ru-RU.ftl b/thinkterm-i18n/i18n/ru-RU.ftl
index 1798da59..db256563 100644
--- a/thinkterm-i18n/i18n/ru-RU.ftl
+++ b/thinkterm-i18n/i18n/ru-RU.ftl
@@ -1574,6 +1574,7 @@ command-detach-domain = Отключить домен { $name }
command-switch-to-workspace = Перейти в рабочую область { $name }
command-move-spaces = Переместить на число пространств: { $n }
command-activate-tab = Активировать вкладку { $ordinal }
+command-activate-thread = Активировать ветку { $n }
command-activate-window = Активировать окно { $ordinal }
command-resize-pane-left = Изменить размер панели влево (ячеек: { $n })
command-resize-pane-right = Изменить размер панели вправо (ячеек: { $n })
@@ -1598,6 +1599,7 @@ menu-bar-resize-pane = Размер панели
menu-bar-rotate-pane = Переставить панели
menu-bar-select-pane = Выбрать панель
menu-bar-select-tab = Выбрать вкладку
+menu-bar-select-thread = Выбрать ветку
menu-bar-select-window = Выбрать окно
menu-bar-workspace = Рабочая область
menu-bar-about = О ThinkTerm
diff --git a/thinkterm-i18n/i18n/zh-CN.ftl b/thinkterm-i18n/i18n/zh-CN.ftl
index e738392a..938daa68 100644
--- a/thinkterm-i18n/i18n/zh-CN.ftl
+++ b/thinkterm-i18n/i18n/zh-CN.ftl
@@ -1594,6 +1594,7 @@ command-detach-domain = 断开域 { $name }
command-switch-to-workspace = 切换到工作区 { $name }
command-move-spaces = 移动 { $n } 个空间
command-activate-tab = 切换到第 { $n } 个标签页
+command-activate-thread = 切换到第 { $n } 个会话
command-activate-window = 切换到第 { $n } 个窗口
command-resize-pane-left = 窗格向左调整 { $n } 格
command-resize-pane-right = 窗格向右调整 { $n } 格
@@ -1621,6 +1622,7 @@ menu-bar-resize-pane = 调整窗格大小
menu-bar-rotate-pane = 轮换窗格
menu-bar-select-pane = 选择窗格
menu-bar-select-tab = 选择标签页
+menu-bar-select-thread = 选择会话
menu-bar-select-window = 选择窗口
menu-bar-workspace = 工作区
menu-bar-about = 关于 ThinkTerm
diff --git a/wezterm-gui/src/commands.rs b/wezterm-gui/src/commands.rs
index b74708e5..4d43cf3d 100644
--- a/wezterm-gui/src/commands.rs
+++ b/wezterm-gui/src/commands.rs
@@ -628,6 +628,7 @@ const MENU_TITLES: &[(&str, &str)] = &[
("Rotate Pane", "menu-bar-rotate-pane"),
("Select Pane", "menu-bar-select-pane"),
("Select Tab", "menu-bar-select-tab"),
+ ("Select Thread", "menu-bar-select-thread"),
("Select Window", "menu-bar-select-window"),
("Workspace", "menu-bar-workspace"),
];
@@ -1545,7 +1546,7 @@ pub fn derive_command_from_key_assignment(action: &KeyAssignment) -> Option<Comm
ActivateTab(-1) => CommandDef {
brief: tr("command-activate-right-most-tab").into(),
doc: "Activates the tab on the far right".into(),
- keys: vec![(Modifiers::SUPER, "9".into())],
+ keys: vec![(Modifiers::CTRL, "9".into())],
args: &[ArgType::ActiveWindow],
menubar: &["Window", "Select Tab"],
icon: None,
@@ -1554,7 +1555,7 @@ pub fn derive_command_from_key_assignment(action: &KeyAssignment) -> Option<Comm
let n = *n;
let ordinal = english_ordinal(n + 1);
let keys = if n >= 0 && n <= 7 {
- vec![(Modifiers::SUPER, (n + 1).to_string())]
+ vec![(Modifiers::CTRL, (n + 1).to_string())]
} else {
vec![]
};
@@ -2599,6 +2600,25 @@ pub fn derive_command_from_key_assignment(action: &KeyAssignment) -> Option<Comm
menubar: &[],
icon: Some("oct_terminal"),
},
+ ActivateWorkspaceThreadByIndex(n) => {
+ let n = *n;
+ let ordinal = english_ordinal(n as isize + 1);
+ // The same digits as the numbers the sidebar shows while these
+ // keys are held: see `termwindow::thread_numbers`.
+ let keys = if n < crate::termwindow::thread_numbers::MOST_NUMBERS {
+ vec![(Modifiers::SUPER, (n + 1).to_string())]
+ } else {
+ vec![]
+ };
+ CommandDef {
+ brief: counted("command-activate-thread", n as i64 + 1, Some(&ordinal)).into(),
+ doc: format!("Opens the {ordinal} thread in the sidebar").into(),
+ keys,
+ args: &[ArgType::ActiveWindow],
+ menubar: &["Window", "Select Thread"],
+ icon: None,
+ }
+ }
})
}
@@ -2701,6 +2721,15 @@ fn compute_default_actions() -> Vec<KeyAssignment> {
}),
RotatePanes(RotationDirection::Clockwise),
RotatePanes(RotationDirection::CounterClockwise),
+ ActivateWorkspaceThreadByIndex(0),
+ ActivateWorkspaceThreadByIndex(1),
+ ActivateWorkspaceThreadByIndex(2),
+ ActivateWorkspaceThreadByIndex(3),
+ ActivateWorkspaceThreadByIndex(4),
+ ActivateWorkspaceThreadByIndex(5),
+ ActivateWorkspaceThreadByIndex(6),
+ ActivateWorkspaceThreadByIndex(7),
+ ActivateWorkspaceThreadByIndex(8),
ActivateTab(0),
ActivateTab(1),
ActivateTab(2),
@@ -2752,6 +2781,26 @@ fn compute_default_actions() -> Vec<KeyAssignment> {
#[cfg(test)]
mod tests {
+ #[test]
+ fn number_keys_reach_threads_and_ctrl_reaches_tabs() {
+ use super::KeyAssignment::{ActivateTab, ActivateWorkspaceThreadByIndex};
+ use crate::inputmap::default_chords;
+ use window::{KeyCode, Modifiers};
+
+ let chord = |c, mods| vec![(KeyCode::Char(c), mods)];
+ assert_eq!(
+ default_chords(&ActivateWorkspaceThreadByIndex(0)),
+ chord('1', Modifiers::SUPER)
+ );
+ assert_eq!(
+ default_chords(&ActivateWorkspaceThreadByIndex(8)),
+ chord('9', Modifiers::SUPER)
+ );
+ assert!(default_chords(&ActivateWorkspaceThreadByIndex(9)).is_empty());
+ assert_eq!(default_chords(&ActivateTab(0)), chord('1', Modifiers::CTRL));
+ assert_eq!(default_chords(&ActivateTab(-1)), chord('9', Modifiers::CTRL));
+ }
+
#[test]
fn every_menu_title_has_an_english_text() {
for (_, id) in super::MENU_TITLES {
diff --git a/wezterm-gui/src/glyph-frag.glsl b/wezterm-gui/src/glyph-frag.glsl
index fc3eec1e..0b32bacb 100644
--- a/wezterm-gui/src/glyph-frag.glsl
+++ b/wezterm-gui/src/glyph-frag.glsl
@@ -169,6 +169,9 @@ void main() {
} else if (o_has_color == 1.0) {
// the texture is full color info (eg: color emoji glyph)
color = texture(atlas_nearest_sampler, o_tex);
+ // The vertex alpha still applies, as the WebGPU shader has it, so that
+ // an emoji goes with the text fading around it.
+ color.a *= fg_color.a;
// this is the alpha
colorMask = color.aaaa;
} else if (o_has_color == 4.0) {
diff --git a/wezterm-gui/src/inputmap.rs b/wezterm-gui/src/inputmap.rs
index d945060a..20259246 100644
--- a/wezterm-gui/src/inputmap.rs
+++ b/wezterm-gui/src/inputmap.rs
@@ -807,6 +807,20 @@ pub(crate) fn chord_label(
label
}
+/// `chord_label`, set tight as the Mac's menus write it: ⌘P, not ⌘ P.
+pub(crate) fn tight_chord_label(
+ key: &KeyCode,
+ mods: Modifiers,
+ ui_key_cap_rendering: UIKeyCapRendering,
+) -> String {
+ let label = chord_label(key, mods, ui_key_cap_rendering);
+ if ui_key_cap_rendering == UIKeyCapRendering::AppleSymbols {
+ label.replace(' ', "")
+ } else {
+ label
+ }
+}
+
/// `key` as the configuration file spells it: parsing the result gives
/// `key` back. Settings → Keymap writes its shortcuts with it.
pub(crate) fn config_key_name(key: &KeyCode) -> String {
diff --git a/wezterm-gui/src/settings_window.rs b/wezterm-gui/src/settings_window.rs
index 9eb46d61..4c728697 100644
--- a/wezterm-gui/src/settings_window.rs
+++ b/wezterm-gui/src/settings_window.rs
@@ -10312,6 +10312,7 @@ impl SettingsWindow {
count_font: &count_font,
count_metrics: &count_metrics,
count_color: self.palette().secondary_text,
+ opacity: 1.0,
};
let pad = (height * 0.22).round();
let bar_height = (height * 0.09).round().max(2.0);
diff --git a/wezterm-gui/src/termwindow/keyevent.rs b/wezterm-gui/src/termwindow/keyevent.rs
index 0e75083b..274c0d0f 100644
--- a/wezterm-gui/src/termwindow/keyevent.rs
+++ b/wezterm-gui/src/termwindow/keyevent.rs
@@ -833,6 +833,13 @@ impl super::TermWindow {
if key.key_is_down && !key.key.is_modifier() && self.dismiss_hover_tooltip() {
context.invalidate();
}
+ // On Windows a modifier's own key event names it physically.
+ if key.key_is_down
+ && !key.key.is_modifier()
+ && !key.phys_code.is_some_and(|code| code.is_modifier())
+ {
+ self.note_key_for_thread_numbers(&key);
+ }
let mut input_trace =
crate::input_diagnostics::KeyEventTrace::begin(key.key_is_down, key.key.is_modifier());
// The leader key is a kind of modal modifier key.
@@ -863,6 +870,11 @@ impl super::TermWindow {
if self.current_modifier_and_leds != modifier_and_leds {
self.current_modifier_and_leds = modifier_and_leds;
self.schedule_next_status_update();
+ // Everywhere else the window has an event for modifiers alone,
+ // and a key's state can run behind it.
+ if cfg!(windows) {
+ self.note_thread_number_modifiers(key.modifiers);
+ }
}
// While the command palette is open no physical-key binding may fire
diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs
index 7933902f..36ff8458 100644
--- a/wezterm-gui/src/termwindow/mod.rs
+++ b/wezterm-gui/src/termwindow/mod.rs
@@ -170,6 +170,7 @@ mod selection;
mod sidebar_hover;
mod sidebar_slide;
mod space_swipe;
+pub(crate) mod thread_numbers;
mod window_tab_reveal;
pub mod spawn;
pub mod ssh_hosts_view;
@@ -3335,6 +3336,8 @@ pub struct TermWindow {
/// The window tab row hidden or brought down from the top edge, as
/// Settings asks; see `window_tab_reveal`.
window_tab_reveal: window_tab_reveal::WindowTabReveal,
+ /// The numbers on the sidebar's threads while their keys are held.
+ thread_numbers: thread_numbers::ThreadNumbers,
/// Hover-reveal of the collapsed right sidebar: the same machine as the
/// left one's, mirrored onto the right edge.
right_sidebar_hover: sidebar_hover::SidebarHoverReveal,
@@ -4667,6 +4670,7 @@ impl TermWindow {
self.workspace_sidebar_hover.cancel_immediately();
self.right_sidebar_hover.cancel_immediately();
self.window_tab_reveal.cancel();
+ self.cancel_thread_numbers();
self.clear_workspace_space_swipe_frame_transition();
self.right_sidebar_note.native_text_input_snapshot_key = None;
window.set_native_text_input_snapshot(None);
@@ -5243,6 +5247,7 @@ impl TermWindow {
library: Default::default(),
workspace_sidebar_hover: sidebar_hover::SidebarHoverReveal::default(),
window_tab_reveal,
+ thread_numbers: Default::default(),
right_sidebar_hover: sidebar_hover::SidebarHoverReveal::default(),
right_sidebar_hover_was_presented: false,
titlebar_sidebar_button_hovered: false,
@@ -5845,6 +5850,7 @@ impl TermWindow {
}
WindowEvent::AdviseModifiersLedStatus(modifiers, leds) => {
self.current_modifier_and_leds = (modifiers, leds);
+ self.note_thread_number_modifiers(modifiers);
self.update_title();
window.invalidate();
Ok(true)
@@ -11460,6 +11466,8 @@ impl TermWindow {
) -> anyhow::Result<PerformAssignmentResult> {
use KeyAssignment::*;
+ self.interrupt_thread_numbers(matches!(assignment, ActivateWorkspaceThreadByIndex(_)));
+
if let Some(modal) = self.get_modal() {
if modal.perform_assignment(assignment, self) {
return Ok(PerformAssignmentResult::Handled);
@@ -12445,6 +12453,11 @@ impl TermWindow {
self.switch_space_to_thread(space_id.clone(), Some(thread_id.clone()), &window);
}
}
+ ActivateWorkspaceThreadByIndex(index) => {
+ if let Some(window) = self.window.as_ref().cloned() {
+ self.activate_numbered_thread(*index, &window);
+ }
+ }
PromptInputLine(args) => self.show_prompt_input_line(args),
InputSelector(args) => self.show_input_selector(args),
Confirmation(args) => self.show_confirmation(args),
diff --git a/wezterm-gui/src/termwindow/mouseevent.rs b/wezterm-gui/src/termwindow/mouseevent.rs
index 4b6ef230..6b549494 100644
--- a/wezterm-gui/src/termwindow/mouseevent.rs
+++ b/wezterm-gui/src/termwindow/mouseevent.rs
@@ -2170,6 +2170,9 @@ impl super::TermWindow {
pub fn mouse_event_impl(&mut self, event: MouseEvent, context: &dyn WindowOps) {
log::trace!("{:?}", event);
+ if matches!(event.kind, WMEK::Press(_)) {
+ self.interrupt_thread_numbers(false);
+ }
// A move that does not reach the terminal -- the tab bar, a sidebar
// -- leaves no cell behind: coming back is coming into a pane.
let pointer_cell_before = if matches!(event.kind, WMEK::Move) {
diff --git a/wezterm-gui/src/termwindow/render/fancy_tab_bar.rs b/wezterm-gui/src/termwindow/render/fancy_tab_bar.rs
index 1ca4b551..ba74d589 100644
--- a/wezterm-gui/src/termwindow/render/fancy_tab_bar.rs
+++ b/wezterm-gui/src/termwindow/render/fancy_tab_bar.rs
@@ -7,15 +7,16 @@ use crate::tabbar::{TabBarItem, TabEntry};
use crate::termwindow::ui::icons::SvgIcon;
use crate::termwindow::ui::platform_chrome::uses_integrated_window_buttons;
use crate::termwindow::ui::tokens::{
- ICON_BUTTON_BORDER_WIDTH, SIDEBAR_INSET, TAB_CLOSE_HOVER_INSET,
- TAB_CLOSE_HOVER_RADIUS, TAB_CONTENT_INSET, TAB_ICON_SIZE, TAB_ROW_START_PADDING,
- TAB_VERTICAL_PADDING,
- WINDOW_TAB_ADD_BUTTON_RADIUS, WINDOW_TAB_FULLSCREEN_SIDEBAR_BUTTON_Y_OFFSET, WINDOW_TAB_GAP,
+ ICON_BUTTON_BORDER_WIDTH, SIDEBAR_INSET, TAB_CLOSE_HOVER_INSET, TAB_CLOSE_HOVER_RADIUS,
+ TAB_CONTENT_INSET, TAB_ICON_SIZE, TAB_ROW_START_PADDING, TAB_TITLE_FADE_GAP,
+ TAB_VERTICAL_PADDING, TITLE_FADE, WINDOW_TAB_ADD_BUTTON_RADIUS,
+ WINDOW_TAB_FULLSCREEN_SIDEBAR_BUTTON_Y_OFFSET, WINDOW_TAB_GAP,
WINDOW_TAB_LEADING_ACTION_BUTTON_SIZE, WINDOW_TAB_LEADING_ACTION_GAP,
WINDOW_TAB_LEADING_ACTION_ICON_SIZE, WINDOW_TAB_RADIUS, WINDOW_TAB_TOP_SPACER,
};
use crate::termwindow::window_tab_reveal::PaneBarWindowChrome;
use crate::termwindow::{TermWindowNotif, UIItem, UIItemType, UiShapeCacheLookup};
+use crate::ui::draw::TextFade;
use crate::ui::UiPalette;
use crate::utilsprites::RenderMetrics;
use anyhow::{anyhow, Context};
@@ -1543,8 +1544,87 @@ impl crate::TermWindow {
}
text.push_str(value);
}
- let text = self.ellipsize_ui_text(font, &text, width)?;
- self.paint_ui_title_text(layers, font, &metrics, &text, x, y, width, foreground)
+ self.paint_fading_title(layers, font, &metrics, &text, x, y, width, foreground)
+ }
+
+ /// A tab's `title` in `width`. One too long goes out towards the end of
+ /// the space it has, rather than stopping at "...".
+ #[allow(clippy::too_many_arguments)]
+ pub(crate) fn paint_fading_title(
+ &self,
+ layers: &mut TripleLayerQuadAllocator,
+ font: &Rc<LoadedFont>,
+ metrics: &RenderMetrics,
+ title: &str,
+ x: usize,
+ y: usize,
+ width: usize,
+ foreground: LinearRgba,
+ ) -> anyhow::Result<()> {
+ self.paint_title_fading_with(
+ layers,
+ font,
+ metrics,
+ title,
+ x,
+ y,
+ width,
+ foreground,
+ TAB_TITLE_FADE_GAP,
+ |fade| fade,
+ )
+ }
+
+ /// `paint_fading_title`, ending `gap` short of `width`, with `fade_for`
+ /// having the last word on the fade it is given, which is `None` for a
+ /// title that fits.
+ #[allow(clippy::too_many_arguments)]
+ pub(crate) fn paint_title_fading_with(
+ &self,
+ layers: &mut TripleLayerQuadAllocator,
+ font: &Rc<LoadedFont>,
+ metrics: &RenderMetrics,
+ title: &str,
+ x: usize,
+ y: usize,
+ width: usize,
+ foreground: LinearRgba,
+ gap: f32,
+ fade_for: impl FnOnce(Option<TextFade>) -> Option<TextFade>,
+ ) -> anyhow::Result<()> {
+ if width == 0 {
+ return Ok(());
+ }
+ let (shaped, _) = self.cached_ui_shape(font, metrics, title)?;
+ let advance: f32 = shaped
+ .iter()
+ .map(|info| info.glyph.x_advance.get() as f32)
+ .sum();
+ let right = (x + width) as f32;
+ let fade = fade_for((advance > width as f32).then(|| {
+ let to = right - self.ui_f32(gap).min(width as f32 / 4.0);
+ TextFade {
+ from: to - self.ui_f32(TITLE_FADE).min(width as f32 / 2.0),
+ to,
+ amount: 1.0,
+ }
+ }));
+ // The glyph the end falls on is drawn too, for the fade to run out
+ // across; those after it would not show.
+ let slack = metrics.cell_size.width as f32 * 2.0;
+ let clip_right = fade.map_or(right, |fade| right.max(fade.to + slack));
+ self.paint_cached_ui_shape_fading(
+ layers,
+ metrics,
+ &shaped,
+ x as f32,
+ y as f32,
+ x as f32,
+ clip_right,
+ fade,
+ |_| foreground,
+ )?;
+ Ok(())
}
#[allow(clippy::too_many_arguments)]
@@ -1768,6 +1848,28 @@ impl crate::TermWindow {
y: f32,
clip_left: f32,
clip_right: f32,
+ color_for: F,
+ ) -> anyhow::Result<f32>
+ where
+ F: FnMut(&ShapedInfo) -> LinearRgba,
+ {
+ self.paint_cached_ui_shape_fading(
+ layers, metrics, shaped, start_x, y, clip_left, clip_right, None, color_for,
+ )
+ }
+
+ /// `paint_cached_ui_shape_clipped`, going out along `fade` if there is one.
+ #[allow(clippy::too_many_arguments)]
+ pub(crate) fn paint_cached_ui_shape_fading<F>(
+ &self,
+ layers: &mut TripleLayerQuadAllocator,
+ metrics: &RenderMetrics,
+ shaped: &[ShapedInfo],
+ start_x: f32,
+ y: f32,
+ clip_left: f32,
+ clip_right: f32,
+ fade: Option<TextFade>,
mut color_for: F,
) -> anyhow::Result<f32>
where
@@ -1808,8 +1910,7 @@ impl crate::TermWindow {
y + top_offset + metrics.cell_size.height as f32,
);
quad.set_texture(sprite.texture_coords());
- quad.set_fg_color(color);
- quad.set_alt_color_and_mix_value(color, 0.0);
+ set_glyph_color(&mut quad, color, x_pos, x_pos + advance, fade);
quad.set_hsv(None);
x_pos += advance;
continue;
@@ -1835,8 +1936,7 @@ impl crate::TermWindow {
glyph_y + top_offset + glyph_height,
);
quad.set_texture(texture.texture_coords());
- quad.set_fg_color(color);
- quad.set_alt_color_and_mix_value(color, 0.0);
+ set_glyph_color(&mut quad, color, glyph_x, glyph_x + glyph_width, fade);
quad.set_has_color(glyph.has_color);
quad.set_hsv(None);
}
@@ -2030,6 +2130,25 @@ struct HorizontalTextureClip {
texture_right: f32,
}
+/// `color` on a glyph's quad, `fade` running across the span it covers.
+fn set_glyph_color(
+ quad: &mut impl QuadTrait,
+ color: LinearRgba,
+ left: f32,
+ right: f32,
+ fade: Option<TextFade>,
+) {
+ match fade {
+ Some(fade) => {
+ let left = color.mul_alpha(fade.alpha_at(left));
+ let right = color.mul_alpha(fade.alpha_at(right));
+ quad.set_corner_gradient(left, right, left, right);
+ }
+ None => quad.set_fg_color(color),
+ }
+ quad.set_alt_color_and_mix_value(color, 0.0);
+}
+
fn horizontal_texture_clip(
position_left: f32,
position_right: f32,
diff --git a/wezterm-gui/src/termwindow/render/hover.rs b/wezterm-gui/src/termwindow/render/hover.rs
index 6bb9b088..bb656bca 100644
--- a/wezterm-gui/src/termwindow/render/hover.rs
+++ b/wezterm-gui/src/termwindow/render/hover.rs
@@ -25,7 +25,7 @@ use std::rc::Rc;
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
use wezterm_font::LoadedFont;
use window::color::LinearRgba;
-use window::{Modifiers, UIKeyCapRendering};
+use window::Modifiers;
const TAG_RADIUS: f32 = 16.0;
const CARD_RADIUS: f32 = 24.0;
@@ -144,14 +144,26 @@ impl TermWindow {
.cloned()
}
- /// The shortcut a tag shows after its label: the first chord bound to
- /// the item's action, the platform's own modifier first, as the
- /// keyboard settings label it.
+ /// The shortcut a tag shows after its label: `native_chord` of the
+ /// item's action, as the keyboard settings label it.
pub(crate) fn hover_shortcut(&self, item_type: &UIItemType) -> Option<String> {
let action = crate::termwindow::tooltip_action_for(item_type)?;
+ let (key, mods) = self.native_chord(&action)?;
+ Some(crate::inputmap::tight_chord_label(
+ &key,
+ mods,
+ self.config.ui_key_cap_rendering,
+ ))
+ }
+
+ /// The first chord bound to `action`, the platform's own modifier first.
+ pub(crate) fn native_chord(
+ &self,
+ action: &config::keyassignment::KeyAssignment,
+ ) -> Option<(window::KeyCode, Modifiers)> {
let mut chords = self
.input_map
- .locate_app_wide_key_assignment(&action)
+ .locate_app_wide_key_assignment(action)
.into_iter()
.map(|(key, mods)| crate::inputmap::canonical_chord(&key, mods))
.collect::<Vec<_>>();
@@ -163,15 +175,7 @@ impl TermWindow {
.then(a_mods.bits().cmp(&b_mods.bits()))
.then(a_key.cmp(b_key))
});
- let (key, mods) = chords.into_iter().next()?;
- let rendering = self.config.ui_key_cap_rendering;
- let label = crate::inputmap::chord_label(&key, mods, rendering);
- // Set tight, as the Mac's menus write it: ⌘P, not ⌘ P.
- Some(if rendering == UIKeyCapRendering::AppleSymbols {
- label.replace(' ', "")
- } else {
- label
- })
+ chords.into_iter().next()
}
fn hover_style(&self) -> anyhow::Result<HoverStyle> {
diff --git a/wezterm-gui/src/termwindow/render/paint.rs b/wezterm-gui/src/termwindow/render/paint.rs
index f9b4dac0..45d3d6d4 100644
--- a/wezterm-gui/src/termwindow/render/paint.rs
+++ b/wezterm-gui/src/termwindow/render/paint.rs
@@ -4931,6 +4931,7 @@ impl crate::TermWindow {
self.advance_workspace_sidebar_hover(frame_now);
self.advance_right_sidebar_hover(frame_now);
self.advance_window_tab_reveal(frame_now);
+ self.advance_thread_numbers(frame_now);
self.advance_content_view_fade(frame_now);
self.advance_sidebar_slides(frame_now);
self.advance_library(frame_now);
diff --git a/wezterm-gui/src/termwindow/render/pane.rs b/wezterm-gui/src/termwindow/render/pane.rs
index 2ebd5147..e1d7a060 100644
--- a/wezterm-gui/src/termwindow/render/pane.rs
+++ b/wezterm-gui/src/termwindow/render/pane.rs
@@ -1847,8 +1847,7 @@ impl crate::TermWindow {
return Ok(());
}
- let text = self.ellipsize_ui_text(font, text, width)?;
- self.paint_ui_title_text(layers, font, &metrics, &text, x, y, width, foreground)
+ self.paint_fading_title(layers, font, &metrics, text, x, y, width, foreground)
}
/// The icon heading a pane tab: the card dressing what the pane runs,
diff --git a/wezterm-gui/src/termwindow/thread_numbers.rs b/wezterm-gui/src/termwindow/thread_numbers.rs
new file mode 100644
index 00000000..ee2c9d3e
--- /dev/null
+++ b/wezterm-gui/src/termwindow/thread_numbers.rs
@@ -0,0 +1,779 @@
+//! The numbers on the sidebar's threads: hold the keys that jump to them and
+//! the first rows each show the chord that reaches them.
+//!
+//! Those keys are the ones most shortcuts start with, so nothing shows until
+//! a hold has lasted, and anything else pressed on the way ends it until the
+//! keys come up: a chord of ours never flashes the numbers. A number pressed
+//! once they are up leaves them up, for the next one. The system's own chords
+//! are another matter: the window hears nothing of Cmd-Tab, so lingering in
+//! the app switcher brings them up until the switch takes the keyboard away.
+//!
+//! Which keys is the keymap's business. What has to be held is the modifiers
+//! of the first number bound, and a row reads what is bound to it, so a
+//! shortcut changed in Settings changes what is held and what shows.
+
+use crate::quad::TripleLayerQuadAllocator;
+use crate::termwindow::render::split_slide::MIN_FRAMES;
+use crate::termwindow::sidebar_hover::HoverFrame;
+use crate::termwindow::ui::icons::SvgIcon;
+use crate::termwindow::ui::sidebar::over;
+use crate::termwindow::ui::tokens::{CAPSULE_BORDER_WIDTH, SIDEBAR_TITLE_FADE_GAP};
+use crate::termwindow::TermWindow;
+use crate::ui::anim::{self, Easing, Timeline};
+use crate::ui::draw::TextFade;
+use crate::ui::UiPalette;
+use crate::utilsprites::RenderMetrics;
+use crate::workspace_threads::{WorkspaceThreadId, WorkspaceThreadsView};
+use anyhow::Context;
+use config::keyassignment::KeyAssignment;
+use mux::Mux;
+use std::rc::Rc;
+use std::time::{Duration, Instant};
+use wezterm_font::LoadedFont;
+use window::color::LinearRgba;
+use window::{Modifiers, PhysKeyCode, RawKeyEvent, UIKeyCapRendering, Window, WindowOps};
+
+/// How many rows have a number: the digits, 1 to 9.
+pub(crate) const MOST_NUMBERS: usize = 9;
+
+/// How long the keys have to stay down before the numbers come.
+const HOLD: Duration = Duration::from_millis(500);
+/// How long all of them take to come, row by row...
+const ARRIVAL: Duration = anim::STANDARD;
+/// ...and to go, which nothing should be kept waiting for.
+const DEPARTURE: Duration = anim::MICRO;
+/// How far through the arrival each row sets off after the one above it.
+const STAGGER: f32 = 0.05;
+/// How soon a number coming again is its key still held down: past the wait
+/// before a key starts to repeat. Nothing is lost to a deliberate second
+/// press this soon, which would find the thread already open.
+const KEY_STILL_DOWN: Duration = Duration::from_millis(700);
+
+/// A number's text, against the sidebar's own.
+const FONT_SCALE: f64 = 0.8;
+const FONT_WEIGHT: u16 = 500;
+/// The Command key's symbol is drawn as an icon, this much of the text's
+/// line tall: the symbol font's stands a third over the digits and runs into
+/// them.
+const COMMAND_SCALE: f32 = 0.85;
+/// The room between it and what follows it.
+const COMMAND_GAP: usize = 2;
+const PAD_X: usize = 10;
+const PAD_Y: usize = 4;
+const RADIUS: f32 = 12.0;
+/// How far short of its place, towards the row's end, a number sets off.
+const TRAVEL: f32 = 12.0;
+/// How far a long name takes to go out in front of a number...
+const NAME_FADE: f32 = 56.0;
+/// ...and the room it leaves there.
+const NAME_FADE_GAP: f32 = 4.0;
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
+enum Hold {
+ #[default]
+ Up,
+ /// Down since then, and not for long enough yet.
+ Counting(Instant),
+ /// Down for long enough: the numbers are up.
+ Held,
+ /// Down, and on the way to something else, until they come up.
+ Spent,
+}
+
+#[derive(Debug, Default)]
+pub(crate) struct ThreadNumbers {
+ hold: Hold,
+ /// How far through their arrival the numbers are, 0 to 1, for as long
+ /// as any of them is on screen.
+ reveal: Option<Timeline>,
+ /// The number that came last, and when.
+ last_number: Option<(usize, Instant)>,
+}
+
+impl ThreadNumbers {
+ /// The keys are down, or they are not. True when a frame has to follow.
+ fn keys(&mut self, down: bool, now: Instant) -> bool {
+ match (down, self.hold) {
+ (true, Hold::Up) => {
+ self.hold = Hold::Counting(now);
+ true
+ }
+ (true, _) | (false, Hold::Up) => false,
+ (false, _) => {
+ self.hold = Hold::Up;
+ self.hide(now);
+ true
+ }
+ }
+ }
+
+ /// The modifiers now down are `down`, and `hold` the ones that bring the
+ /// numbers, when they may come. One beyond those is a chord on its way,
+ /// whichever key of it came first and however they go on to come up; one
+ /// of a `hold` of two may just be the first of them. True when a frame
+ /// has to follow.
+ fn modifiers(&mut self, down: Modifiers, hold: Option<Modifiers>, now: Instant) -> bool {
+ if down == Modifiers::NONE {
+ self.keys(false, now)
+ } else if Some(down) == hold {
+ self.keys(true, now)
+ } else if self.hold == Hold::Up && hold.is_some_and(|hold| !hold.contains(down)) {
+ self.hold = Hold::Spent;
+ false
+ } else {
+ self.interrupt(false, now)
+ }
+ }
+
+ /// Number `index` came. False when that is its key still held down,
+ /// coming round again: a jump can move the rows, and the same number
+ /// would then be a different thread.
+ fn number_pressed(&mut self, index: usize, now: Instant) -> bool {
+ let again = self.last_number.is_some_and(|(last, at)| {
+ last == index && now.saturating_duration_since(at) < KEY_STILL_DOWN
+ });
+ self.last_number = Some((index, now));
+ !again
+ }
+
+ /// Something other than the keys was pressed, a `number` or not. True
+ /// when a frame has to follow.
+ fn interrupt(&mut self, number: bool, now: Instant) -> bool {
+ match self.hold {
+ // Whoever presses a number this soon knows it already.
+ Hold::Counting(_) => {
+ self.hold = Hold::Spent;
+ false
+ }
+ Hold::Held if !number => {
+ self.hold = Hold::Spent;
+ self.hide(now);
+ true
+ }
+ _ => false,
+ }
+ }
+
+ /// No fade: a window that has lost the keyboard hears nothing of them
+ /// coming up, and gets few frames to finish one in.
+ fn cancel(&mut self) {
+ *self = Self::default();
+ }
+
+ fn show(&mut self, now: Instant) {
+ match self.reveal.as_mut() {
+ Some(reveal) => reveal.retarget(now, 1.0, ARRIVAL, Easing::Linear),
+ None => self.reveal = Some(Timeline::new(now, 0.0, 1.0, ARRIVAL, Easing::Linear)),
+ }
+ }
+
+ fn hide(&mut self, now: Instant) {
+ if let Some(reveal) = self.reveal.as_mut() {
+ if reveal.target() != 0.0 {
+ reveal.retarget(now, 0.0, DEPARTURE, Easing::Linear);
+ }
+ }
+ }
+
+ /// Move on to the frame at `now`.
+ fn step(&mut self, now: Instant) -> HoverFrame {
+ let mut counting = None;
+ if let Hold::Counting(since) = self.hold {
+ let due = since + HOLD;
+ if now >= due {
+ self.hold = Hold::Held;
+ self.show(now);
+ } else {
+ counting = Some(due);
+ }
+ }
+ if let Some(reveal) = self.reveal.as_mut() {
+ reveal.pace(now, ARRIVAL / MIN_FRAMES);
+ if reveal.advance(now) {
+ return HoverFrame::Now;
+ }
+ if reveal.target() == 0.0 {
+ self.reveal = None;
+ }
+ }
+ counting.map_or(HoverFrame::None, HoverFrame::At)
+ }
+
+ /// How far through their arrival the numbers are, when they are up at
+ /// all.
+ fn out(&self, now: Instant) -> Option<f32> {
+ self.reveal.as_ref().map(|reveal| reveal.value(now))
+ }
+}
+
+/// How far out the number of row `index` is, 0 to 1, with all of them `out`
+/// of the way: a wave down the rows, which going runs back up.
+fn row_progress(out: f32, index: usize) -> f32 {
+ let start = index as f32 * STAGGER;
+ let span = 1.0 - (MOST_NUMBERS - 1) as f32 * STAGGER;
+ Easing::OutCubic.apply((out - start) / span)
+}
+
+fn is_number_key(key: &RawKeyEvent) -> bool {
+ use PhysKeyCode::*;
+ matches!(
+ key.phys_code,
+ Some(K1 | K2 | K3 | K4 | K5 | K6 | K7 | K8 | K9)
+ )
+}
+
+/// One row's number, as far out as this frame has it.
+pub(crate) struct ThreadNumber {
+ thread_id: WorkspaceThreadId,
+ /// Whether it opens with the Command key's symbol, which `label` then
+ /// leaves out.
+ command: bool,
+ label: String,
+ text_width: usize,
+ progress: f32,
+ font: Rc<LoadedFont>,
+ metrics: RenderMetrics,
+}
+
+impl ThreadNumber {
+ /// How much of the row's end icons is left, as the number takes over.
+ pub(crate) fn icons_left(&self) -> f32 {
+ 1.0 - self.progress
+ }
+}
+
+/// The numbers one paint of the sidebar shows.
+pub(crate) struct ThreadNumberRows(Vec<ThreadNumber>);
+
+impl ThreadNumberRows {
+ pub(crate) fn of(&self, thread_id: &str) -> Option<&ThreadNumber> {
+ self.0.iter().find(|number| number.thread_id == thread_id)
+ }
+}
+
+impl TermWindow {
+ /// The modifiers the window reports as held now.
+ pub(crate) fn note_thread_number_modifiers(&mut self, modifiers: Modifiers) {
+ let hold = self
+ .thread_numbers_can_show()
+ .then(|| self.thread_number_modifiers())
+ .flatten();
+ let down = modifiers.remove_positional_mods();
+ if self.thread_numbers.modifiers(down, hold, Instant::now()) {
+ self.invalidate_window();
+ }
+ }
+
+ /// A key that is not a modifier went down.
+ pub(crate) fn note_key_for_thread_numbers(&mut self, key: &RawKeyEvent) {
+ self.interrupt_thread_numbers(is_number_key(key));
+ }
+
+ /// Something other than the keys was pressed or done, a `number` or not.
+ /// Mac menus take their chords before any key event, so an action is as
+ /// good as a key here.
+ pub(crate) fn interrupt_thread_numbers(&mut self, number: bool) {
+ if self.thread_numbers.interrupt(number, Instant::now()) {
+ self.invalidate_window();
+ }
+ }
+
+ /// The window lost the keyboard.
+ pub(crate) fn cancel_thread_numbers(&mut self) {
+ self.thread_numbers.cancel();
+ }
+
+ pub(crate) fn advance_thread_numbers(&mut self, now: Instant) {
+ match self.thread_numbers.step(now) {
+ HoverFrame::None => {}
+ HoverFrame::Now => self.invalidate_window(),
+ HoverFrame::At(due) => self.update_next_frame_time(Some(due)),
+ }
+ }
+
+ /// Nothing is holding the keyboard for itself. Mac menus take the number
+ /// keys ahead of whatever is, so that has to be asked here too.
+ fn thread_keys_free(&self) -> bool {
+ self.command_palette.is_none()
+ && !self.menu_or_overlay_open()
+ && !self.recording_overlay.owns_keyboard()
+ && !self.share_panel_open()
+ && !self.library_open()
+ }
+
+ /// The window has the keyboard to itself, and the sidebar is there to
+ /// show them on.
+ fn thread_numbers_can_show(&self) -> bool {
+ self.focused.is_some() && self.workspace_sidebar_is_presented() && self.thread_keys_free()
+ }
+
+ /// The modifiers of the first number bound to anything.
+ fn thread_number_modifiers(&self) -> Option<Modifiers> {
+ (0..MOST_NUMBERS)
+ .find_map(|index| {
+ self.native_chord(&KeyAssignment::ActivateWorkspaceThreadByIndex(index))
+ })
+ .map(|(_, mods)| mods.remove_positional_mods())
+ }
+
+ /// What number `index` reads: whether it opens with the Command key,
+ /// and the rest of its chord, set tight, as the Mac writes them. Spelled
+ /// out in words a chord would take half the row, and it would say nine
+ /// times over what is being held, so elsewhere it is the key alone.
+ fn thread_number_label(&self, index: usize) -> Option<(bool, String)> {
+ let (key, mods) =
+ self.native_chord(&KeyAssignment::ActivateWorkspaceThreadByIndex(index))?;
+ let rendering = self.config.ui_key_cap_rendering;
+ if rendering != UIKeyCapRendering::AppleSymbols {
+ return Some((false, crate::inputmap::ui_key(&key, rendering)));
+ }
+ let rest = mods - Modifiers::SUPER;
+ Some((
+ mods.contains(Modifiers::SUPER),
+ crate::inputmap::tight_chord_label(&key, rest, rendering),
+ ))
+ }
+
+ /// The numbers to show on the rows of `view` in this frame, when any
+ /// are up.
+ pub(crate) fn thread_number_rows(
+ &self,
+ view: &WorkspaceThreadsView,
+ ) -> anyhow::Result<Option<ThreadNumberRows>> {
+ let Some(out) = self
+ .thread_numbers
+ .out(Instant::now())
+ .filter(|_| self.thread_numbers_can_show())
+ else {
+ return Ok(None);
+ };
+ let font = self
+ .fonts
+ .title_font_with_size_and_weight(
+ crate::native_settings::sidebar_font_size(&crate::native_settings::load_shared())
+ * FONT_SCALE,
+ FONT_WEIGHT,
+ )
+ .context("sidebar thread number font")?;
+ let metrics = RenderMetrics::with_font_metrics(&font.metrics());
+ let mut rows = Vec::new();
+ for (index, thread) in view.first_threads(MOST_NUMBERS).into_iter().enumerate() {
+ let Some((command, label)) = self.thread_number_label(index) else {
+ continue;
+ };
+ let text_width = self.sidebar_text_width(&font, &label)?.ceil() as usize;
+ rows.push(ThreadNumber {
+ thread_id: thread.id.clone(),
+ command,
+ label,
+ text_width,
+ progress: row_progress(out, index),
+ font: Rc::clone(&font),
+ metrics,
+ });
+ }
+ Ok(Some(ThreadNumberRows(rows)))
+ }
+
+ /// How tall the Command key's symbol stands in `number`.
+ fn thread_number_command_size(&self, number: &ThreadNumber) -> usize {
+ (number.metrics.cell_size.height as f32 * COMMAND_SCALE).round() as usize
+ }
+
+ /// How wide `number` is, padding and all.
+ fn thread_number_width(&self, number: &ThreadNumber) -> usize {
+ let command = if number.command {
+ self.thread_number_command_size(number) + self.ui_px(COMMAND_GAP)
+ } else {
+ 0
+ };
+ command + number.text_width + self.ui_px(PAD_X) * 2
+ }
+
+ /// Where a row's number starts in this frame, when it ends at `right`
+ /// once it has landed.
+ fn thread_number_left(&self, number: &ThreadNumber, right: usize) -> usize {
+ let width = self.thread_number_width(number);
+ let shift = (self.ui_f32(TRAVEL) * (1.0 - number.progress)).round() as usize;
+ right.saturating_sub(width) + shift
+ }
+
+ /// What a row's name does in front of its number: it thins out to
+ /// nothing short of it, so a long name ends softly and not at an edge,
+ /// and it travels with the number, coming and going as the number does.
+ fn thread_number_fade(&self, number: &ThreadNumber, right: usize) -> TextFade {
+ let to = self.thread_number_left(number, right) as f32 - self.ui_f32(NAME_FADE_GAP);
+ TextFade {
+ from: to - self.ui_f32(NAME_FADE),
+ to,
+ amount: number.progress,
+ }
+ }
+
+ /// A thread row's `name`, and its number when it has one, ending at
+ /// `row_end`.
+ #[allow(clippy::too_many_arguments)]
+ pub(crate) fn paint_thread_row_name(
+ &self,
+ layers: &mut TripleLayerQuadAllocator,
+ font: &Rc<LoadedFont>,
+ metrics: RenderMetrics,
+ name: &str,
+ x: usize,
+ text_y: usize,
+ width: usize,
+ color: LinearRgba,
+ number: Option<&ThreadNumber>,
+ row_end: usize,
+ row_y: usize,
+ row_height: usize,
+ current: bool,
+ chrome: &UiPalette,
+ ) -> anyhow::Result<()> {
+ self.paint_title_fading_with(
+ layers,
+ font,
+ &metrics,
+ name,
+ x,
+ text_y,
+ width,
+ color,
+ SIDEBAR_TITLE_FADE_GAP,
+ |own| {
+ let Some(number) = number else {
+ return own;
+ };
+ let fade = self.thread_number_fade(number, row_end);
+ // A name already going out goes out in front of the number
+ // instead, by the time it has landed.
+ Some(own.map_or(fade, |own| own.towards(fade, number.progress)))
+ },
+ )?;
+ let Some(number) = number else {
+ return Ok(());
+ };
+ self.paint_thread_number(layers, number, row_end, row_y, row_height, current, chrome)
+ }
+
+ /// A row's number, ending at `right`. It is solid, on the sidebar's own
+ /// colour whatever shows through the sidebar, so as it fades in it takes
+ /// the place of the row's mark and nothing on the row has to move.
+ #[allow(clippy::too_many_arguments)]
+ fn paint_thread_number(
+ &self,
+ layers: &mut TripleLayerQuadAllocator,
+ number: &ThreadNumber,
+ right: usize,
+ y: usize,
+ row_height: usize,
+ current: bool,
+ chrome: &UiPalette,
+ ) -> anyhow::Result<()> {
+ let progress = number.progress;
+ let cell_height = number.metrics.cell_size.height as usize;
+ let pad_x = self.ui_px(PAD_X);
+ let width = self.thread_number_width(number);
+ let height = (cell_height + self.ui_px(PAD_Y) * 2).min(row_height);
+ let x = self.thread_number_left(number, right);
+ let top = y + row_height.saturating_sub(height) / 2;
+ self.fill_rounded_rectangle_with_border(
+ layers,
+ 2,
+ euclid::rect(x as f32, top as f32, width as f32, height as f32),
+ over(chrome.sidebar_row_active_bg, chrome.workspace_sidebar_bg).mul_alpha(progress),
+ chrome.sidebar_row_active_border.mul_alpha(progress),
+ self.ui_f32(RADIUS),
+ CAPSULE_BORDER_WIDTH,
+ )
+ .context("sidebar thread number")?;
+ let color = if current {
+ chrome.text
+ } else {
+ chrome.secondary_text
+ }
+ .mul_alpha(progress);
+ let mut text_x = x + pad_x;
+ if number.command {
+ let size = self.thread_number_command_size(number);
+ let icon_y = top + height.saturating_sub(size) / 2;
+ self.paint_sidebar_icon(layers, SvgIcon::Command, text_x, icon_y, size, color)?;
+ text_x += size + self.ui_px(COMMAND_GAP);
+ }
+ self.paint_sidebar_text(
+ layers,
+ &number.font,
+ number.metrics,
+ &number.label,
+ text_x,
+ top + height.saturating_sub(cell_height) / 2,
+ number.text_width + pad_x,
+ color,
+ )
+ }
+
+ /// Open the thread number `index` reaches, as a click on its row does,
+ /// unless something else has the keyboard: with the Library up, say, its
+ /// list is not there to count down.
+ pub(crate) fn activate_numbered_thread(&mut self, index: usize, window: &Window) {
+ if !self.thread_keys_free() || !self.thread_numbers.number_pressed(index, Instant::now()) {
+ return;
+ }
+ let mux = Mux::get();
+ let active_workspace = self
+ .current_mux_workspace()
+ .unwrap_or_else(|| mux.active_workspace());
+ let workspaces = mux.iter_workspaces();
+ let view = self.workspace_sidebar_view(&active_workspace, &workspaces);
+ let threads = view.first_threads(index + 1);
+ let Some(thread_id) = threads.get(index).map(|thread| thread.id.clone()) else {
+ return;
+ };
+ if !self.open_remote_workspace_thread_without_connecting(&thread_id, window) {
+ self.activate_workspace_thread(thread_id, window);
+ }
+ window.invalidate();
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn at(start: Instant, ms: u64) -> Instant {
+ start + Duration::from_millis(ms)
+ }
+
+ /// A frame every 10ms from `from` to `to`, each one painted.
+ fn frames(numbers: &mut ThreadNumbers, start: Instant, from: u64, to: u64) {
+ for ms in (from..=to).step_by(10) {
+ numbers.step(at(start, ms));
+ numbers.out(at(start, ms));
+ }
+ }
+
+ /// Up for good, `at` 1000ms past `start`.
+ fn held(start: Instant) -> ThreadNumbers {
+ let mut numbers = ThreadNumbers::default();
+ numbers.keys(true, start);
+ frames(&mut numbers, start, 500, 1000);
+ assert_eq!(numbers.out(at(start, 1000)), Some(1.0));
+ numbers
+ }
+
+ #[test]
+ fn a_chord_that_lets_go_of_its_extra_key_first_stays_spent() {
+ let start = Instant::now();
+ let hold = Some(Modifiers::SUPER);
+ let mut numbers = ThreadNumbers::default();
+ numbers.modifiers(Modifiers::SUPER, hold, start);
+ numbers.modifiers(Modifiers::SUPER | Modifiers::SHIFT, hold, at(start, 50));
+ numbers.modifiers(Modifiers::SUPER, hold, at(start, 100));
+ frames(&mut numbers, start, 100, 1000);
+ assert_eq!(numbers.out(at(start, 1000)), None);
+ numbers.modifiers(Modifiers::NONE, hold, at(start, 1010));
+ numbers.modifiers(Modifiers::SUPER, hold, at(start, 1020));
+ assert!(matches!(numbers.hold, Hold::Counting(_)));
+ }
+
+ #[test]
+ fn a_chord_that_starts_with_its_extra_key_is_spent_from_the_start() {
+ let start = Instant::now();
+ let hold = Some(Modifiers::SUPER);
+ let mut numbers = ThreadNumbers::default();
+ numbers.modifiers(Modifiers::SHIFT, hold, start);
+ numbers.modifiers(Modifiers::SHIFT | Modifiers::SUPER, hold, at(start, 50));
+ numbers.modifiers(Modifiers::SUPER, hold, at(start, 100));
+ frames(&mut numbers, start, 100, 1000);
+ assert_eq!(numbers.out(at(start, 1000)), None);
+ numbers.modifiers(Modifiers::NONE, hold, at(start, 1010));
+ numbers.modifiers(Modifiers::SUPER, hold, at(start, 1020));
+ assert!(matches!(numbers.hold, Hold::Counting(_)));
+ }
+
+ #[test]
+ fn the_keys_of_a_hold_of_two_can_come_one_at_a_time() {
+ let start = Instant::now();
+ let hold = Some(Modifiers::CTRL | Modifiers::SHIFT);
+ let mut numbers = ThreadNumbers::default();
+ numbers.modifiers(Modifiers::CTRL, hold, start);
+ assert_eq!(numbers.hold, Hold::Up);
+ numbers.modifiers(Modifiers::CTRL | Modifiers::SHIFT, hold, at(start, 50));
+ assert!(matches!(numbers.hold, Hold::Counting(_)));
+ }
+
+ #[test]
+ fn a_number_key_held_down_counts_once() {
+ let start = Instant::now();
+ let mut numbers = ThreadNumbers::default();
+ assert!(numbers.number_pressed(1, start));
+ // The wait before it starts to repeat, and the repeats that follow.
+ assert!(!numbers.number_pressed(1, at(start, 500)));
+ assert!(!numbers.number_pressed(1, at(start, 530)));
+ assert!(!numbers.number_pressed(1, at(start, 1100)));
+ // Let go, and pressed again.
+ assert!(numbers.number_pressed(1, at(start, 2000)));
+ }
+
+ #[test]
+ fn another_number_is_never_the_last_one_coming_round() {
+ let start = Instant::now();
+ let mut numbers = ThreadNumbers::default();
+ assert!(numbers.number_pressed(1, start));
+ assert!(numbers.number_pressed(2, at(start, 50)));
+ assert!(numbers.number_pressed(1, at(start, 100)));
+ }
+
+ #[test]
+ fn keys_that_may_not_bring_them_leave_them_away() {
+ let start = Instant::now();
+ let mut numbers = ThreadNumbers::default();
+ numbers.modifiers(Modifiers::SUPER, None, start);
+ frames(&mut numbers, start, 0, 1000);
+ assert_eq!(numbers.out(at(start, 1000)), None);
+ assert_eq!(numbers.hold, Hold::Up);
+ }
+
+ #[test]
+ fn a_short_press_shows_nothing() {
+ let start = Instant::now();
+ let mut numbers = ThreadNumbers::default();
+ assert!(numbers.keys(true, start));
+ assert_eq!(numbers.step(at(start, 100)), HoverFrame::At(at(start, 500)));
+ assert_eq!(numbers.out(at(start, 100)), None);
+ assert!(numbers.keys(false, at(start, 200)));
+ assert_eq!(numbers.step(at(start, 500)), HoverFrame::None);
+ assert_eq!(numbers.out(at(start, 500)), None);
+ }
+
+ #[test]
+ fn a_hold_brings_them_up_and_then_asks_for_nothing() {
+ let start = Instant::now();
+ let mut numbers = ThreadNumbers::default();
+ numbers.keys(true, start);
+ assert_eq!(numbers.step(at(start, 500)), HoverFrame::Now);
+ // Not a moment of the arrival goes on the frame that first draws it.
+ assert_eq!(numbers.out(at(start, 500)), Some(0.0));
+ frames(&mut numbers, start, 510, 1000);
+ assert_eq!(numbers.out(at(start, 1000)), Some(1.0));
+ assert_eq!(numbers.step(at(start, 1010)), HoverFrame::None);
+ }
+
+ #[test]
+ fn letting_go_takes_them_away() {
+ let start = Instant::now();
+ let mut numbers = held(start);
+ assert!(numbers.keys(false, at(start, 1000)));
+ assert_eq!(numbers.step(at(start, 1000)), HoverFrame::Now);
+ frames(&mut numbers, start, 1000, 1300);
+ assert_eq!(numbers.out(at(start, 1300)), None);
+ assert_eq!(numbers.step(at(start, 1310)), HoverFrame::None);
+ }
+
+ #[test]
+ fn going_again_while_they_leave_waits_out_a_whole_hold() {
+ let start = Instant::now();
+ let mut numbers = held(start);
+ numbers.keys(false, at(start, 1000));
+ frames(&mut numbers, start, 1000, 1040);
+ assert!(numbers.keys(true, at(start, 1050)));
+ frames(&mut numbers, start, 1050, 1300);
+ assert_eq!(numbers.out(at(start, 1300)), None);
+ frames(&mut numbers, start, 1300, 2000);
+ assert_eq!(numbers.out(at(start, 2000)), Some(1.0));
+ }
+
+ #[test]
+ fn a_chord_on_the_way_shows_nothing_until_the_keys_come_up() {
+ let start = Instant::now();
+ let mut numbers = ThreadNumbers::default();
+ numbers.keys(true, start);
+ assert!(!numbers.interrupt(false, at(start, 100)));
+ frames(&mut numbers, start, 100, 1000);
+ assert_eq!(numbers.out(at(start, 1000)), None);
+
+ // Still down, as far as the window hears of it again.
+ assert!(!numbers.keys(true, at(start, 1000)));
+ frames(&mut numbers, start, 1000, 2000);
+ assert_eq!(numbers.out(at(start, 2000)), None);
+
+ numbers.keys(false, at(start, 2000));
+ numbers.keys(true, at(start, 2010));
+ frames(&mut numbers, start, 2510, 3000);
+ assert_eq!(numbers.out(at(start, 3000)), Some(1.0));
+ }
+
+ #[test]
+ fn a_number_pressed_before_they_are_up_keeps_them_away() {
+ let start = Instant::now();
+ let mut numbers = ThreadNumbers::default();
+ numbers.keys(true, start);
+ numbers.interrupt(true, at(start, 100));
+ frames(&mut numbers, start, 100, 1000);
+ assert_eq!(numbers.out(at(start, 1000)), None);
+ }
+
+ #[test]
+ fn a_number_leaves_them_up_and_anything_else_takes_them_away() {
+ let start = Instant::now();
+ let mut numbers = held(start);
+ assert!(!numbers.interrupt(true, at(start, 1000)));
+ frames(&mut numbers, start, 1000, 1200);
+ assert_eq!(numbers.out(at(start, 1200)), Some(1.0));
+
+ assert!(numbers.interrupt(false, at(start, 1200)));
+ frames(&mut numbers, start, 1200, 1500);
+ assert_eq!(numbers.out(at(start, 1500)), None);
+ }
+
+ #[test]
+ fn losing_the_keyboard_leaves_nothing_up_and_nothing_counting() {
+ let start = Instant::now();
+ let mut numbers = held(start);
+ numbers.cancel();
+ assert_eq!(numbers.out(at(start, 1000)), None);
+ assert_eq!(numbers.step(at(start, 1000)), HoverFrame::None);
+
+ // Keys that come back down are a new hold, not the rest of the old.
+ assert!(numbers.keys(true, at(start, 1010)));
+ assert_eq!(
+ numbers.step(at(start, 1020)),
+ HoverFrame::At(at(start, 1510))
+ );
+ }
+
+ #[test]
+ fn the_rows_go_out_in_a_wave_that_lands_together() {
+ for index in 0..MOST_NUMBERS {
+ assert_eq!(row_progress(0.0, index), 0.0);
+ assert!(row_progress(1.0, index) > 0.999);
+ }
+ let halfway: Vec<f32> = (0..MOST_NUMBERS)
+ .map(|index| row_progress(0.5, index))
+ .collect();
+ assert!(halfway.windows(2).all(|rows| rows[0] > rows[1]));
+ assert!(halfway[0] > 0.9);
+ assert!(halfway[MOST_NUMBERS - 1] > 0.0);
+ }
+
+ #[test]
+ fn only_the_digits_are_numbers() {
+ let key = |phys_code| RawKeyEvent {
+ key: window::KeyCode::Char('x'),
+ modifiers: Modifiers::NONE,
+ leds: window::KeyboardLedStatus::empty(),
+ phys_code,
+ raw_code: 0,
+ #[cfg(windows)]
+ scan_code: 0,
+ repeat_count: 1,
+ key_is_down: true,
+ handled: window::Handled::new(),
+ };
+ assert!(is_number_key(&key(Some(PhysKeyCode::K1))));
+ assert!(is_number_key(&key(Some(PhysKeyCode::K9))));
+ assert!(!is_number_key(&key(Some(PhysKeyCode::K0))));
+ assert!(!is_number_key(&key(Some(PhysKeyCode::A))));
+ assert!(!is_number_key(&key(None)));
+ }
+}
diff --git a/wezterm-gui/src/termwindow/ui/command_palette.rs b/wezterm-gui/src/termwindow/ui/command_palette.rs
index 3edefc59..5e946db6 100644
--- a/wezterm-gui/src/termwindow/ui/command_palette.rs
+++ b/wezterm-gui/src/termwindow/ui/command_palette.rs
@@ -841,6 +841,7 @@ fn thread_icon_style<'a>(
count_font: &marks.count_font,
count_metrics: &marks.count_metrics,
count_color,
+ opacity: 1.0,
}
}
diff --git a/wezterm-gui/src/termwindow/ui/icons.rs b/wezterm-gui/src/termwindow/ui/icons.rs
index 7a901eab..ffdcbdc7 100644
--- a/wezterm-gui/src/termwindow/ui/icons.rs
+++ b/wezterm-gui/src/termwindow/ui/icons.rs
@@ -109,6 +109,7 @@ pub enum SvgIcon {
Terminal,
Trash2,
Unlink2,
+ Command,
ALargeSmall,
AppWindow,
Bold,
@@ -403,6 +404,7 @@ impl SvgIcon {
}
Self::Terminal => include_bytes!("../../../../third_party/lucide/icons/terminal.svg"),
Self::Trash2 => include_bytes!("../../../../third_party/lucide/icons/trash-2.svg"),
+ Self::Command => include_bytes!("../../../../third_party/lucide/icons/command.svg"),
Self::ALargeSmall => {
include_bytes!("../../../../third_party/lucide/icons/a-large-small.svg")
}
@@ -965,6 +967,7 @@ mod tests {
SvgIcon::SplitVertical,
SvgIcon::Terminal,
SvgIcon::Trash2,
+ SvgIcon::Command,
SvgIcon::X,
// Remote Hosts' Tailscale group: the tailnet and its machines.
SvgIcon::Apple,
diff --git a/wezterm-gui/src/termwindow/ui/sidebar.rs b/wezterm-gui/src/termwindow/ui/sidebar.rs
index 8b07045c..66ebbbcd 100644
--- a/wezterm-gui/src/termwindow/ui/sidebar.rs
+++ b/wezterm-gui/src/termwindow/ui/sidebar.rs
@@ -10,7 +10,7 @@ use crate::termwindow::ui::status_icon::UiStatusKind;
use crate::termwindow::ui::tokens::{
CAPSULE_BORDER_WIDTH, SIDEBAR_ICON_GAP, SIDEBAR_INSET, SIDEBAR_MAX_WIDTH, SIDEBAR_MIN_WIDTH,
SIDEBAR_RESIZE_HANDLE_WIDTH, SIDEBAR_ROW_GAP, SIDEBAR_ROW_HIGHLIGHT_RADIUS,
- SIDEBAR_ROW_RADIUS, SIDEBAR_WIDTH_CELLS,
+ SIDEBAR_ROW_RADIUS, SIDEBAR_TITLE_FADE_GAP, SIDEBAR_WIDTH_CELLS,
WINDOW_TAB_FULLSCREEN_NEW_SESSION_EXTRA_HEIGHT, WINDOW_TAB_FULLSCREEN_NEW_SESSION_Y_OFFSET,
WINDOW_TAB_FULLSCREEN_SIDEBAR_BUTTON_X, WINDOW_TAB_FULLSCREEN_SIDEBAR_BUTTON_Y_OFFSET,
WINDOW_TAB_TOP_SPACER,
@@ -945,8 +945,9 @@ impl crate::TermWindow {
/// `end_x`. With `show_end` false the row's buttons have the end, and
/// neither the mark nor trailing icons are drawn. A `dimmed` row -- a
/// ref whose machine is away -- has no mark: it cannot say what the
- /// thread is doing. Returns
- /// where the name starts and the right edge it must keep clear of.
+ /// thread is doing. `icons_at_end` is how present icons kept at the row's
+ /// end are. Returns where the name starts and the right edge it must keep
+ /// clear of.
#[allow(clippy::too_many_arguments)]
fn paint_sidebar_thread_marks(
&self,
@@ -961,6 +962,7 @@ impl crate::TermWindow {
show_end: bool,
dimmed: bool,
current: bool,
+ icons_at_end: f32,
chrome: &UiPalette,
foreground: LinearRgba,
) -> anyhow::Result<(usize, usize)> {
@@ -994,6 +996,11 @@ impl crate::TermWindow {
count_font: &marks.count_font,
count_metrics: &marks.count_metrics,
count_color: chrome.secondary_text,
+ opacity: if marks.layout == NativeThreadIcons::Trailing {
+ icons_at_end
+ } else {
+ 1.0
+ },
};
if marks.layout == NativeThreadIcons::Trailing {
if show_end {
@@ -1285,7 +1292,7 @@ impl crate::TermWindow {
/// The rows of the Space the sidebar is painted for. Painted for one
/// this window is not in -- a card in the Library, a Space swiped to --
/// nothing of the window's own workspace goes into them.
- fn workspace_sidebar_view(
+ pub(crate) fn workspace_sidebar_view(
&self,
active_workspace: &str,
workspaces: &[String],
@@ -2125,6 +2132,13 @@ impl crate::TermWindow {
.first()
.cloned()
};
+ // A card in the Library and a Space swiped to are not the list the
+ // numbers count down.
+ let numbers = if card || self.workspace_sidebar_preview_space_id.is_some() {
+ None
+ } else {
+ self.thread_number_rows(&view)?
+ };
// Everything from here until the end of the project loop scrolls with
// `virtual_y`. A space-swipe slides exactly this stretch and leaves the
// chrome painted before and after it standing.
@@ -2251,9 +2265,13 @@ impl crate::TermWindow {
let pin_x = delete_x.saturating_sub(action_size + 4);
let action_y = y + ((session_row_height.saturating_sub(action_size)) / 2);
let row_hovered = is_hovered && !is_renaming_session;
+ let number = numbers.as_ref().and_then(|numbers| numbers.of(&session.id));
// In a Library card a row takes its click whole
// (`push_library_card_items`): no buttons on it there.
- let shows_actions = row_hovered && self.library_card_rect().is_none();
+ // Nor under a number, where a click would find them
+ // unseen.
+ let shows_actions =
+ row_hovered && self.library_card_rect().is_none() && number.is_none();
let surface = if is_selected {
over(selected_bg, sidebar_bg)
} else if row_hovered {
@@ -2261,26 +2279,28 @@ impl crate::TermWindow {
} else {
sidebar_bg
};
+ let row_end = pinned_x
+ .saturating_add(pinned_width)
+ .saturating_sub(self.ui_px(SIDEBAR_INSET));
let (pinned_text_x, marks_right) = self.paint_sidebar_thread_marks(
layers,
&row_marks,
session,
pinned_status_x,
- pinned_x
- .saturating_add(pinned_width)
- .saturating_sub(self.ui_px(SIDEBAR_INSET)),
+ row_end,
y,
session_row_height,
surface,
!shows_actions,
false,
is_selected,
+ number.map_or(1.0, |number| number.icons_left()),
&chrome,
foreground,
)?;
let text_right = if shows_actions { pin_x } else { marks_right };
let title = self.sidebar_thread_title(&session.id, &session.name);
- self.paint_sidebar_text(
+ self.paint_thread_row_name(
layers,
&ui_font,
ui_metrics,
@@ -2289,6 +2309,12 @@ impl crate::TermWindow {
text_y,
text_right.saturating_sub(pinned_text_x + self.ui_px(SIDEBAR_INSET)),
if is_selected { active_fg } else { foreground },
+ number,
+ row_end,
+ y,
+ session_row_height,
+ is_selected,
+ &chrome,
)?;
if shows_actions {
@@ -2461,7 +2487,7 @@ impl crate::TermWindow {
muted_fg,
)?;
let project_title = self.sidebar_project_title(&project.id, &project.name);
- self.paint_sidebar_text(
+ self.paint_sidebar_name(
layers,
&ui_font,
ui_metrics,
@@ -2544,7 +2570,7 @@ impl crate::TermWindow {
)?;
}
let project_title = self.sidebar_project_title(&project.id, &project.name);
- self.paint_sidebar_text(
+ self.paint_sidebar_name(
layers,
&ui_font,
ui_metrics,
@@ -2704,9 +2730,13 @@ impl crate::TermWindow {
.context("sidebar hovered thread")?;
}
let row_hovered = is_hovered && !is_renaming_session;
+ let number =
+ numbers.as_ref().and_then(|numbers| numbers.of(&session.id));
// As for a pinned thread: no buttons on a row in a
- // Library card.
- let shows_actions = row_hovered && self.library_card_rect().is_none();
+ // Library card, or under a number.
+ let shows_actions = row_hovered
+ && self.library_card_rect().is_none()
+ && number.is_none();
let surface = if is_selected {
over(selected_bg, sidebar_bg)
} else if row_hovered {
@@ -2714,30 +2744,31 @@ impl crate::TermWindow {
} else {
sidebar_bg
};
- let (session_text_x, marks_right) = self
- .paint_sidebar_thread_marks(
- layers,
- &row_marks,
- session,
- session_status_x,
- session_x
- .saturating_add(session_width)
- .saturating_sub(self.ui_px(SIDEBAR_INSET)),
- y,
- session_row_height,
- surface,
- !shows_actions,
- false,
- is_selected,
- &chrome,
- foreground,
- )?;
+ let row_end = session_x
+ .saturating_add(session_width)
+ .saturating_sub(self.ui_px(SIDEBAR_INSET));
+ let (session_text_x, marks_right) = self.paint_sidebar_thread_marks(
+ layers,
+ &row_marks,
+ session,
+ session_status_x,
+ row_end,
+ y,
+ session_row_height,
+ surface,
+ !shows_actions,
+ false,
+ is_selected,
+ number.map_or(1.0, |number| number.icons_left()),
+ &chrome,
+ foreground,
+ )?;
let text_right = if shows_actions { pin_x } else { marks_right };
let text_width = text_right
.saturating_sub(session_text_x + self.ui_px(SIDEBAR_INSET));
let session_title =
self.sidebar_thread_title(&session.id, &session.name);
- self.paint_sidebar_text(
+ self.paint_thread_row_name(
layers,
&ui_font,
ui_metrics,
@@ -2746,6 +2777,12 @@ impl crate::TermWindow {
text_y,
text_width,
if is_selected { active_fg } else { foreground },
+ number,
+ row_end,
+ y,
+ session_row_height,
+ is_selected,
+ &chrome,
)?;
if shows_actions {
let pin_icon = if session.is_pinned {
@@ -2929,7 +2966,7 @@ impl crate::TermWindow {
};
let text_avail =
group_action_x.saturating_sub(group_text_x + self.ui_px(SIDEBAR_INSET));
- self.paint_sidebar_text(
+ self.paint_sidebar_name(
layers,
&ui_font,
ui_metrics,
@@ -3117,29 +3154,34 @@ impl crate::TermWindow {
} else {
sidebar_bg
};
+ let number = numbers.as_ref().and_then(|numbers| numbers.of(&session.id));
// A ref whose machine is away says nothing of what
// it is doing: it keeps its icons, not its mark.
+ let row_end = session_x
+ .saturating_add(session_width)
+ .saturating_sub(self.ui_px(SIDEBAR_INSET));
let (session_text_x, marks_right) = self.paint_sidebar_thread_marks(
layers,
&row_marks,
session,
session_status_x,
- session_x
- .saturating_add(session_width)
- .saturating_sub(self.ui_px(SIDEBAR_INSET)),
+ row_end,
y,
session_row_height,
surface,
- !is_hovered,
+ !is_hovered || number.is_some(),
dimmed,
is_selected,
+ number.map_or(1.0, |number| number.icons_left()),
&chrome,
foreground,
)?;
// Only a reference can be taken out: a row a server
// folder shows, with none of its own, stays as long
- // as the folder does.
+ // as the folder does. Nor is it to be hit unseen
+ // under a number.
let removable = is_hovered
+ && number.is_none()
&& (!reference.server_folder
|| workspace_threads::thread_ref_is_explicit(
self.workspace_sidebar_space_id(),
@@ -3153,7 +3195,7 @@ impl crate::TermWindow {
} else {
foreground
};
- self.paint_sidebar_text(
+ self.paint_thread_row_name(
layers,
&ui_font,
ui_metrics,
@@ -3162,6 +3204,12 @@ impl crate::TermWindow {
text_y,
text_right.saturating_sub(session_text_x + self.ui_px(SIDEBAR_INSET)),
text_fg,
+ number,
+ row_end,
+ y,
+ session_row_height,
+ is_selected,
+ &chrome,
)?;
if removable {
@@ -4352,6 +4400,33 @@ impl crate::TermWindow {
)
}
+ /// A folder's name: as a thread row's, it goes out when it is too long.
+ #[allow(clippy::too_many_arguments)]
+ fn paint_sidebar_name(
+ &self,
+ layers: &mut TripleLayerQuadAllocator,
+ font: &Rc<LoadedFont>,
+ metrics: RenderMetrics,
+ name: &str,
+ x: usize,
+ y: usize,
+ width: usize,
+ foreground: LinearRgba,
+ ) -> anyhow::Result<()> {
+ self.paint_title_fading_with(
+ layers,
+ font,
+ &metrics,
+ name,
+ x,
+ y,
+ width,
+ foreground,
+ SIDEBAR_TITLE_FADE_GAP,
+ |fade| fade,
+ )
+ }
+
pub(crate) fn paint_sidebar_text(
&self,
layers: &mut TripleLayerQuadAllocator,
diff --git a/wezterm-gui/src/termwindow/ui/tokens.rs b/wezterm-gui/src/termwindow/ui/tokens.rs
index e219219f..65a5857f 100644
--- a/wezterm-gui/src/termwindow/ui/tokens.rs
+++ b/wezterm-gui/src/termwindow/ui/tokens.rs
@@ -87,6 +87,12 @@ pub const WINDOW_TAB_GAP: usize = 18;
/// Matches `ssh_hosts_view`'s list fades, which solve the same problem
/// vertically.
pub const TAB_ROW_FADE_WIDTH: usize = 32;
+/// How far a title too long for its place takes to go out...
+pub const TITLE_FADE: f32 = 56.0;
+/// ...and the room it leaves before a tab's close button...
+pub const TAB_TITLE_FADE_GAP: f32 = 6.0;
+/// ...and before a sidebar row's mark, which a name runs right up to.
+pub const SIDEBAR_TITLE_FADE_GAP: f32 = 16.0;
/// Pill: `snapped_rounded_corner_radius` clamps this to half the surface's
/// short side, so the tab keeps semicircular ends at every row height.
pub const WINDOW_TAB_RADIUS: f32 = 999.0;
diff --git a/wezterm-gui/src/thread_marks.rs b/wezterm-gui/src/thread_marks.rs
index 3b8fc6de..cfe415ff 100644
--- a/wezterm-gui/src/thread_marks.rs
+++ b/wezterm-gui/src/thread_marks.rs
@@ -156,6 +156,8 @@ pub(crate) struct IconStyle<'a> {
pub count_metrics: &'a crate::utilsprites::RenderMetrics,
/// "+N" after trailing icons.
pub count_color: LinearRgba,
+ /// How present the icons are, 1 for all the way.
+ pub opacity: f32,
}
/// Draw `icons` in the slot at `x` (see [`slot_width`]) centred on `cy`;
@@ -254,7 +256,8 @@ pub(crate) fn draw_trailing(
}
if let Some(text) = more {
let x = left + d + step * (shown - 1) as f32 + d * 0.15;
- draw_count_text(ctx, layers, &text, x, cy, style.count_color, style)?;
+ let color = style.count_color.mul_alpha(style.opacity);
+ draw_count_text(ctx, layers, &text, x, cy, color, style)?;
}
Ok(left)
}
@@ -274,7 +277,8 @@ fn draw_icon(
ring: f32,
) -> Result<()> {
if ring > 0.0 {
- ctx.draw_disc(layers, LAYER, x + d / 2.0, y + d / 2.0, d + ring * 2.0, style.surface)?;
+ let surface = style.surface.mul_alpha(style.opacity);
+ ctx.draw_disc(layers, LAYER, x + d / 2.0, y + d / 2.0, d + ring * 2.0, surface)?;
}
crate::ui::tile::draw_tile(
ctx,
@@ -284,7 +288,7 @@ fn draw_icon(
y,
d,
d / 2.0,
- icon.circle.linear(),
+ icon.circle.linear().mul_alpha(style.opacity),
style.dark,
&tab_icons::PLATE,
)?;
@@ -298,7 +302,7 @@ fn draw_icon(
x + (d - size) / 2.0,
y + (d - size) / 2.0,
size,
- icon.glyph_color.linear(),
+ icon.glyph_color.linear().mul_alpha(style.opacity),
)?;
}
Ok(())
diff --git a/wezterm-gui/src/ui/draw.rs b/wezterm-gui/src/ui/draw.rs
index 4dcdcefc..114be7b0 100644
--- a/wezterm-gui/src/ui/draw.rs
+++ b/wezterm-gui/src/ui/draw.rs
@@ -22,6 +22,7 @@ use crate::termwindow::render::corners::{
TOP_RIGHT_ROUNDED_CORNER_MASK, TOP_RIGHT_ROUNDED_CORNER_OUTLINE,
};
use crate::termwindow::ui::icons::{BrandIcon, SvgIcon};
+use crate::ui::anim::Easing;
use crate::ui::{UiPalette, UiTokens};
use crate::utilsprites::RenderMetrics;
use std::collections::HashMap;
@@ -1179,6 +1180,34 @@ pub(crate) fn rasterize_disc(key: DiscKey) -> Image {
image
}
+/// Text going out towards its right end: whole up to `from`, and down by
+/// `amount` at `to` and past it. It is held in the glyphs' own colour, not
+/// painted over them, so it reads the same over any ground, a see-through
+/// one too.
+#[derive(Debug, Clone, Copy, PartialEq)]
+pub(crate) struct TextFade {
+ pub(crate) from: f32,
+ pub(crate) to: f32,
+ pub(crate) amount: f32,
+}
+
+impl TextFade {
+ pub(crate) fn alpha_at(&self, x: f32) -> f32 {
+ let through = (x - self.from) / (self.to - self.from).max(1.0);
+ 1.0 - self.amount * Easing::Smooth.apply(through)
+ }
+
+ /// This fade `t` of the way over to where `other` runs.
+ pub(crate) fn towards(self, other: Self, t: f32) -> Self {
+ let mix = |here: f32, there: f32| here + (there - here) * t;
+ Self {
+ from: mix(self.from, other.from),
+ to: mix(self.to, other.to),
+ amount: self.amount,
+ }
+ }
+}
+
/// Whether a glyph that starts at `pos_x` and moves the pen by `advance`
/// fits text that ends at `right_edge`.
///
@@ -1435,9 +1464,84 @@ impl RoundedFramePainter for DrawContext<'_> {
#[cfg(test)]
mod tests {
- use super::{fit_ellipsized, glyph_fits, pixel_snap_rounded_rect, rasterize_disc, DiscKey};
+ use super::{
+ fit_ellipsized, glyph_fits, pixel_snap_rounded_rect, rasterize_disc, DiscKey, TextFade,
+ };
use window::bitmaps::BitmapImage;
+ #[test]
+ fn a_text_fade_leaves_the_start_whole_and_takes_out_the_end() {
+ let fade = TextFade {
+ from: 100.0,
+ to: 140.0,
+ amount: 1.0,
+ };
+ assert_eq!(fade.alpha_at(20.0), 1.0);
+ assert_eq!(fade.alpha_at(100.0), 1.0);
+ assert_eq!(fade.alpha_at(120.0), 0.5);
+ assert_eq!(fade.alpha_at(140.0), 0.0);
+ assert_eq!(fade.alpha_at(300.0), 0.0);
+ let mut last = 1.0;
+ for x in 100..=140 {
+ let alpha = fade.alpha_at(x as f32);
+ assert!(alpha <= last, "brighter again at {x}");
+ last = alpha;
+ }
+ }
+
+ #[test]
+ fn a_text_fade_on_its_way_takes_only_its_share() {
+ let fade = |amount| TextFade {
+ from: 100.0,
+ to: 140.0,
+ amount,
+ };
+ assert_eq!(fade(0.0).alpha_at(300.0), 1.0);
+ assert_eq!(fade(0.25).alpha_at(300.0), 0.75);
+ assert_eq!(fade(0.25).alpha_at(20.0), 1.0);
+ }
+
+ #[test]
+ fn a_text_fade_moves_over_to_another() {
+ let here = TextFade {
+ from: 100.0,
+ to: 140.0,
+ amount: 1.0,
+ };
+ let there = TextFade {
+ from: 60.0,
+ to: 100.0,
+ amount: 0.5,
+ };
+ assert_eq!(here.towards(there, 0.0), here);
+ assert_eq!(
+ here.towards(there, 0.5),
+ TextFade {
+ from: 80.0,
+ to: 120.0,
+ amount: 1.0,
+ }
+ );
+ assert_eq!(
+ here.towards(there, 1.0),
+ TextFade {
+ amount: 1.0,
+ ..there
+ }
+ );
+ }
+
+ #[test]
+ fn a_text_fade_with_no_width_is_still_a_number() {
+ let fade = TextFade {
+ from: 100.0,
+ to: 100.0,
+ amount: 1.0,
+ };
+ assert_eq!(fade.alpha_at(100.0), 1.0);
+ assert_eq!(fade.alpha_at(101.0), 0.0);
+ }
+
#[test]
fn a_disc_is_round_and_its_offset_moves_it() {
let alpha = |key: DiscKey, x: usize, y: usize| {
diff --git a/wezterm-gui/src/workspace_threads.rs b/wezterm-gui/src/workspace_threads.rs
index cfe94066..b82fb646 100644
--- a/wezterm-gui/src/workspace_threads.rs
+++ b/wezterm-gui/src/workspace_threads.rs
@@ -386,6 +386,44 @@ impl WorkspaceThreadsView {
.any(|reference| reference.thread.is_active)
})
}
+
+ /// The first `most` threads on the sidebar's rows, top to bottom: what a
+ /// number reaches. Only rows that are there to click count, so a folded
+ /// folder takes no numbers and a dangling reference, with nothing to
+ /// open, takes none.
+ pub fn first_threads(&self, most: usize) -> Vec<&WorkspaceThreadView> {
+ let mut threads: Vec<&WorkspaceThreadView> = self.pinned_threads.iter().collect();
+ for folder in &self.display_order {
+ if threads.len() >= most {
+ break;
+ }
+ match *folder {
+ SidebarFolder::Project(index) => {
+ if let Some(project) = self
+ .projects
+ .get(index)
+ .filter(|project| !project.threads_collapsed)
+ {
+ threads.extend(project.threads.iter());
+ }
+ }
+ SidebarFolder::RefGroup(index) => {
+ if let Some(group) = self.ref_groups.get(index).filter(|group| !group.collapsed)
+ {
+ threads.extend(
+ group
+ .threads
+ .iter()
+ .filter(|reference| !reference.dangling)
+ .map(|reference| &reference.thread),
+ );
+ }
+ }
+ }
+ }
+ threads.truncate(most);
+ threads
+ }
}
/// One folder-style group of thread references sharing an origin Space.
@@ -13940,6 +13978,90 @@ mod tests {
assert!(store.projects[0].threads[2].work_is_running);
}
+ #[test]
+ fn numbers_count_the_rows_a_click_can_reach() {
+ let ids = |threads: Vec<&WorkspaceThreadView>| {
+ threads
+ .into_iter()
+ .map(|thread| thread.id.clone())
+ .collect::<Vec<_>>()
+ };
+ let thread = |name: &str| WorkspaceThreadView {
+ id: name.to_string(),
+ name: name.to_string(),
+ is_active: false,
+ is_materialized: true,
+ is_pinned: false,
+ is_unread: false,
+ work_status: WorkspaceThreadWorkStatus::Idle,
+ };
+ let project = |id: &str, collapsed: bool, names: &[&str]| ProjectView {
+ id: id.to_string(),
+ name: id.to_string(),
+ is_active: false,
+ threads_collapsed: collapsed,
+ threads: names.iter().map(|name| thread(*name)).collect(),
+ is_remote: false,
+ distro: None,
+ is_archived: false,
+ archived_at: None,
+ };
+ let reference = |name: &str, dangling: bool| ThreadRefView {
+ thread: thread(name),
+ origin_space_id: String::new(),
+ origin_space_name: String::new(),
+ origin_project_id: String::new(),
+ origin_project_name: String::new(),
+ machine_label: String::new(),
+ machine_is_local: true,
+ origin_domain_attached: true,
+ workspace_name: String::new(),
+ dangling,
+ server_folder: false,
+ };
+ let group = |key: &str, collapsed: bool, threads: Vec<ThreadRefView>| ThreadRefGroupView {
+ key: key.to_string(),
+ label: key.to_string(),
+ machine_label: String::new(),
+ machine_is_local: true,
+ origin_space_name: String::new(),
+ attached: true,
+ server_folder: false,
+ collapsed,
+ threads,
+ };
+ let view = WorkspaceThreadsView {
+ pinned_threads: vec![thread("pinned")],
+ projects: vec![
+ project("first", false, &["a", "b"]),
+ project("folded", true, &["unseen"]),
+ project("last", false, &["c"]),
+ ],
+ ref_groups: vec![
+ group(
+ "refs",
+ false,
+ vec![reference("gone", true), reference("kept", false)],
+ ),
+ group("folded-refs", true, vec![reference("unseen-ref", false)]),
+ ],
+ // The sidebar's own order, not the Vecs': references go between
+ // the folders.
+ display_order: vec![
+ SidebarFolder::Project(0),
+ SidebarFolder::RefGroup(0),
+ SidebarFolder::RefGroup(1),
+ SidebarFolder::Project(1),
+ SidebarFolder::Project(2),
+ ],
+ };
+ assert_eq!(
+ ids(view.first_threads(9)),
+ vec!["pinned", "a", "b", "kept", "c"]
+ );
+ assert_eq!(ids(view.first_threads(2)), vec!["pinned", "a"]);
+ }
+
#[test]
fn status_filter_hides_threads_but_never_the_active_one() {
let hidden = [WorkspaceThreadWorkStatus::Idle];