From 2e70ad20df7c2c4839f53a65cceea8616d3abbc1 Mon Sep 17 00:00:00 2001 From: Eduardo Dominguez Date: Fri, 16 Aug 2024 15:25:44 -0600 Subject: [PATCH 1/2] Config: cursor-style can bet set to block_hollow `cursor-style` can now also be set to `block_hollow`, no other changes in behaviour are added. --- src/config/Config.zig | 1 + src/renderer/cursor.zig | 1 + src/terminal/Screen.zig | 2 +- src/termio/stream_handler.zig | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/config/Config.zig b/src/config/Config.zig index ace9c5e4a..4822e1b45 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -325,6 +325,7 @@ palette: Palette = .{}, /// * `block` /// * `bar` /// * `underline` +/// * `block_hollow` /// @"cursor-style": terminal.CursorStyle = .block, diff --git a/src/renderer/cursor.zig b/src/renderer/cursor.zig index 18af9228e..c7667d379 100644 --- a/src/renderer/cursor.zig +++ b/src/renderer/cursor.zig @@ -16,6 +16,7 @@ pub const CursorStyle = enum { return switch (style) { .bar => .bar, .block => .block, + .block_hollow => .block_hollow, .underline => .underline, }; } diff --git a/src/terminal/Screen.zig b/src/terminal/Screen.zig index 620267ad5..8b8941516 100644 --- a/src/terminal/Screen.zig +++ b/src/terminal/Screen.zig @@ -139,7 +139,7 @@ pub const Cursor = struct { /// The visual style of the cursor. Whether or not it blinks /// is determined by mode 12 (modes.zig). This mode is synchronized /// with CSI q, the same as xterm. -pub const CursorStyle = enum { bar, block, underline }; +pub const CursorStyle = enum { bar, block, underline, block_hollow }; /// Saved cursor state. pub const SavedCursor = struct { diff --git a/src/termio/stream_handler.zig b/src/termio/stream_handler.zig index 648efb6fb..16e6d5880 100644 --- a/src/termio/stream_handler.zig +++ b/src/termio/stream_handler.zig @@ -208,6 +208,7 @@ pub const StreamHandler = struct { const blink = self.terminal.modes.get(.cursor_blinking); const style: u8 = switch (self.terminal.screen.cursor.cursor_style) { .block => if (blink) 1 else 2, + .block_hollow => if (blink) 1 else 2, .underline => if (blink) 3 else 4, .bar => if (blink) 5 else 6, }; From 18a8d2b01d730f68c8098467dadd44e6ba97bc15 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 18 Aug 2024 15:01:03 -0700 Subject: [PATCH 2/2] Minor changes, mainly commenting to clarify some behaviors --- src/terminal/Screen.zig | 13 ++++++++++++- src/termio/stream_handler.zig | 5 ++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/terminal/Screen.zig b/src/terminal/Screen.zig index 8b8941516..9d9db4b74 100644 --- a/src/terminal/Screen.zig +++ b/src/terminal/Screen.zig @@ -139,7 +139,18 @@ pub const Cursor = struct { /// The visual style of the cursor. Whether or not it blinks /// is determined by mode 12 (modes.zig). This mode is synchronized /// with CSI q, the same as xterm. -pub const CursorStyle = enum { bar, block, underline, block_hollow }; +pub const CursorStyle = enum { + bar, // DECSCUSR 5, 6 + block, // DECSCUSR 1, 2 + underline, // DECSCUSR 3, 4 + + /// The cursor styles below aren't known by DESCUSR and are custom + /// implemented in Ghostty. They are reported as some standard style + /// if requested, though. + /// Hollow block cursor. This is a block cursor with the center empty. + /// Reported as DECSCUSR 1 or 2 (block). + block_hollow, +}; /// Saved cursor state. pub const SavedCursor = struct { diff --git a/src/termio/stream_handler.zig b/src/termio/stream_handler.zig index 16e6d5880..7daf2b7a2 100644 --- a/src/termio/stream_handler.zig +++ b/src/termio/stream_handler.zig @@ -208,9 +208,12 @@ pub const StreamHandler = struct { const blink = self.terminal.modes.get(.cursor_blinking); const style: u8 = switch (self.terminal.screen.cursor.cursor_style) { .block => if (blink) 1 else 2, - .block_hollow => if (blink) 1 else 2, .underline => if (blink) 3 else 4, .bar => if (blink) 5 else 6, + + // Below here, the cursor styles aren't represented by + // DECSCUSR so we map it to some other style. + .block_hollow => if (blink) 1 else 2, }; try writer.print("{d} q", .{style}); },