Closed DEberhardt closed 2 years ago
@DEberhardt this is a PSReadline bug. We set the prompt line count correctly, but somehow this use-case isn't yet well supported.
ah - PsReadLine again - I shall report there :smile:
@DEberhardt it's a core functionality in PowerShell. Do let me know if there's something I can do. All of this isn't very well documented yet.
Not to resurrect an old thread, but since no progress has been made on the PSReadline issue, I devised a workaround if you are running into issues with this. If you adjust the transient prompt behavior to also ensure the commandline is shorter than the current buffer, you can prevent this issue. You can test this locally with this:
Set-PSReadLineKeyHandler -Key Enter -BriefDescription 'OhMyPoshEnterKeyHandlerCleaned' -ScriptBlock {
$previousOutputEncoding = [Console]::OutputEncoding
try {
$parseErrors = $null
$currentAst = $null
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$currentAst, [ref]$null, [ref]$parseErrors, [ref]$null)
if ($parseErrors.Count -eq 0) {
# get number of lines in the current commandline
$lines = $currentAst.Extent.Text.Split("`n").Count
# get buffer height
$terminalHeight = $Host.UI.RawUI.WindowSize.Height
# only render transient prompt if the commandline fits in the buffer
if ($lines -le $terminalHeight -and $terminalHeight -gt 0) {
# HACK for debugging
if ($null -ne ($omp = Get-Module oh-my-posh-core -ErrorAction SilentlyContinue)) { & $omp { $script:TransientPrompt = $true } }
# ENDHACK
# $script:TransientPrompt = $true
[Console]::OutputEncoding = [Text.Encoding]::UTF8
[Microsoft.PowerShell.PSConsoleReadLine]::EndOfLine
[Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt()
}
}
}
finally {
# If PSReadline is set to display suggestion list, this workaround is needed to clear the buffer below
# before accepting the current commandline. The max amount of items in the list is 10, so 12 lines
# are cleared (10 + 1 more for the prompt + 1 more for current commandline).
if ((Get-PSReadLineOption).PredictionViewStyle -eq 'ListView') {
$terminalHeight = $Host.UI.RawUI.WindowSize.Height
# only do this on an valid value
if ([int]$terminalHeight -gt 0) {
[Microsoft.PowerShell.PSConsoleReadLine]::Insert("`n" * [System.Math]::Min($terminalHeight - $Host.UI.RawUI.CursorPosition.Y - 1, 12))
[Microsoft.PowerShell.PSConsoleReadLine]::Undo()
}
}
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
[Console]::OutputEncoding = $previousOutputEncoding
}
}
This will make these larger entries not update to your transient prompt, but since they are already scrolled off the visible window, the space-savings of your transient prompt are less impactful. Obviously being able to adjust the prompt from a prior entry would be optimal, but in the interim, this allows you to continue to use large code blocks without erroring.
This issue has been automatically locked since there has not been any recent activity (i.e. last half year) after it was closed. It helps our maintainers focus on the active issues. If you have found a problem that seems similar, please open a discussion first, complete the body with all the details necessary to reproduce, and mention this issue as reference.
Code of Conduct
What happened?
I may not be able to describe this well, I think I am missing some vocabulary, but here it goes:
When I select multi-line text, like this one:
and paste it into a session that has Oh-my-posh loaded with TransientPrompt enabled, the output is this:
On line 4, the text "de is off." is repeated from line 2. I could observe this in other areas.
This has no impact on the execution, but is a visual bug on the terminal.
Theme
ParagnosterPlus2
{ "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json", "blocks": [{ "alignment": "left", "segments": [{ "Enabled": false, "foreground": "#1BD760", "properties": { "paused_icon": "\uf8e3 ", "playing_icon": "\ue602 ", "stopped_icon": "\uf04d ", "track_separator": " - " }, "style": "plain", "template": "{{ .Icon }}{{ if ne .Status \"stopped\" }}{{ .Artist }} - {{ .Track }}{{ end }} ", "type": "spotify" }], "type": "prompt" }, { "alignment": "right", "segments": [{ "foreground": "#91ddff", "style": "plain", "template": " \uf85a {{ round .PhysicalPercentUsed .Precision }}% ", "type": "sysinfo" }, { "foreground_templates": [ "{{if eq \"Charging\" .State.String}}#40c4ff{{end}}", "{{if eq \"Discharging\" .State.String}}#ff5722{{end}}", "{{if eq \"Full\" .State.String}}#4caf50{{end}}" ], "foreground": "#f36943", "properties": { "charged_icon": "\uf583 ", "charging_icon": "\uf588 ", "discharging_icon": "\uf57d " }, "style": "plain", "template": " {{ if not .Error }}{{ .Icon }}{{ .Percentage }}{{ end }}{{ .Error }}% ", "type": "battery" }, { "type": "owm", "style": "plain", "foreground": "#91ddff", "template": "{{.Weather}} {{ .Temperature }}{{.UnitIcon }} ", "properties": { "apikey": "3d07cc3aeda66d90243a06c9f4deac5f", "location": "BRISTOL,GB", "units": "metric", "http_timeout": 100, "cache_timeout": 10 } }, { "foreground": "#ffffff", "properties": { "time_format": "_2 Jan" }, "style": "plain", "template": " {{ .CurrentDate | date .Format }}", "type": "time" }, { "foreground": "#91ddff", "properties": { "datetime_format": "2022-01-02 15:04:05", "time_format": "15:04:05" }, "style": "plain", "template": " {{ .CurrentDate | date .Format }}", "type": "time" } ], "type": "prompt" }, { "type": "newline" }, { "alignment": "left", "segments": [{ "Enabled": false, "background": "#ff8800", "foreground": "#100e23", "powerline_symbol": "\ue0c0", "properties": { "root_icon": "" }, "style": "powerline", "template": " \uf0e7 ", "type": "root" }, { "Enabled": false, "background": "#8800dd", "foreground": "#ffffff", "powerline_symbol": "\ue0b0", "properties": { "style": "amarillo", "threshold": 500 }, "style": "powerline", "template": " {{ .FormattedMs }} ", "type": "executiontime" }, { "background": "#ffffff", "foreground": "#100e23", "powerline_symbol": "\ue0b0", "style": "powerline", "template": " {{ .Name }} ", "type": "shell" }, { "Enabled": false, "background": "#91ddff", "foreground": "#100e23", "powerline_symbol": "\ue0b0", "properties": { "folder_icon": "\uf115", "folder_separator_icon": " \ue0b1 ", "style": "full" }, "style": "powerline", "template": " {{ .Path }} ", "type": "path" }, { "background": "#95ffa4", "background_templates": [ "{{ if or (.Working.Changed) (.Staging.Changed) }}#FF9248{{ end }}", "{{ if and (gt .Ahead 0) (gt .Behind 0) }}#ff4500{{ end }}", "{{ if gt .Ahead 0 }}#B388FF{{ end }}", "{{ if gt .Behind 0 }}#B388FF{{ end }}" ], "foreground": "#193549", "leading_diamond": "\ue0b6", "powerline_symbol": "\ue0b0", "properties": { "branch_max_length": 25, "fetch_stash_count": true, "fetch_status": true, "fetch_upstream_icon": true }, "style": "powerline", "template": " {{ .UpstreamIcon }}{{ .HEAD }}{{if .BranchStatus }} {{ .BranchStatus }}{{ end }}{{ if .Working.Changed }} \uf044 {{ .Working.String }}{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} |{{ end }}{{ if .Staging.Changed }} \uf046 {{ .Staging.String }}{{ end }}{{ if gt .StashCount 0 }} \uf692 {{ .StashCount }}{{ end }} ", "trailing_diamond": "\ue0b4", "type": "git" }, { "Enabled": false, "background": "#906cff", "foreground": "#100e23", "powerline_symbol": "\ue0b0", "style": "powerline", "template": " \ue235 {{ if .Error }}{{ .Error }}{{ else }}{{ if .Venv }}{{ .Venv }} {{ end }}{{ .Full }}{{ end }} ", "type": "python" }, { "Enabled": false, "background": "#ff8080", "foreground": "#ffffff", "powerline_symbol": "\ue0b0", "style": "powerline", "template": " {{ if gt .Code 0 }}\uf00d {{ .Meaning }}{{ else }}\uf42e{{ end }} ", "type": "exit" } ], "type": "prompt" }, { "type": "newline" }, { "alignment": "left", "segments": [{ "Enabled": false, "foreground": "#007ACC", "style": "plain", "template": "\u276f ", "type": "text" }], "type": "prompt" } ], "transient_prompt": { "background": "transparent", "foreground": "#666666", "template": "[{{ .Segments.Time.CurrentDate | date \"2006-01-02 15:04:05\" }}]{{ if .Segments.Executiontime.Ms }}{{ if eq \"False\" (title (default \"False\" .Env.DISABLE_SEGMENT_TRANSIENT_EXEC_TIME)) }}[{{ .Segments.Executiontime.FormattedMs }}]{{ end }}{{ end }}\u276f " }, "version": 2 }
What OS are you seeing the problem on?
Windows
Which shell are you using?
powershell
Log output