diff --git a/src/engine/engine.go b/src/engine/engine.go index e37ad554..5ee07391 100644 --- a/src/engine/engine.go +++ b/src/engine/engine.go @@ -398,6 +398,9 @@ func (e *Engine) PrintTooltip(tip string) string { return "" } text, length := block.RenderSegments() + // clear from cursor to the end of the line in case a previous tooltip is cut off and partially preserved, + // if the new one is shorter + e.write(e.Writer.ClearAfter()) e.write(e.Writer.CarriageForward()) e.write(e.Writer.GetCursorForRightWrite(length, 0)) e.write(text) diff --git a/src/shell/scripts/omp.ps1 b/src/shell/scripts/omp.ps1 index bb05cd4c..b013b8fc 100644 --- a/src/shell/scripts/omp.ps1 +++ b/src/shell/scripts/omp.ps1 @@ -123,23 +123,24 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock { if (("::TOOLTIPS::" -eq "true") -and ($ExecutionContext.SessionState.LanguageMode -ne "ConstrainedLanguage")) { Set-PSReadLineKeyHandler -Key Spacebar -BriefDescription 'OhMyPoshSpaceKeyHandler' -ScriptBlock { [Microsoft.PowerShell.PSConsoleReadLine]::Insert(' ') - $position = $host.UI.RawUI.CursorPosition - $cleanPSWD = Get-CleanPSWD $command = $null [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$command, [ref]$null) $command = $command.TrimStart().Split(" ", 2) | Select-Object -First 1 - if ($command -eq $script:ToolTipCommand) { + # ignore an empty/repeated tip + if ($command -eq '' -or $command -eq $script:ToolTipCommand) { return } - $script:ToolTipCommand = $command + $position = $host.UI.RawUI.CursorPosition + $cleanPSWD = Get-CleanPSWD $standardOut = @(Start-Utf8Process $script:OMPExecutable @("print", "tooltip", "--error=$script:ErrorCode", "--shell=$script:ShellName", "--pswd=$cleanPSWD", "--config=$env:POSH_THEME", "--command=$command", "--shell-version=$script:PSVersion")) - if ($standardOut -ne '') { - # clear from cursor to the end of the line in case a previous tooltip is cut off and partially preserved, - # if the new one is shorter - Write-Host "`e[K" -NoNewline - Write-Host $standardOut -NoNewline + # ignore an empty tooltip + if ($standardOut -eq '') { + return } + Write-Host $standardOut -NoNewline $host.UI.RawUI.CursorPosition = $position + # cache the tip command + $script:ToolTipCommand = $command # we need this workaround to prevent the text after cursor from disappearing when the tooltip is rendered [Microsoft.PowerShell.PSConsoleReadLine]::Insert(' ') [Microsoft.PowerShell.PSConsoleReadLine]::Undo()