fix(bash): correctly align multiline prompt

relates to #5308
This commit is contained in:
Jan De Dobbeleer 2024-07-20 23:06:17 +02:00 committed by Jan De Dobbeleer
parent 87732c1074
commit c5195f6668
2 changed files with 7 additions and 1 deletions

View file

@ -61,7 +61,7 @@ func (e *Engine) RPrompt() string {
// bash prints this on the same line as the prompt so we need to move the cursor down // bash prints this on the same line as the prompt so we need to move the cursor down
// in case the prompt spans multiple lines // in case the prompt spans multiple lines
if lineCount > 0 { if lineCount > 0 {
return terminal.SaveCursorPosition() + strings.Repeat("\n", lineCount) + text + terminal.RestoreCursorPosition() return terminal.SaveCursorPosition() + fmt.Sprintf("\x1b[%bB", lineCount) + text + terminal.RestoreCursorPosition()
} }
return text return text

View file

@ -43,6 +43,12 @@ Tells the engine what to do with the block. There are two options:
- `rprompt` renders one or more segments aligned to the right of the cursor. Only one `rprompt` block is permitted. - `rprompt` renders one or more segments aligned to the right of the cursor. Only one `rprompt` block is permitted.
Supported on zsh, bash, PowerShell, cmd, nu and fish. Supported on zsh, bash, PowerShell, cmd, nu and fish.
:::warning bash
`rprompt` is not natively supported in bash and comes with one side effect. When you have a multiline prompt,
the `rprompt` will not display when your new prompt is drawn at the bottom of the terminal. This is a limitation
of bash and not Oh My Posh.
:::
### Newline ### Newline
Start the block on a new line - defaults to `false`. For `pwsh` and `cmd` this will not print a newline Start the block on a new line - defaults to `false`. For `pwsh` and `cmd` this will not print a newline