mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
Support changing the cursor style for unfocused windows
This commit is contained in:
@ -442,6 +442,10 @@ palette: Palette = .{},
|
|||||||
///
|
///
|
||||||
@"cursor-style": terminal.CursorStyle = .block,
|
@"cursor-style": terminal.CursorStyle = .block,
|
||||||
|
|
||||||
|
/// The style of the cursor when the window is not focused. All valid values
|
||||||
|
/// supported by `cursor-style` are accepted here as well.
|
||||||
|
@"cursor-style-unfocused": terminal.CursorStyle = .block_hollow,
|
||||||
|
|
||||||
/// Sets the default blinking state of the cursor. This is just the default
|
/// Sets the default blinking state of the cursor. This is just the default
|
||||||
/// state; running programs may override the cursor style using `DECSCUSR` (`CSI
|
/// state; running programs may override the cursor style using `DECSCUSR` (`CSI
|
||||||
/// q`).
|
/// q`).
|
||||||
|
@ -53,7 +53,7 @@ pub fn style(
|
|||||||
|
|
||||||
// If we're not focused, our cursor is always visible so that
|
// If we're not focused, our cursor is always visible so that
|
||||||
// we can show the hollow box.
|
// we can show the hollow box.
|
||||||
if (!focused) return .block_hollow;
|
if (!focused) return Style.fromTerminal(state.terminal.screen.cursor.cursor_style_unfocused);
|
||||||
|
|
||||||
// If the cursor is blinking and our blink state is not visible,
|
// If the cursor is blinking and our blink state is not visible,
|
||||||
// then we don't show the cursor.
|
// then we don't show the cursor.
|
||||||
@ -72,6 +72,7 @@ test "cursor: default uses configured style" {
|
|||||||
defer term.deinit(alloc);
|
defer term.deinit(alloc);
|
||||||
|
|
||||||
term.screen.cursor.cursor_style = .bar;
|
term.screen.cursor.cursor_style = .bar;
|
||||||
|
term.screen.cursor.cursor_style_unfocused = .underline;
|
||||||
term.modes.set(.cursor_blinking, true);
|
term.modes.set(.cursor_blinking, true);
|
||||||
|
|
||||||
var state: State = .{
|
var state: State = .{
|
||||||
@ -81,8 +82,8 @@ test "cursor: default uses configured style" {
|
|||||||
};
|
};
|
||||||
|
|
||||||
try testing.expect(style(&state, true, true) == .bar);
|
try testing.expect(style(&state, true, true) == .bar);
|
||||||
try testing.expect(style(&state, false, true) == .block_hollow);
|
try testing.expect(style(&state, false, true) == .underline);
|
||||||
try testing.expect(style(&state, false, false) == .block_hollow);
|
try testing.expect(style(&state, false, false) == .underline);
|
||||||
try testing.expect(style(&state, true, false) == null);
|
try testing.expect(style(&state, true, false) == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,6 +91,9 @@ pub const Cursor = struct {
|
|||||||
/// encouraged to set their own default.
|
/// encouraged to set their own default.
|
||||||
cursor_style: CursorStyle = .block,
|
cursor_style: CursorStyle = .block,
|
||||||
|
|
||||||
|
/// The visual style of the cursor when the window is not focused.
|
||||||
|
cursor_style_unfocused: CursorStyle = .block_hollow,
|
||||||
|
|
||||||
/// The "last column flag (LCF)" as its called. If this is set then the
|
/// The "last column flag (LCF)" as its called. If this is set then the
|
||||||
/// next character print will force a soft-wrap.
|
/// next character print will force a soft-wrap.
|
||||||
pending_wrap: bool = false,
|
pending_wrap: bool = false,
|
||||||
|
@ -79,6 +79,7 @@ pub const DerivedConfig = struct {
|
|||||||
palette: terminal.color.Palette,
|
palette: terminal.color.Palette,
|
||||||
image_storage_limit: usize,
|
image_storage_limit: usize,
|
||||||
cursor_style: terminal.CursorStyle,
|
cursor_style: terminal.CursorStyle,
|
||||||
|
cursor_style_unfocused: terminal.CursorStyle,
|
||||||
cursor_blink: ?bool,
|
cursor_blink: ?bool,
|
||||||
cursor_color: ?configpkg.Config.Color,
|
cursor_color: ?configpkg.Config.Color,
|
||||||
cursor_invert: bool,
|
cursor_invert: bool,
|
||||||
@ -101,6 +102,7 @@ pub const DerivedConfig = struct {
|
|||||||
.palette = config.palette.value,
|
.palette = config.palette.value,
|
||||||
.image_storage_limit = config.@"image-storage-limit",
|
.image_storage_limit = config.@"image-storage-limit",
|
||||||
.cursor_style = config.@"cursor-style",
|
.cursor_style = config.@"cursor-style",
|
||||||
|
.cursor_style_unfocused = config.@"cursor-style-unfocused",
|
||||||
.cursor_blink = config.@"cursor-style-blink",
|
.cursor_blink = config.@"cursor-style-blink",
|
||||||
.cursor_color = config.@"cursor-color",
|
.cursor_color = config.@"cursor-color",
|
||||||
.cursor_invert = config.@"cursor-invert-fg-bg",
|
.cursor_invert = config.@"cursor-invert-fg-bg",
|
||||||
@ -167,6 +169,7 @@ pub fn init(self: *Termio, alloc: Allocator, opts: termio.Options) !void {
|
|||||||
|
|
||||||
// Set our default cursor style
|
// Set our default cursor style
|
||||||
term.screen.cursor.cursor_style = opts.config.cursor_style;
|
term.screen.cursor.cursor_style = opts.config.cursor_style;
|
||||||
|
term.screen.cursor.cursor_style_unfocused = opts.config.cursor_style_unfocused;
|
||||||
|
|
||||||
// Setup our terminal size in pixels for certain requests.
|
// Setup our terminal size in pixels for certain requests.
|
||||||
term.width_px = term.cols * opts.size.cell.width;
|
term.width_px = term.cols * opts.size.cell.width;
|
||||||
|
Reference in New Issue
Block a user