fix(cursor): allow disabling cursor positioning

resolves #4072
This commit is contained in:
Jan De Dobbeleer 2023-07-24 19:07:16 +02:00 committed by Jan De Dobbeleer
parent f47da9592f
commit 0af3029cf1
5 changed files with 43 additions and 35 deletions

View file

@ -70,8 +70,8 @@ func runInit(shellName string) {
shell.ShellIntegration = cfg.ShellIntegration shell.ShellIntegration = cfg.ShellIntegration
for i, block := range cfg.Blocks { for i, block := range cfg.Blocks {
// only fetch cursor position when relevant // only fetch cursor position when relevant
if i == 0 && block.Newline { if !cfg.DisableCursorPositioning && (i == 0 && block.Newline) {
shell.Cursor = true shell.CursorPositioning = true
} }
if block.Type == engine.RPrompt { if block.Type == engine.RPrompt {
shell.RPrompt = true shell.RPrompt = true

View file

@ -34,24 +34,25 @@ const (
// Config holds all the theme for rendering the prompt // Config holds all the theme for rendering the prompt
type Config struct { type Config struct {
Version int `json:"version"` Version int `json:"version"`
FinalSpace bool `json:"final_space,omitempty"` FinalSpace bool `json:"final_space,omitempty"`
ConsoleTitleTemplate string `json:"console_title_template,omitempty"` ConsoleTitleTemplate string `json:"console_title_template,omitempty"`
TerminalBackground string `json:"terminal_background,omitempty"` TerminalBackground string `json:"terminal_background,omitempty"`
AccentColor string `json:"accent_color,omitempty"` AccentColor string `json:"accent_color,omitempty"`
Blocks []*Block `json:"blocks,omitempty"` Blocks []*Block `json:"blocks,omitempty"`
Tooltips []*Segment `json:"tooltips,omitempty"` Tooltips []*Segment `json:"tooltips,omitempty"`
TransientPrompt *Segment `json:"transient_prompt,omitempty"` TransientPrompt *Segment `json:"transient_prompt,omitempty"`
ValidLine *Segment `json:"valid_line,omitempty"` ValidLine *Segment `json:"valid_line,omitempty"`
ErrorLine *Segment `json:"error_line,omitempty"` ErrorLine *Segment `json:"error_line,omitempty"`
SecondaryPrompt *Segment `json:"secondary_prompt,omitempty"` SecondaryPrompt *Segment `json:"secondary_prompt,omitempty"`
DebugPrompt *Segment `json:"debug_prompt,omitempty"` DebugPrompt *Segment `json:"debug_prompt,omitempty"`
Palette ansi.Palette `json:"palette,omitempty"` Palette ansi.Palette `json:"palette,omitempty"`
Palettes *ansi.Palettes `json:"palettes,omitempty"` Palettes *ansi.Palettes `json:"palettes,omitempty"`
Cycle ansi.Cycle `json:"cycle,omitempty"` Cycle ansi.Cycle `json:"cycle,omitempty"`
ShellIntegration bool `json:"shell_integration,omitempty"` ShellIntegration bool `json:"shell_integration,omitempty"`
PWD string `json:"pwd,omitempty"` PWD string `json:"pwd,omitempty"`
Var map[string]interface{} `json:"var,omitempty"` Var map[string]interface{} `json:"var,omitempty"`
DisableCursorPositioning bool `json:"disable_cursor_positioning,omitempty"`
// Deprecated // Deprecated
OSC99 bool `json:"osc99,omitempty"` OSC99 bool `json:"osc99,omitempty"`

View file

@ -46,12 +46,12 @@ const (
) )
var ( var (
Transient bool Transient bool
ErrorLine bool ErrorLine bool
Tooltips bool Tooltips bool
ShellIntegration bool ShellIntegration bool
RPrompt bool RPrompt bool
Cursor bool CursorPositioning bool
) )
func getExecutablePath(env platform.Environment) (string, error) { func getExecutablePath(env platform.Environment) (string, error) {
@ -270,7 +270,7 @@ func PrintInit(env platform.Environment) string {
"::TOOLTIPS::", toggleSetting(Tooltips), "::TOOLTIPS::", toggleSetting(Tooltips),
"::FTCS_MARKS::", toggleSetting(ShellIntegration), "::FTCS_MARKS::", toggleSetting(ShellIntegration),
"::RPROMPT::", strconv.FormatBool(RPrompt), "::RPROMPT::", strconv.FormatBool(RPrompt),
"::CURSOR::", strconv.FormatBool(Cursor), "::CURSOR::", strconv.FormatBool(CursorPositioning),
"::UPGRADE::", strconv.FormatBool(hasNotice), "::UPGRADE::", strconv.FormatBool(hasNotice),
"::UPGRADENOTICE::", notice, "::UPGRADENOTICE::", notice,
).Replace(script) ).Replace(script)

View file

@ -3269,6 +3269,12 @@
"description": "https://ohmyposh.dev/docs/configuration/overview#general-settings", "description": "https://ohmyposh.dev/docs/configuration/overview#general-settings",
"default": true "default": true
}, },
"disable_cursor_positioning": {
"type": "boolean",
"title": "Disable Cursor Positioning",
"description": "https://ohmyposh.dev/docs/configuration/overview#general-settings",
"default": false
},
"shell_integration": { "shell_integration": {
"type": "boolean", "type": "boolean",
"title": "FTCS command marks for shell integration", "title": "FTCS command marks for shell integration",

View file

@ -126,14 +126,15 @@ For example, the following is a valid `--config` flag:
## General Settings ## General Settings
| Name | Type | Description | | Name | Type | Description |
| --------------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ---------------------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `final_space` | `boolean` | when true adds a space at the end of the prompt | | `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 | | `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 | | `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 | | `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 | | `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 | | `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 ### JSON Schema Validation