From 0af3029cf18adcbcf85e646183789151e118df36 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Mon, 24 Jul 2023 19:07:16 +0200 Subject: [PATCH] fix(cursor): allow disabling cursor positioning resolves #4072 --- src/cli/init.go | 4 +-- src/engine/config.go | 37 +++++++++++++------------ src/shell/init.go | 14 +++++----- themes/schema.json | 6 ++++ website/docs/configuration/overview.mdx | 17 ++++++------ 5 files changed, 43 insertions(+), 35 deletions(-) diff --git a/src/cli/init.go b/src/cli/init.go index 456b8fd6..4c486d38 100644 --- a/src/cli/init.go +++ b/src/cli/init.go @@ -70,8 +70,8 @@ func runInit(shellName string) { shell.ShellIntegration = cfg.ShellIntegration for i, block := range cfg.Blocks { // only fetch cursor position when relevant - if i == 0 && block.Newline { - shell.Cursor = true + if !cfg.DisableCursorPositioning && (i == 0 && block.Newline) { + shell.CursorPositioning = true } if block.Type == engine.RPrompt { shell.RPrompt = true diff --git a/src/engine/config.go b/src/engine/config.go index 644a27a1..f6be03a2 100644 --- a/src/engine/config.go +++ b/src/engine/config.go @@ -34,24 +34,25 @@ const ( // Config holds all the theme for rendering the prompt type Config struct { - Version int `json:"version"` - FinalSpace bool `json:"final_space,omitempty"` - ConsoleTitleTemplate string `json:"console_title_template,omitempty"` - TerminalBackground string `json:"terminal_background,omitempty"` - AccentColor string `json:"accent_color,omitempty"` - Blocks []*Block `json:"blocks,omitempty"` - Tooltips []*Segment `json:"tooltips,omitempty"` - TransientPrompt *Segment `json:"transient_prompt,omitempty"` - ValidLine *Segment `json:"valid_line,omitempty"` - ErrorLine *Segment `json:"error_line,omitempty"` - SecondaryPrompt *Segment `json:"secondary_prompt,omitempty"` - DebugPrompt *Segment `json:"debug_prompt,omitempty"` - Palette ansi.Palette `json:"palette,omitempty"` - Palettes *ansi.Palettes `json:"palettes,omitempty"` - Cycle ansi.Cycle `json:"cycle,omitempty"` - ShellIntegration bool `json:"shell_integration,omitempty"` - PWD string `json:"pwd,omitempty"` - Var map[string]interface{} `json:"var,omitempty"` + Version int `json:"version"` + FinalSpace bool `json:"final_space,omitempty"` + ConsoleTitleTemplate string `json:"console_title_template,omitempty"` + TerminalBackground string `json:"terminal_background,omitempty"` + AccentColor string `json:"accent_color,omitempty"` + Blocks []*Block `json:"blocks,omitempty"` + Tooltips []*Segment `json:"tooltips,omitempty"` + TransientPrompt *Segment `json:"transient_prompt,omitempty"` + ValidLine *Segment `json:"valid_line,omitempty"` + ErrorLine *Segment `json:"error_line,omitempty"` + SecondaryPrompt *Segment `json:"secondary_prompt,omitempty"` + DebugPrompt *Segment `json:"debug_prompt,omitempty"` + Palette ansi.Palette `json:"palette,omitempty"` + Palettes *ansi.Palettes `json:"palettes,omitempty"` + Cycle ansi.Cycle `json:"cycle,omitempty"` + ShellIntegration bool `json:"shell_integration,omitempty"` + PWD string `json:"pwd,omitempty"` + Var map[string]interface{} `json:"var,omitempty"` + DisableCursorPositioning bool `json:"disable_cursor_positioning,omitempty"` // Deprecated OSC99 bool `json:"osc99,omitempty"` diff --git a/src/shell/init.go b/src/shell/init.go index 25978d10..14bfe60b 100644 --- a/src/shell/init.go +++ b/src/shell/init.go @@ -46,12 +46,12 @@ const ( ) var ( - Transient bool - ErrorLine bool - Tooltips bool - ShellIntegration bool - RPrompt bool - Cursor bool + Transient bool + ErrorLine bool + Tooltips bool + ShellIntegration bool + RPrompt bool + CursorPositioning bool ) func getExecutablePath(env platform.Environment) (string, error) { @@ -270,7 +270,7 @@ func PrintInit(env platform.Environment) string { "::TOOLTIPS::", toggleSetting(Tooltips), "::FTCS_MARKS::", toggleSetting(ShellIntegration), "::RPROMPT::", strconv.FormatBool(RPrompt), - "::CURSOR::", strconv.FormatBool(Cursor), + "::CURSOR::", strconv.FormatBool(CursorPositioning), "::UPGRADE::", strconv.FormatBool(hasNotice), "::UPGRADENOTICE::", notice, ).Replace(script) diff --git a/themes/schema.json b/themes/schema.json index 9a0332e7..735ea4ee 100644 --- a/themes/schema.json +++ b/themes/schema.json @@ -3269,6 +3269,12 @@ "description": "https://ohmyposh.dev/docs/configuration/overview#general-settings", "default": true }, + "disable_cursor_positioning": { + "type": "boolean", + "title": "Disable Cursor Positioning", + "description": "https://ohmyposh.dev/docs/configuration/overview#general-settings", + "default": false + }, "shell_integration": { "type": "boolean", "title": "FTCS command marks for shell integration", diff --git a/website/docs/configuration/overview.mdx b/website/docs/configuration/overview.mdx index 61c9d5d1..26993bfb 100644 --- a/website/docs/configuration/overview.mdx +++ b/website/docs/configuration/overview.mdx @@ -126,14 +126,15 @@ For example, the following is a valid `--config` flag: ## General Settings -| Name | Type | Description | -| --------------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `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 | -| `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 | -| `shell_integration` | `boolean` | enable shell integration using FinalTerm's OSC sequences. Works in bash, cmd (Clink v1.14.25+), fish, powershell and zsh | +| Name | Type | Description | +| ---------------------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `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 | +| `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 | +| `shell_integration` | `boolean` | enable shell integration using FinalTerm's OSC sequences. Works in bash, cmd (Clink v1.14.25+), fish, powershell and zsh | +| `disable_cursor_positioning` | `boolean` | disable fetching the cursor position in bash and zsh in case of unwanted side-effects | ### JSON Schema Validation