fix(prompt): write real newlines for Elvish on non-Windows systems
Some checks are pending
Code QL / code-ql (push) Waiting to run
Azure Static Web Apps CI/CD / Build and Deploy (push) Waiting to run
Release / changelog (push) Waiting to run
Release / artifacts (push) Blocked by required conditions

This commit is contained in:
L. Yeung 2024-09-19 14:58:59 +08:00 committed by Jan De Dobbeleer
parent 68a1e89f29
commit 3114666a25
2 changed files with 16 additions and 8 deletions

View file

@ -113,8 +113,8 @@ func (e *Engine) getNewline() string {
}
// Warp terminal will remove a newline character ('\n') from the prompt, so we hack it in.
// For Elvish, we do this to prevent cutting off a right-aligned block.
if e.isWarp() || e.Env.Shell() == shell.ELVISH {
// For Elvish on Windows, we do this to prevent cutting off a right-aligned block.
if e.isWarp() || (e.Env.Shell() == shell.ELVISH && e.Env.GOOS() == runtime.WINDOWS) {
return terminal.LineBreak()
}
@ -545,16 +545,17 @@ func New(flags *runtime.Flags) *Engine {
}
switch env.Shell() {
case shell.TCSH:
// In Tcsh, newlines in a prompt are badly translated.
// No silver bullet here. We have to reduce the terminal width by 1 so a right-aligned block will not be broken.
eng.rectifyTerminalWidth(-1)
case shell.ELVISH, shell.XONSH:
// In these shells, the behavior of wrapping at the end of a prompt line is inconsistent across platforms.
case shell.XONSH:
// In Xonsh, the behavior of wrapping at the end of a prompt line is inconsistent across platforms.
// On Windows, it wraps before the rightmost cell on the terminal screen, that is, the rightmost cell is never available for a prompt line.
if eng.Env.GOOS() == runtime.WINDOWS {
eng.rectifyTerminalWidth(-1)
}
case shell.TCSH, shell.ELVISH:
// In Tcsh, newlines in a prompt are badly translated.
// No silver bullet here. We have to reduce the terminal width by 1 so a right-aligned block will not be broken.
// In Elvish, the behavior is similar to that in Xonsh, but we do this for all platforms.
eng.rectifyTerminalWidth(-1)
case shell.PWSH, shell.PWSH5:
// when in PowerShell, and force patching the bleed bug
// we need to reduce the terminal width by 1 so the last

View file

@ -2,6 +2,8 @@ package prompt
import (
"github.com/jandedobbeleer/oh-my-posh/src/config"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
"github.com/jandedobbeleer/oh-my-posh/src/shell"
)
func (e *Engine) RPrompt() string {
@ -29,5 +31,10 @@ func (e *Engine) RPrompt() string {
text, length := e.renderBlockSegments(rprompt)
e.rpromptLength = length
if e.Env.Shell() == shell.ELVISH && e.Env.GOOS() != runtime.WINDOWS {
// Workaround to align with a right-aligned block on non-Windows systems.
text += " "
}
return text
}