fix(pwsh): prevent a command from eating tail of a transient prompt
Some checks failed
Code QL / code-ql (push) Has been cancelled
Release / changelog (push) Has been cancelled
Release / artifacts (push) Has been cancelled

This commit is contained in:
L. Yeung 2024-09-13 02:01:07 +08:00 committed by Jan De Dobbeleer
parent 4291da4b5a
commit 063b95da25
2 changed files with 16 additions and 3 deletions

View file

@ -157,7 +157,9 @@ func (e *Engine) shouldFill(filler string, padLength int) (string, bool) {
} }
repeat := padLength / lenFiller repeat := padLength / lenFiller
return strings.Repeat(filler, repeat), true unfilled := padLength % lenFiller
text := strings.Repeat(filler, repeat) + strings.Repeat(" ", unfilled)
return text, true
} }
func (e *Engine) getTitleTemplateText() string { func (e *Engine) getTitleTemplateText() string {
@ -531,7 +533,7 @@ func New(flags *runtime.Flags) *Engine {
switch env.Shell() { switch env.Shell() {
case shell.ELVISH: case shell.ELVISH:
// In Elvish, continuous text is always cut off before the right-most cell on the terminal screen. // In Elvish, a prompt line will always wrap when the cursor reaches the rightmost cell on the terminal screen.
// We have to reduce the terminal width by 1 so a right-aligned block will not be broken. // We have to reduce the terminal width by 1 so a right-aligned block will not be broken.
eng.rectifyTerminalWidth(-1) eng.rectifyTerminalWidth(-1)
case shell.PWSH, shell.PWSH5: case shell.PWSH, shell.PWSH5:

View file

@ -458,7 +458,18 @@ Example:
Set-PSReadLineOption -ExtraPromptLineCount (($standardOut | Measure-Object -Line).Lines - 1) Set-PSReadLineOption -ExtraPromptLineCount (($standardOut | Measure-Object -Line).Lines - 1)
# The output can be multi-line, joining them ensures proper rendering. # The output can be multi-line, joining them ensures proper rendering.
$standardOut -join "`n" $output = $standardOut -join "`n"
if ($script:PromptType -eq 'transient') {
# Workaround to prevent a command from eating the tail of a transient prompt, when we're at the end of the line.
$command = ''
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$command, [ref]$null)
if ($command) {
$output += " `b`b"
}
}
$output
# remove any posh-git status # remove any posh-git status
$env:POSH_GIT_STATUS = $null $env:POSH_GIT_STATUS = $null