Skip to content

Commit 1699d7a

Browse files
feat(config): add default_steady/default_blinking cursor styles
Adds two cursor_style values that only touch shape reset (CSI 0 SP q) and blink mode (CSI ? 12 h/l), instead of selecting one of the fixed DECSCUSR shapes. Some terminals - Windows Terminal among them - offer cursor shapes with no DECSCUSR equivalent (vintage/thick underscore, double underscore, empty box). Existing cursor_style values always override those with block/underline/bar, but default_steady and default_blinking let the terminal profile's own shape stand while still controlling steady vs. blinking. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 6fa38fd commit 1699d7a

4 files changed

Lines changed: 31 additions & 2 deletions

File tree

src/terminal/writer.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ const (
152152
BlinkingBar = "blinking_bar"
153153
SteadyBar = "steady_bar"
154154

155+
// DefaultSteady and DefaultBlinking reset DECSCUSR to the terminal's own
156+
// default shape (CSI 0 SP q) and only toggle blink (CSI ? 12 h/l), so
157+
// terminal-specific shapes DECSCUSR can't select - Windows Terminal's
158+
// vintage, double-underscore and empty-box cursors among them - stay
159+
// under the user's terminal profile setting instead of being overridden.
160+
DefaultSteady = "default_steady"
161+
DefaultBlinking = "default_blinking"
162+
155163
ANCHOR = "ANCHOR"
156164
BG = "BG"
157165
FG = "FG"
@@ -395,6 +403,13 @@ func SetCursorStyle(style string) string {
395403
return ""
396404
}
397405

406+
switch style {
407+
case DefaultSteady:
408+
return fmt.Sprintf(formats.Escape, "\x1b[0 q\x1b[?12l")
409+
case DefaultBlinking:
410+
return fmt.Sprintf(formats.Escape, "\x1b[0 q\x1b[?12h")
411+
}
412+
398413
code, ok := decscusrCodes[style]
399414
if !ok {
400415
return ""

src/terminal/writer_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,18 @@ func TestSetCursorStyle(t *testing.T) {
601601
Style: "not-a-style",
602602
Expected: "",
603603
},
604+
{
605+
Case: "Default steady, generic shell",
606+
Shell: shell.GENERIC,
607+
Style: DefaultSteady,
608+
Expected: "\x1b[0 q\x1b[?12l",
609+
},
610+
{
611+
Case: "Default blinking wrapped for zsh",
612+
Shell: shell.ZSH,
613+
Style: DefaultBlinking,
614+
Expected: "%{\x1b[0 q\x1b[?12h%}",
615+
},
604616
{
605617
Case: "Plain mode renders nothing",
606618
Shell: shell.GENERIC,

themes/schema.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5481,7 +5481,9 @@
54815481
"blinking_underline",
54825482
"steady_underline",
54835483
"blinking_bar",
5484-
"steady_bar"
5484+
"steady_bar",
5485+
"default_steady",
5486+
"default_blinking"
54855487
]
54865488
},
54875489
"enable_cursor_positioning": {

website/docs/configuration/general.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ For example, the following is a valid `--config` flag:
130130
| --------------------------- | ---------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
131131
| `final_space` | `boolean` | | when true adds a space at the end of the prompt |
132132
| `pwd` | `string` | | notify terminal of current working directory, values can be `osc99`, `osc7` or `osc51` depending on your terminal. Supports [templates][templates] |
133-
| `cursor_style` | `string` | | set the cursor's shape/blink state at the start of the prompt using a DECSCUSR sequence, values can be `blinking_block`, `steady_block`, `blinking_underline`, `steady_underline`, `blinking_bar` or `steady_bar`. Supports [templates][templates], e.g. to vary by `.Env.POSH_VI_MODE` (set by the [`vimode`][vimode] segment's shell hooks) |
133+
| `cursor_style` | `string` | | set the cursor's shape/blink state at the start of the prompt using a DECSCUSR sequence, values can be `blinking_block`, `steady_block`, `blinking_underline`, `steady_underline`, `blinking_bar`, `steady_bar`, `default_steady` or `default_blinking` (the latter two only reset shape/blink, leaving terminal-specific cursors like Windows Terminal's vintage, double underscore or empty box shapes as configured in the terminal profile). Supports [templates][templates], e.g. to vary by `.Env.POSH_VI_MODE` (set by the [`vimode`][vimode] segment's shell hooks) |
134134
| `terminal_background` | `string` | | [color][colors] - terminal background color, set to your terminal's background color when you notice black elements in Windows Terminal or the Visual Studio Code integrated terminal |
135135
| `accent_color` | `string` | | [color][colors] - accent color, used as a fallback when the `accent` [color][accent] is not supported |
136136
| `var` | `map[string]any` | | config variables to use in [templates][templates]. Can be any value |

0 commit comments

Comments
 (0)