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(settings): keep the cursor steady unless blinking is chosen

RoversX27e2e47e0a5a
diff --git a/thinkterm-i18n/i18n/de-DE.ftl b/thinkterm-i18n/i18n/de-DE.ftl
index e761d0b7..e5fa8fa9 100644
--- a/thinkterm-i18n/i18n/de-DE.ftl
+++ b/thinkterm-i18n/i18n/de-DE.ftl
@@ -259,7 +259,8 @@ settings-text-contrast-3 = 3:1
settings-text-contrast-45 = 4.5:1
settings-text-contrast-7 = 7:1
settings-cursor-blink = Cursor-Blinken
-settings-cursor-blink-description = „Hart“ schaltet den Cursor direkt ein und aus; „Sanft“ blendet ihn mit der eingestellten Kurve ein und aus.
+settings-cursor-blink-description = „Sanft“ blendet den Cursor mit der eingestellten Kurve ein und aus; „Hart“ schaltet ihn direkt ein und aus. Legt ein Programm selbst einen Cursorstil fest, gilt dieser.
+settings-cursor-blink-off = Aus
settings-cursor-blink-hard = Hart
settings-cursor-blink-smooth = Sanft
settings-overlay-scrollbar = Bildlaufleiste
diff --git a/thinkterm-i18n/i18n/en-US.ftl b/thinkterm-i18n/i18n/en-US.ftl
index bc791636..1e7d6856 100644
--- a/thinkterm-i18n/i18n/en-US.ftl
+++ b/thinkterm-i18n/i18n/en-US.ftl
@@ -259,7 +259,8 @@ settings-text-contrast-3 = 3:1
settings-text-contrast-45 = 4.5:1
settings-text-contrast-7 = 7:1
settings-cursor-blink = Cursor blink
-settings-cursor-blink-description = Hard switches the cursor between fully on and fully off; Smooth eases it in and out with the configured curve.
+settings-cursor-blink-description = Smooth eases the cursor in and out with the configured curve; Hard switches it between fully on and fully off. A program that sets its own cursor style keeps it.
+settings-cursor-blink-off = Off
settings-cursor-blink-hard = Hard
settings-cursor-blink-smooth = Smooth
settings-overlay-scrollbar = Scrollbar
diff --git a/thinkterm-i18n/i18n/fr-FR.ftl b/thinkterm-i18n/i18n/fr-FR.ftl
index 26d2000f..18fa0b36 100644
--- a/thinkterm-i18n/i18n/fr-FR.ftl
+++ b/thinkterm-i18n/i18n/fr-FR.ftl
@@ -259,7 +259,8 @@ settings-text-contrast-3 = 3:1
settings-text-contrast-45 = 4.5:1
settings-text-contrast-7 = 7:1
settings-cursor-blink = Clignotement du curseur
-settings-cursor-blink-description = « Net » allume et éteint le curseur d'un coup ; « Doux » le fait apparaître et disparaître avec la courbe configurée.
+settings-cursor-blink-description = « Doux » fait apparaître et disparaître le curseur avec la courbe configurée ; « Net » l'allume et l'éteint d'un coup. Un programme qui choisit son propre style de curseur le garde.
+settings-cursor-blink-off = Désactivé
settings-cursor-blink-hard = Net
settings-cursor-blink-smooth = Doux
settings-overlay-scrollbar = Barre de défilement
diff --git a/thinkterm-i18n/i18n/ja-JP.ftl b/thinkterm-i18n/i18n/ja-JP.ftl
index 5447091a..7562b8cf 100644
--- a/thinkterm-i18n/i18n/ja-JP.ftl
+++ b/thinkterm-i18n/i18n/ja-JP.ftl
@@ -256,7 +256,8 @@ settings-text-contrast-3 = 3:1
settings-text-contrast-45 = 4.5:1
settings-text-contrast-7 = 7:1
settings-cursor-blink = カーソルの点滅
-settings-cursor-blink-description = 「ハード」はカーソルをそのまま点けたり消したりします。「スムーズ」は設定された曲線で徐々に表示・非表示にします。
+settings-cursor-blink-description = 「スムーズ」は設定された曲線で徐々に表示・非表示にし、「ハード」はカーソルをそのまま点けたり消したりします。プログラムが独自のカーソルスタイルを指定している場合はそちらが優先されます。
+settings-cursor-blink-off = オフ
settings-cursor-blink-hard = ハード
settings-cursor-blink-smooth = スムーズ
settings-overlay-scrollbar = スクロールバー
diff --git a/thinkterm-i18n/i18n/zh-CN.ftl b/thinkterm-i18n/i18n/zh-CN.ftl
index 724f506d..7c613547 100644
--- a/thinkterm-i18n/i18n/zh-CN.ftl
+++ b/thinkterm-i18n/i18n/zh-CN.ftl
@@ -256,7 +256,8 @@ settings-text-contrast-3 = 3:1
settings-text-contrast-45 = 4.5:1
settings-text-contrast-7 = 7:1
settings-cursor-blink = 光标闪烁
-settings-cursor-blink-description = “硬闪”让光标直接亮灭;“平滑”按配置的曲线渐入渐出。
+settings-cursor-blink-description = “平滑”按配置的曲线渐入渐出;“硬闪”让光标直接亮灭。程序自己指定光标样式时,以程序为准。
+settings-cursor-blink-off = 不闪
settings-cursor-blink-hard = 硬闪
settings-cursor-blink-smooth = 平滑
settings-overlay-scrollbar = 滚动条
diff --git a/wezterm-gui/src/native_settings.rs b/wezterm-gui/src/native_settings.rs
index 650e8e23..eb419177 100644
--- a/wezterm-gui/src/native_settings.rs
+++ b/wezterm-gui/src/native_settings.rs
@@ -362,27 +362,30 @@ impl NativeTextContrast {
/// How the cursor blinks.
///
-/// `Hard` switches it between fully on and fully off, as Apple's Terminal
-/// does; `Smooth` eases it in and out, as the Lua
-/// `cursor_blink_ease_in`/`cursor_blink_ease_out` settings describe. Smooth
-/// stays the default so the configuration keeps deciding; Hard is there for
-/// the classic on/off cursor.
+/// `Off` is the default and leaves the cursor as the configuration has it:
+/// steady, unless the Lua `default_cursor_style` or the running program asks
+/// for a blink. `Smooth` and `Hard` make the default cursor blink; a program
+/// that sets its own cursor style still decides. `Smooth` eases it in and
+/// out, as the Lua `cursor_blink_ease_in`/`cursor_blink_ease_out` settings
+/// describe; `Hard` switches it between fully on and fully off, as Apple's
+/// Terminal does.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Deserialize, Serialize)]
#[serde(rename_all = "snake_case")]
pub(crate) enum NativeCursorBlink {
+ Off,
Hard,
Smooth,
}
impl Default for NativeCursorBlink {
fn default() -> Self {
- Self::Smooth
+ Self::Off
}
}
impl NativeCursorBlink {
/// Every choice, in the order the settings window offers them.
- pub(crate) const ALL: [Self; 2] = [Self::Smooth, Self::Hard];
+ pub(crate) const ALL: [Self; 3] = [Self::Off, Self::Smooth, Self::Hard];
}
/// A value this build does not know about must not cost the user the rest of
@@ -899,8 +902,8 @@ pub(crate) struct NativeTerminalSettings {
/// `text_min_contrast_ratio`, which is itself off unless set.
#[serde(deserialize_with = "text_contrast_or_default")]
pub(crate) text_contrast: NativeTextContrast,
- /// See [`NativeCursorBlink`]. Smooth is the default, preserving the
- /// eased cursor the Lua settings describe.
+ /// See [`NativeCursorBlink`]. Off is the default, keeping the steady
+ /// cursor the configuration describes.
#[serde(deserialize_with = "choice_or_default")]
pub(crate) cursor_blink: NativeCursorBlink,
pub(crate) bottom_quote_enabled: bool,
@@ -993,10 +996,11 @@ pub(crate) fn text_min_contrast_ratio(config: &ConfigHandle) -> Option<f32> {
/// The easing pair the cursor's `ColorEase` should use.
///
-/// `Hard` overrides the Lua easing entirely; `Smooth` leaves it in charge,
-/// so a configuration that named `EaseIn`, `EaseInOut` or `Linear` keeps the
-/// function it asked for. Read when the state is built and when the setting
-/// changes, not per frame.
+/// `Hard` overrides the Lua easing entirely; `Off` and `Smooth` leave it in
+/// charge, so a configuration that named `EaseIn`, `EaseInOut` or `Linear`
+/// keeps the function it asked for, and a program that asks for a blinking
+/// cursor while the setting is off blinks as it always has. Read when the
+/// state is built and when the setting changes, not per frame.
pub(crate) fn cursor_blink_eases(
config: &ConfigHandle,
) -> (config::EasingFunction, config::EasingFunction) {
@@ -1005,10 +1009,18 @@ pub(crate) fn cursor_blink_eases(
config::EasingFunction::Constant,
config::EasingFunction::Constant,
),
- NativeCursorBlink::Smooth => (config.cursor_blink_ease_in, config.cursor_blink_ease_out),
+ NativeCursorBlink::Off | NativeCursorBlink::Smooth => {
+ (config.cursor_blink_ease_in, config.cursor_blink_ease_out)
+ }
}
}
+/// Whether the default cursor blinks: Settings chose Smooth or Hard. Read
+/// alongside `cursor_blink_eases`, not per frame.
+pub(crate) fn cursor_blinks_by_default() -> bool {
+ load_shared().terminal.cursor_blink != NativeCursorBlink::Off
+}
+
/// Read once per painted pane, through the shared handle.
pub(crate) fn overlay_scrollbar() -> bool {
load_shared().terminal.overlay_scrollbar
@@ -3445,22 +3457,23 @@ mod tests {
}
}
- /// A file written before this setting existed keeps the eased cursor the
- /// Lua defaults describe rather than silently changing its blink.
+ /// A file written before this setting existed keeps the steady cursor the
+ /// Lua defaults describe rather than silently starting to blink.
#[test]
- fn a_settings_file_without_a_blink_choice_reads_as_smooth() {
+ fn a_settings_file_without_a_blink_choice_reads_as_off() {
let json = r#"{
"version": 1,
"terminal": { "scroll_mode": "smooth" }
}"#;
let settings: ThinkTermNativeSettings =
serde_json::from_str(json).expect("the file has to survive");
- assert_eq!(settings.terminal.cursor_blink, NativeCursorBlink::Smooth);
+ assert_eq!(settings.terminal.cursor_blink, NativeCursorBlink::Off);
}
#[test]
fn a_blink_choice_round_trips_through_the_file() {
for (written, expected) in [
+ ("off", NativeCursorBlink::Off),
("hard", NativeCursorBlink::Hard),
("smooth", NativeCursorBlink::Smooth),
] {
@@ -3472,7 +3485,9 @@ mod tests {
let out = serde_json::to_string(&settings).expect("serialises");
assert!(
out.contains(&format!("\"cursor_blink\":\"{written}\"")),
- "{written} has to survive a save: {out}"
+ "{} has to survive a save: {}",
+ written,
+ out
);
}
}
diff --git a/wezterm-gui/src/settings_window.rs b/wezterm-gui/src/settings_window.rs
index a364f1b6..f33f2745 100644
--- a/wezterm-gui/src/settings_window.rs
+++ b/wezterm-gui/src/settings_window.rs
@@ -1783,6 +1783,7 @@ fn localized_text_contrast_label(mode: crate::native_settings::NativeTextContras
fn localized_cursor_blink_label(mode: crate::native_settings::NativeCursorBlink) -> String {
use crate::native_settings::NativeCursorBlink;
crate::i18n::tr(match mode {
+ NativeCursorBlink::Off => "settings-cursor-blink-off",
NativeCursorBlink::Hard => "settings-cursor-blink-hard",
NativeCursorBlink::Smooth => "settings-cursor-blink-smooth",
})
diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs
index f9298268..e971849a 100644
--- a/wezterm-gui/src/termwindow/mod.rs
+++ b/wezterm-gui/src/termwindow/mod.rs
@@ -3084,6 +3084,9 @@ pub struct TermWindow {
/// Throttle for `log_gpu_allocator_throttled`; runtime-only diagnostics.
last_gpu_allocator_log: Cell<Option<Instant>>,
cursor_blink_state: RefCell<ColorEase>,
+ /// 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,
blink_state: RefCell<ColorEase>,
rapid_blink_state: RefCell<ColorEase>,
@@ -5016,6 +5019,7 @@ impl TermWindow {
cursor_blink_ease_out,
None,
)),
+ cursor_blinks_by_default: crate::native_settings::cursor_blinks_by_default(),
blink_state: RefCell::new(ColorEase::new(
config.text_blink_rate,
config.text_blink_ease_in,
@@ -7777,6 +7781,7 @@ impl TermWindow {
ease_out,
None,
);
+ self.cursor_blinks_by_default = crate::native_settings::cursor_blinks_by_default();
self.invalidate_window();
}
@@ -8058,6 +8063,7 @@ impl TermWindow {
cursor_blink_ease_out,
None,
);
+ self.cursor_blinks_by_default = crate::native_settings::cursor_blinks_by_default();
*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.rs
index 9e7da818..e769fa37 100644
--- a/wezterm-gui/src/termwindow/render/mod.rs
+++ b/wezterm-gui/src/termwindow/render/mod.rs
@@ -891,6 +891,25 @@ 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.
+ fn effective_cursor_shape(
+ default_style: config::DefaultCursorStyle,
+ shape: CursorShape,
+ blinks_by_default: bool,
+ ) -> CursorShape {
+ let effective = default_style.effective_shape(shape);
+ if shape != CursorShape::Default || !blinks_by_default {
+ return effective;
+ }
+ match effective {
+ CursorShape::SteadyBlock => CursorShape::BlinkingBlock,
+ CursorShape::SteadyUnderline => CursorShape::BlinkingUnderline,
+ CursorShape::SteadyBar => CursorShape::BlinkingBar,
+ other => other,
+ }
+ }
+
pub fn compute_cell_fg_bg(&self, params: ComputeCellFgBgParams) -> ComputeCellFgBgResult {
let focused_and_active =
self.focused.is_some() && params.is_active_pane && !self.right_sidebar_has_text_focus();
@@ -976,10 +995,11 @@ impl crate::TermWindow {
let (cursor_shape, visibility) = match params.cursor {
Some(cursor) => (
- params
- .config
- .default_cursor_style
- .effective_shape(cursor.shape),
+ Self::effective_cursor_shape(
+ params.config.default_cursor_style,
+ cursor.shape,
+ self.cursor_blinks_by_default,
+ ),
cursor.visibility,
),
_ => (CursorShape::default(), CursorVisibility::Hidden),
@@ -1749,3 +1769,49 @@ mod cursor_colour_tests {
);
}
}
+
+#[cfg(test)]
+mod cursor_blink_tests {
+ use crate::TermWindow;
+ use config::DefaultCursorStyle;
+ use termwiz::surface::CursorShape;
+
+ fn shape(style: DefaultCursorStyle, asked: CursorShape, blinks: bool) -> CursorShape {
+ TermWindow::effective_cursor_shape(style, asked, blinks)
+ }
+
+ /// With the setting off the cursor is exactly what the configuration
+ /// says, including a blink it asked for itself.
+ #[test]
+ fn off_leaves_the_configured_cursor_alone() {
+ assert_eq!(
+ shape(DefaultCursorStyle::SteadyBlock, CursorShape::Default, false),
+ CursorShape::SteadyBlock
+ );
+ assert_eq!(
+ shape(DefaultCursorStyle::BlinkingBar, CursorShape::Default, false),
+ CursorShape::BlinkingBar
+ );
+ }
+
+ #[test]
+ fn the_default_cursor_blinks_when_settings_ask() {
+ assert_eq!(
+ shape(DefaultCursorStyle::SteadyBlock, CursorShape::Default, true),
+ CursorShape::BlinkingBlock
+ );
+ assert_eq!(
+ shape(DefaultCursorStyle::SteadyBar, CursorShape::Default, true),
+ CursorShape::BlinkingBar
+ );
+ }
+
+ /// A program that chose a steady cursor keeps it.
+ #[test]
+ fn a_program_s_own_cursor_style_wins() {
+ assert_eq!(
+ shape(DefaultCursorStyle::SteadyBlock, CursorShape::SteadyBar, true),
+ CursorShape::SteadyBar
+ );
+ }
+}