Open yan12125 opened 1 year ago
The issue is gone after Remove-module PSReadline
. Probably an issue with PSReadline?
Both PSReadline 2.2.6 and 2.3.1-beta1 have this issue.
I had the exactly problem. In my case OSC 9;9
output the last symbol of prompt string, m
in prompt below. I do not know why and how but I fixed this by exporting [int] class (no matter what class).
Set-PSReadlineOption -ContinuationPrompt $("`u{20}" * 5)
[console]::WriteLine("`e]12;#0087ff`a")
function Global:Prompt
{
$null = [int]::new() # No artefacts. I do not know why.
$prompt = "`e[38;5;31m `u{ff05} `e]9;9;${PWD}`e\`e[0m"
return $prompt
}
You may want this instead of hacking around $null
:
$normalPrompt = "`e[38;5;31m `u{ff05} `e[0m"
$errorPrompt = "`e[91m `u{ff05} `e[0m"
Set-PSReadlineOption -PromptText $normalPrompt, $errorPrompt
From a comment in https://github.com/MicrosoftDocs/terminal/issues/597#issuecomment-1346749542,
IMPORTANT: Make sure there's a printable charater last in the prompt. Otherwise, PSReadline is gonna use the terminating
\
here and colorize that if it detects a syntax error
-PromptText
explicitly specifies prompts to use for syntax error indication and avoids fragile auto detection.
I have no idea why hacking around $null
works, though.
Apparently PSReadLine simply cuts a substring since the last non-whitespace character in the prompt: https://github.com/PowerShell/PSReadLine/blob/v2.2.6/PSReadLine/ReadLine.cs#L819. It will be great if OSC commands are parsed and ignored, but that may be far from trivial due to the need of a parser of various escape sequences.
If I were a PowerShell developer, I might close this as WONTFIX :)
GitHubA bash inspired readline implementation for PowerShell - PSReadLine/PSReadLine/ReadLine.cs at v2.2.6 · PowerShell/PSReadLine
You may want this
No, I do not want. I showed this example to present a workaround that is inexplicable to me.
I cannot reproduce the issue with the repro steps described in the issue. The GIF below is from WSL Ubuntu 18.04 with PowerShell 7.4-preview.3 + PSReadLine 2.3.1-beta1. I tried on Windows 11 with both conhost and Windows Terminal, and cannot reproduce too.
@yan12125 and @237dmitry Can either of you please provide a repro that help me reproduce the issue locally?
@daxian-dbw For me, the issue happens only when the prompt function is defined in $PROFILE
. It does not happend when the function is defined from the command line.
Also, it seems that error prompt is not enabled for you (the last non-whitespace character should become red when there is a syntax error). Could you check if PromptText
or ErrorColor
in Get-PSReadLineOption
results is overridden or not?
I can reproduce the issue after moving the prompt function to $PROFILE
. We will investigate it.
Thank you for confirmation. As the reproducer is from official Microsoft docs, how do you think about updating docs to work-around this issue first? https://github.com/MicrosoftDocs/terminal/pull/689
Unfortunately, we don't own that doc.
Prerequisites
Steps to reproduce
Configure OSC 9;9 for PowerShell and add custom prompt in
$PROFILE
following https://learn.microsoft.com/en-us/windows/terminal/tutorials/new-tab-same-directory#powershell-powershellexe-or-pwshexe:'
or a dot.
Expected behavior
Actual behavior
Error details
No response
Environment data
Visuals
This is captured with Konsole 23.04.2 and tmux 3.3a. I can reproduce the same issue with PowerShell 7.3.4 on Windows 10 22H2.