carapace-sh / carapace

command argument completion generator for spf13/cobra
https://carapace.sh
Apache License 2.0
289 stars 8 forks source link

A bug in Powershell using the tab key #997

Open Shadow-XT opened 4 months ago

Shadow-XT commented 4 months ago

Current Behavior

PowerShell: 7.4.1 Windows: 22631.3235 When entering a command in PowerShell, such as git or gh, an error such as "^ [[21; 22; 23; 24; 25; 29m ^ [[3" will appear after pressing the tab key, which will affect normal use, as shown in the figure below: image

Expected Behavior

If it is used normally, the following content should appear, and the excess "^ [[21; 22; 23; 24; 25; 29m ^ [[3" should not appear. image

Steps To Reproduce

No response

Version

0.30.2

OS

Shell

Anything else?

No response

rsteube commented 4 months ago

Ok this will be hard because it works for me. The escape code should be one for the colored highlighting.

Is it only happening in gh <TAB> or somewhere else as well? Might be related to some alias or extension (name/description).

Shadow-XT commented 4 months ago

Ok this will be hard because it works for me. The escape code should be one for the colored highlighting.

Is it only happening in gh <TAB> or somewhere else as well? Might be related to some alias or extension (name/description).

It also appears when using other commands, such as python, pip, etc., but with your reminder, I tried to modify my PowerShell Profile and found that the location of the loading configuration has a certain impact on whether the above bug will appear, as follows

#--------- configuration 1 ---------- 
Set-PSReadlineOption -EditMode Emacs
Set-PSReadLineOption -PredictionSource HistoryAndPlugin
Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
#---------------------------
#--------- configuration 2 ---------- 
#powershell (~/.config/powershell/Microsoft PowerShell_profile ps1)
Set-PSReadLineOption -Colors @{"Selection" = "'e [7m"}
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
Carapace _carapace | Out-String | Invoke-Expression
#---------------------------

It turns out that I put configuration 2 before configuration 1, and the above bug will appear. Now after reversing the order, the previous bug has not been found for the time being.

rsteube commented 4 months ago

Seems to be related to the Emacs mode, i get the error on linux as well:

Set-PSReadlineOption -EditMode Emacs

Moving it above the other configuration fixes it indeed.

Shadow-XT commented 4 months ago

Seems to be related to the Emacs mode, i get the error on linux as well:

Set-PSReadlineOption -EditMode Emacs

Moving it above the other configuration fixes it indeed.

It should be caused by this configuration. I tried to comment out the emacs mode, so the above problem will not occur. Thank you!