Skip to content

Commit

Permalink
fix(prompt): write real newlines for Elvish on non-Windows systems
Browse files Browse the repository at this point in the history
  • Loading branch information
lewis-yeung authored and JanDeDobbeleer committed Sep 19, 2024
1 parent 68a1e89 commit 3114666
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/prompt/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/prompt/rprompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

0 comments on commit 3114666

Please sign in to comment.