mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2026-08-24 02:34:19 -05:00
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>
This commit is contained in:
committed by
Jan De Dobbeleer
co-authored by
Copilot App
parent
4813f30942
commit
49a5524bd4
@@ -152,6 +152,14 @@ const (
|
||||
BlinkingBar = "blinking_bar"
|
||||
SteadyBar = "steady_bar"
|
||||
|
||||
// DefaultSteady and DefaultBlinking reset DECSCUSR to the terminal's own
|
||||
// default shape (CSI 0 SP q) and only toggle blink (CSI ? 12 h/l), so
|
||||
// terminal-specific shapes DECSCUSR can't select - Windows Terminal's
|
||||
// vintage, double-underscore and empty-box cursors among them - stay
|
||||
// under the user's terminal profile setting instead of being overridden.
|
||||
DefaultSteady = "default_steady"
|
||||
DefaultBlinking = "default_blinking"
|
||||
|
||||
ANCHOR = "ANCHOR"
|
||||
BG = "BG"
|
||||
FG = "FG"
|
||||
@@ -395,6 +403,13 @@ func SetCursorStyle(style string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
switch style {
|
||||
case DefaultSteady:
|
||||
return fmt.Sprintf(formats.Escape, "\x1b[0 q\x1b[?12l")
|
||||
case DefaultBlinking:
|
||||
return fmt.Sprintf(formats.Escape, "\x1b[0 q\x1b[?12h")
|
||||
}
|
||||
|
||||
code, ok := decscusrCodes[style]
|
||||
if !ok {
|
||||
return ""
|
||||
|
||||
@@ -601,6 +601,18 @@ func TestSetCursorStyle(t *testing.T) {
|
||||
Style: "not-a-style",
|
||||
Expected: "",
|
||||
},
|
||||
{
|
||||
Case: "Default steady, generic shell",
|
||||
Shell: shell.GENERIC,
|
||||
Style: DefaultSteady,
|
||||
Expected: "\x1b[0 q\x1b[?12l",
|
||||
},
|
||||
{
|
||||
Case: "Default blinking wrapped for zsh",
|
||||
Shell: shell.ZSH,
|
||||
Style: DefaultBlinking,
|
||||
Expected: "%{\x1b[0 q\x1b[?12h%}",
|
||||
},
|
||||
{
|
||||
Case: "Plain mode renders nothing",
|
||||
Shell: shell.GENERIC,
|
||||
|
||||
+3
-1
@@ -5481,7 +5481,9 @@
|
||||
"blinking_underline",
|
||||
"steady_underline",
|
||||
"blinking_bar",
|
||||
"steady_bar"
|
||||
"steady_bar",
|
||||
"default_steady",
|
||||
"default_blinking"
|
||||
]
|
||||
},
|
||||
"enable_cursor_positioning": {
|
||||
|
||||
@@ -130,7 +130,7 @@ For example, the following is a valid `--config` flag:
|
||||
| --------------------------- | ---------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `final_space` | `boolean` | | when true adds a space at the end of the prompt |
|
||||
| `pwd` | `string` | | notify terminal of current working directory, values can be `osc99`, `osc7` or `osc51` depending on your terminal. Supports [templates][templates] |
|
||||
| `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) |
|
||||
| `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) |
|
||||
| `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 |
|
||||
| `accent_color` | `string` | | [color][colors] - accent color, used as a fallback when the `accent` [color][accent] is not supported |
|
||||
| `var` | `map[string]any` | | config variables to use in [templates][templates]. Can be any value |
|
||||
|
||||
Reference in New Issue
Block a user