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.
Rust agentagent-orchestrationaiai-agentsclaude-codecodexcoding-agentlinuxmacosmultiplayermultiplexerrustterminalterminal-emulatorterminal-multiplexertmuxtuiweztermwindows
feat(settings): choose the cursor's shape
RoversXebbc95eb6033
diff --git a/thinkterm-i18n/i18n/de-DE.ftl b/thinkterm-i18n/i18n/de-DE.ftlindex e5fa8fa9..8648b5df 100644--- a/thinkterm-i18n/i18n/de-DE.ftl+++ b/thinkterm-i18n/i18n/de-DE.ftl@@ -263,6 +263,11 @@ settings-cursor-blink-description = „Sanft“ blendet den Cursor mit der eingesettings-cursor-blink-off = Aussettings-cursor-blink-hard = Hartsettings-cursor-blink-smooth = Sanft+settings-cursor-shape = Cursorform+settings-cursor-shape-description = Die übliche Form des Cursors. Legt ein Programm selbst einen Cursorstil fest, gilt dieser.+settings-cursor-shape-block = Block+settings-cursor-shape-bar = Balken+settings-cursor-shape-underline = Unterstrichsettings-overlay-scrollbar = Bildlaufleistesettings-overlay-scrollbar-description = Beim Scrollen erscheint am rechten Rand des Fensterbereichs eine schmale Bildlaufleiste, die danach ausblendet; sie lässt sich ziehen.settings-split-animation = Teilungsanimationdiff --git a/thinkterm-i18n/i18n/en-US.ftl b/thinkterm-i18n/i18n/en-US.ftlindex 1e7d6856..d15e65f2 100644--- a/thinkterm-i18n/i18n/en-US.ftl+++ b/thinkterm-i18n/i18n/en-US.ftl@@ -263,6 +263,11 @@ settings-cursor-blink-description = Smooth eases the cursor in and out with thesettings-cursor-blink-off = Offsettings-cursor-blink-hard = Hardsettings-cursor-blink-smooth = Smooth+settings-cursor-shape = Cursor shape+settings-cursor-shape-description = The cursor's usual shape. A program that sets its own cursor style keeps it.+settings-cursor-shape-block = Block+settings-cursor-shape-bar = Bar+settings-cursor-shape-underline = Underlinesettings-overlay-scrollbar = Scrollbarsettings-overlay-scrollbar-description = A thin scrollbar appears over the right edge of a pane while it scrolls and fades out afterwards; it can be dragged.settings-split-animation = Split animationdiff --git a/thinkterm-i18n/i18n/fr-FR.ftl b/thinkterm-i18n/i18n/fr-FR.ftlindex 18fa0b36..dadab07a 100644--- a/thinkterm-i18n/i18n/fr-FR.ftl+++ b/thinkterm-i18n/i18n/fr-FR.ftl@@ -263,6 +263,11 @@ settings-cursor-blink-description = « Doux » fait apparaître et disparaîtresettings-cursor-blink-off = Désactivésettings-cursor-blink-hard = Netsettings-cursor-blink-smooth = Doux+settings-cursor-shape = Forme du curseur+settings-cursor-shape-description = La forme habituelle du curseur. Un programme qui choisit son propre style de curseur le garde.+settings-cursor-shape-block = Bloc+settings-cursor-shape-bar = Barre+settings-cursor-shape-underline = Soulignementsettings-overlay-scrollbar = Barre de défilementsettings-overlay-scrollbar-description = Une fine barre de défilement apparaît sur le bord droit du volet pendant le défilement puis disparaît en fondu ; elle peut être glissée.settings-split-animation = Animation de divisiondiff --git a/thinkterm-i18n/i18n/ja-JP.ftl b/thinkterm-i18n/i18n/ja-JP.ftlindex 7562b8cf..0884db69 100644--- a/thinkterm-i18n/i18n/ja-JP.ftl+++ b/thinkterm-i18n/i18n/ja-JP.ftl@@ -260,6 +260,11 @@ settings-cursor-blink-description = 「スムーズ」は設定された曲線settings-cursor-blink-off = オフsettings-cursor-blink-hard = ハードsettings-cursor-blink-smooth = スムーズ+settings-cursor-shape = カーソルの形+settings-cursor-shape-description = 通常のカーソルの形です。プログラムが独自のカーソルスタイルを指定している場合はそちらが優先されます。+settings-cursor-shape-block = ブロック+settings-cursor-shape-bar = バー+settings-cursor-shape-underline = 下線settings-overlay-scrollbar = スクロールバーsettings-overlay-scrollbar-description = スクロール中はペインの右端に細いスクロールバーが表示され、その後フェードアウトします。ドラッグもできます。settings-split-animation = 分割アニメーションdiff --git a/thinkterm-i18n/i18n/zh-CN.ftl b/thinkterm-i18n/i18n/zh-CN.ftlindex 7c613547..d8b59abb 100644--- a/thinkterm-i18n/i18n/zh-CN.ftl+++ b/thinkterm-i18n/i18n/zh-CN.ftl@@ -260,6 +260,11 @@ settings-cursor-blink-description = “平滑”按配置的曲线渐入渐出settings-cursor-blink-off = 不闪settings-cursor-blink-hard = 硬闪settings-cursor-blink-smooth = 平滑+settings-cursor-shape = 光标形状+settings-cursor-shape-description = 光标平时的样子。程序自己指定光标样式时,以程序为准。+settings-cursor-shape-block = 方块+settings-cursor-shape-bar = 竖线+settings-cursor-shape-underline = 下划线settings-overlay-scrollbar = 滚动条settings-overlay-scrollbar-description = 滚动时在面板右侧显示一条细滚动条,停止后自动淡出;可以拖动。settings-split-animation = 分屏动画diff --git a/wezterm-gui/src/native_settings.rs b/wezterm-gui/src/native_settings.rsindex eb419177..f9dd1d2f 100644--- a/wezterm-gui/src/native_settings.rs+++ b/wezterm-gui/src/native_settings.rs@@ -388,6 +388,32 @@ impl NativeCursorBlink {pub(crate) const ALL: [Self; 3] = [Self::Off, Self::Smooth, Self::Hard];}+/// The cursor's usual shape.+///+/// `Block` is the default and leaves the shape to the Lua+/// `default_cursor_style`, which is a block unless it says otherwise. `Bar`+/// and `Underline` replace the configured shape and keep its blink. A+/// program that sets its own cursor style still decides, as with+/// [`NativeCursorBlink`].+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Deserialize, Serialize)]+#[serde(rename_all = "snake_case")]+pub(crate) enum NativeCursorShape {+ Block,+ Bar,+ Underline,+}++impl Default for NativeCursorShape {+ fn default() -> Self {+ Self::Block+ }+}++impl NativeCursorShape {+ /// Every choice, in the order the settings window offers them.+ pub(crate) const ALL: [Self; 3] = [Self::Block, Self::Bar, Self::Underline];+}+/// A value this build does not know about must not cost the user the rest of/// their settings, so an unreadable choice reads as the default rather than/// failing the whole file. Same reasoning as `theme_mode_or_default`.@@ -906,6 +932,10 @@ pub(crate) struct NativeTerminalSettings {/// cursor the configuration describes.#[serde(deserialize_with = "choice_or_default")]pub(crate) cursor_blink: NativeCursorBlink,+ /// See [`NativeCursorShape`]. Block is the default, keeping the shape+ /// the configuration describes.+ #[serde(deserialize_with = "choice_or_default")]+ pub(crate) cursor_shape: NativeCursorShape,pub(crate) bottom_quote_enabled: bool,pub(crate) bottom_quote_mode: NativeBottomQuoteMode,pub(crate) bottom_quote_interval_minutes: Option<u32>,@@ -931,6 +961,7 @@ impl Default for NativeTerminalSettings {focus_follows_mouse: false,text_contrast: NativeTextContrast::default(),cursor_blink: NativeCursorBlink::default(),+ cursor_shape: NativeCursorShape::default(),bottom_quote_enabled: false,bottom_quote_mode: NativeBottomQuoteMode::default(),bottom_quote_interval_minutes: None,@@ -1021,6 +1052,12 @@ pub(crate) fn cursor_blinks_by_default() -> bool {load_shared().terminal.cursor_blink != NativeCursorBlink::Off}+/// The cursor shape chosen in Settings. Read alongside `cursor_blink_eases`,+/// not per frame.+pub(crate) fn cursor_shape_choice() -> NativeCursorShape {+ load_shared().terminal.cursor_shape+}+/// Read once per painted pane, through the shared handle.pub(crate) fn overlay_scrollbar() -> bool {load_shared().terminal.overlay_scrollbar@@ -2280,7 +2317,8 @@ fn apply_external_change(before: &ThinkTermNativeSettings, after: &ThinkTermNatilet font_size = (before.terminal.font_size != after.terminal.font_size).then_some(after.terminal.font_size);let contrast = before.terminal.text_contrast != after.terminal.text_contrast;- let cursor_blink = before.terminal.cursor_blink != after.terminal.cursor_blink;+ let cursor_style = before.terminal.cursor_blink != after.terminal.cursor_blink+ || before.terminal.cursor_shape != after.terminal.cursor_shape;let before_chrome = &before.chrome;let after_chrome = &after.chrome;let panels = before_chrome.right_sidebar_files_enabled != after_chrome.right_sidebar_files_enabled@@ -2314,8 +2352,8 @@ fn apply_external_change(before: &ThinkTermNativeSettings, after: &ThinkTermNatiif contrast {term_window.refresh_text_min_contrast();}- if cursor_blink {- term_window.refresh_cursor_blink();+ if cursor_style {+ term_window.refresh_cursor_style();}if panels {term_window.right_sidebar_panels_changed();@@ -3468,6 +3506,29 @@ mod tests {let settings: ThinkTermNativeSettings =serde_json::from_str(json).expect("the file has to survive");assert_eq!(settings.terminal.cursor_blink, NativeCursorBlink::Off);+ assert_eq!(settings.terminal.cursor_shape, NativeCursorShape::Block);+ }++ #[test]+ fn a_cursor_shape_choice_round_trips_through_the_file() {+ for (written, expected) in [+ ("block", NativeCursorShape::Block),+ ("bar", NativeCursorShape::Bar),+ ("underline", NativeCursorShape::Underline),+ ] {+ let json = format!(r#"{{"terminal": {{"cursor_shape": "{written}"}}}}"#);+ let settings: ThinkTermNativeSettings =+ serde_json::from_str(&json).expect("the file has to survive");+ assert_eq!(settings.terminal.cursor_shape, expected, "{written}");++ let out = serde_json::to_string(&settings).expect("serialises");+ assert!(+ out.contains(&format!("\"cursor_shape\":\"{written}\"")),+ "{} has to survive a save: {}",+ written,+ out+ );+ }}#[test]diff --git a/wezterm-gui/src/settings_window.rs b/wezterm-gui/src/settings_window.rsindex f33f2745..7303dc53 100644--- a/wezterm-gui/src/settings_window.rs+++ b/wezterm-gui/src/settings_window.rs@@ -1213,6 +1213,10 @@ impl SettingsSection {"Selection","Split Animation","Animation",+ "Cursor",+ "Cursor Shape",+ "Cursor Blink",+ "Blink","Terminal",],Self::Workspaces => &[@@ -1397,6 +1401,8 @@ impl SettingsSection {"settings-copy-effect","settings-focus-follows-mouse","settings-split-animation",+ "settings-cursor-shape",+ "settings-cursor-blink",].iter().any(|id| crate::i18n::tr(id).to_lowercase().contains(query)))@@ -1780,6 +1786,15 @@ fn localized_text_contrast_label(mode: crate::native_settings::NativeTextContras})}+fn localized_cursor_shape_label(shape: crate::native_settings::NativeCursorShape) -> String {+ use crate::native_settings::NativeCursorShape;+ crate::i18n::tr(match shape {+ NativeCursorShape::Block => "settings-cursor-shape-block",+ NativeCursorShape::Bar => "settings-cursor-shape-bar",+ NativeCursorShape::Underline => "settings-cursor-shape-underline",+ })+}+fn localized_cursor_blink_label(mode: crate::native_settings::NativeCursorBlink) -> String {use crate::native_settings::NativeCursorBlink;crate::i18n::tr(match mode {@@ -2094,6 +2109,7 @@ enum SettingsAction {OpenColorSchemePicker,SetTextContrast(crate::native_settings::NativeTextContrast),SetCursorBlink(crate::native_settings::NativeCursorBlink),+ SetCursorShape(crate::native_settings::NativeCursorShape),ToggleOverlayScrollbar,ToggleSplitAnimation,SetBottomQuoteMode(NativeBottomQuoteMode),@@ -5609,12 +5625,31 @@ impl SettingsWindow {}fn apply_cursor_blink(&mut self, mode: crate::native_settings::NativeCursorBlink) {- self.ui.open_dropdown = None;- // Merge into the freshest settings for the reason `apply_text_contrast`- // gives: another row may have written the file while this window was- // open.let mut merged = crate::native_settings::load();merged.terminal.cursor_blink = mode;+ self.save_cursor_style(merged, "settings-cursor-blink", localized_cursor_blink_label(mode));+ }++ fn apply_cursor_shape(&mut self, shape: crate::native_settings::NativeCursorShape) {+ let mut merged = crate::native_settings::load();+ merged.terminal.cursor_shape = shape;+ self.save_cursor_style(+ merged,+ "settings-cursor-shape",+ localized_cursor_shape_label(shape),+ );+ }++ /// Save a cursor blink or shape choice, made on settings merged from the+ /// freshest file for the reason `apply_text_contrast` gives: another row+ /// may have written it while this window was open.+ fn save_cursor_style(+ &mut self,+ merged: crate::native_settings::ThinkTermNativeSettings,+ setting: &str,+ value: String,+ ) {+ self.ui.open_dropdown = None;self.set_native_settings(merged);match crate::native_settings::save(&self.native_settings) {Ok(()) => {@@ -5624,17 +5659,14 @@ impl SettingsWindow {for gui_window in front_end.gui_windows() {gui_window.window.notify(crate::termwindow::TermWindowNotif::Apply(Box::new(|term_window| {- term_window.refresh_cursor_blink();+ term_window.refresh_cursor_style();})),);}}self.status = settings_tr("settings-status-value-now",- &[- ("setting", crate::i18n::tr("settings-cursor-blink")),- ("value", localized_cursor_blink_label(mode)),- ],+ &[("setting", crate::i18n::tr(setting)), ("value", value)],);}Err(err) => {@@ -6715,6 +6747,7 @@ impl SettingsWindow {SettingsAction::WindowOpacitySlider => {}SettingsAction::SetTextContrast(mode) => self.apply_text_contrast(mode),SettingsAction::SetCursorBlink(mode) => self.apply_cursor_blink(mode),+ SettingsAction::SetCursorShape(shape) => self.apply_cursor_shape(shape),SettingsAction::SetRemotePaneResizeMode(mode) => {self.apply_remote_pane_resize_mode(mode)}@@ -13638,7 +13671,7 @@ impl SettingsWindow {)?;let bottom = self.paint_card(layers, x, card_y, max_width, |this, layers, top| {use crate::native_settings::{- NativeCursorBlink, NativeScrollMode, NativeTextContrast,+ NativeCursorBlink, NativeCursorShape, NativeScrollMode, NativeTextContrast,};let mut rows = RowCursor::new(top, this);@@ -13748,6 +13781,39 @@ impl SettingsWindow {rows.rule(),)?);+ let options: Vec<(String, SettingsAction)> = NativeCursorShape::ALL+ .iter()+ .map(|shape| {+ (+ localized_cursor_shape_label(*shape),+ SettingsAction::SetCursorShape(*shape),+ )+ })+ .collect();+ let selected = NativeCursorShape::ALL+ .iter()+ .position(|shape| *shape == this.native_settings.terminal.cursor_shape)+ .unwrap_or(0);+ let (tx, tw) = this.paint_row_tile(+ layers,+ row_x,+ rows.y,+ row_width,+ SvgIcon::Square,+ TileColor::Indigo,+ )?;+ rows.add(this.paint_segmented_setting_row(+ layers,+ tx,+ rows.y,+ tw,+ &crate::i18n::tr("settings-cursor-shape"),+ &crate::i18n::tr("settings-cursor-shape-description"),+ &options,+ selected,+ rows.rule(),+ )?);+let options: Vec<(String, SettingsAction)> = NativeCursorBlink::ALL.iter().map(|mode| {diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rsindex e971849a..0c887881 100644--- a/wezterm-gui/src/termwindow/mod.rs+++ b/wezterm-gui/src/termwindow/mod.rs@@ -3087,6 +3087,9 @@ pub struct TermWindow {/// Settings' cursor blink is Smooth or Hard, so a cursor in the default/// style blinks. Rebuilt with `cursor_blink_state`.cursor_blinks_by_default: bool,+ /// The cursor shape chosen in Settings, for a cursor in the default+ /// style. Rebuilt with `cursor_blink_state`.+ cursor_shape_choice: crate::native_settings::NativeCursorShape,blink_state: RefCell<ColorEase>,rapid_blink_state: RefCell<ColorEase>,@@ -5020,6 +5023,7 @@ impl TermWindow {None,)),cursor_blinks_by_default: crate::native_settings::cursor_blinks_by_default(),+ cursor_shape_choice: crate::native_settings::cursor_shape_choice(),blink_state: RefCell::new(ColorEase::new(config.text_blink_rate,config.text_blink_ease_in,@@ -7768,11 +7772,11 @@ impl TermWindow {self.invalidate_window();}- /// Rebuild the cursor's blink state from the style chosen in Settings.- /// `config_was_reloaded` does this too; this is the direct route, for the- /// settings window, which writes the choice to its own file and never- /// touches the configuration.- pub(crate) fn refresh_cursor_blink(&mut self) {+ /// Rebuild the cursor's blink state and shape from the style chosen in+ /// Settings. `config_was_reloaded` does this too; this is the direct+ /// route, for the settings window, which writes the choice to its own+ /// file and never touches the configuration.+ pub(crate) fn refresh_cursor_style(&mut self) {let (ease_in, ease_out) = crate::native_settings::cursor_blink_eases(&self.config);*self.cursor_blink_state.borrow_mut() = ColorEase::new(self.config.cursor_blink_rate,@@ -7782,6 +7786,7 @@ impl TermWindow {None,);self.cursor_blinks_by_default = crate::native_settings::cursor_blinks_by_default();+ self.cursor_shape_choice = crate::native_settings::cursor_shape_choice();self.invalidate_window();}@@ -8064,6 +8069,7 @@ impl TermWindow {None,);self.cursor_blinks_by_default = crate::native_settings::cursor_blinks_by_default();+ self.cursor_shape_choice = crate::native_settings::cursor_shape_choice();*self.blink_state.borrow_mut() = ColorEase::new(config.text_blink_rate,config.text_blink_ease_in,diff --git a/wezterm-gui/src/termwindow/render/mod.rs b/wezterm-gui/src/termwindow/render/mod.rsindex bfc82ad8..c5ab01d6 100644--- a/wezterm-gui/src/termwindow/render/mod.rs+++ b/wezterm-gui/src/termwindow/render/mod.rs@@ -896,17 +896,29 @@ impl crate::TermWindow {}/// The shape a cursor is drawn with. A program that set its own style- /// keeps it; the default style blinks when Settings asks for a blink.+ /// keeps it; the default style takes the shape chosen in Settings, and+ /// blinks when Settings or the configuration asks for a blink.fn effective_cursor_shape(default_style: config::DefaultCursorStyle,shape: CursorShape,+ chosen_shape: crate::native_settings::NativeCursorShape,blinks_by_default: bool,) -> CursorShape {- let effective = default_style.effective_shape(shape);- if shape != CursorShape::Default || !blinks_by_default {- return effective;+ use crate::native_settings::NativeCursorShape;++ let configured = default_style.effective_shape(shape);+ if shape != CursorShape::Default {+ return configured;+ }+ let shape = match chosen_shape {+ NativeCursorShape::Block => configured,+ NativeCursorShape::Bar => CursorShape::SteadyBar,+ NativeCursorShape::Underline => CursorShape::SteadyUnderline,+ };+ if !blinks_by_default && !configured.is_blinking() {+ return shape;}- match effective {+ match shape {CursorShape::SteadyBlock => CursorShape::BlinkingBlock,CursorShape::SteadyUnderline => CursorShape::BlinkingUnderline,CursorShape::SteadyBar => CursorShape::BlinkingBar,@@ -1002,6 +1014,7 @@ impl crate::TermWindow {Self::effective_cursor_shape(params.config.default_cursor_style,cursor.shape,+ self.cursor_shape_choice,self.cursor_blinks_by_default,),cursor.visibility,@@ -1794,10 +1807,15 @@ mod cursor_colour_tests {mod cursor_blink_tests {use crate::TermWindow;use config::DefaultCursorStyle;+ use crate::native_settings::NativeCursorShape;use termwiz::surface::CursorShape;fn shape(style: DefaultCursorStyle, asked: CursorShape, blinks: bool) -> CursorShape {- TermWindow::effective_cursor_shape(style, asked, blinks)+ TermWindow::effective_cursor_shape(style, asked, NativeCursorShape::Block, blinks)+ }++ fn chosen(style: DefaultCursorStyle, pick: NativeCursorShape, blinks: bool) -> CursorShape {+ TermWindow::effective_cursor_shape(style, CursorShape::Default, pick, blinks)}/// With the setting off the cursor is exactly what the configuration@@ -1833,5 +1851,40 @@ mod cursor_blink_tests {shape(DefaultCursorStyle::SteadyBlock, CursorShape::SteadyBar, true),CursorShape::SteadyBar);+ assert_eq!(+ TermWindow::effective_cursor_shape(+ DefaultCursorStyle::SteadyBlock,+ CursorShape::SteadyBlock,+ NativeCursorShape::Bar,+ false,+ ),+ CursorShape::SteadyBlock+ );+ }++ #[test]+ fn a_chosen_shape_replaces_the_default_one() {+ assert_eq!(+ chosen(DefaultCursorStyle::SteadyBlock, NativeCursorShape::Bar, false),+ CursorShape::SteadyBar+ );+ assert_eq!(+ chosen(DefaultCursorStyle::SteadyBlock, NativeCursorShape::Underline, true),+ CursorShape::BlinkingUnderline+ );+ }++ /// Block leaves the configured shape alone; another shape keeps the+ /// blink the configuration asked for.+ #[test]+ fn the_configuration_s_shape_and_blink_survive_where_they_can() {+ assert_eq!(+ chosen(DefaultCursorStyle::SteadyUnderline, NativeCursorShape::Block, false),+ CursorShape::SteadyUnderline+ );+ assert_eq!(+ chosen(DefaultCursorStyle::BlinkingBlock, NativeCursorShape::Bar, false),+ CursorShape::BlinkingBar+ );}}