PSReadLine icon indicating copy to clipboard operation
PSReadLine copied to clipboard

Complete function completes common ANSI escape sequence in completion items

Open 8LWXpg opened this issue 1 month ago • 0 comments

Prerequisites

  • [x] Write a descriptive title.
  • [x] Make sure you are able to repro it on the latest released version
  • [x] Search the existing issues, especially the pinned issues.

Exception report

From https://github.com/carapace-sh/carapace/issues/997#issuecomment-3566731943

PSReadLine's `Complete` logic attempts to auto-complete the input with the "common prefix" of all available matches on the first `<TAB>`. While the actual `CompletionText` differ, Carapace prepends the same ANSI escape codes to the `ListItemText` of every entry to ensure styling. The `Complete` function _correctly_ identifies this ANSI sequence as the shared prefix and prints it to the prompt.

Screenshot

Image

Environment data

PS Version: 7.5.4
PS HostName: ConsoleHost (Windows Terminal)
PSReadLine Version: 2.4.5
PSReadLine EditMode: Windows
OS: 10.0.26100.7306 (WinBuild.160101.0800)
BufferWidth: 158
BufferHeight: 25

Steps to reproduce

Set-PSReadLineKeyHandler -Chord Tab -Function Complete
Register-ArgumentCompleter -Native -ScriptBlock {
    param($wordToComplete, $commandAst, $cursorPosition)
    @(
        [System.Management.Automation.CompletionResult]::new("aa", "`e[2maa", [System.Management.Automation.CompletionResultType]::ParameterValue, "1"),
        [System.Management.Automation.CompletionResult]::new("bb", "`e[2mbb", [System.Management.Automation.CompletionResultType]::ParameterValue, "2")
    )
} -CommandName 'bash'

Expected behavior

Completion should not include ANSI escape sequence

Actual behavior

Escape sequence is completed as part of the arguments

bash ^[[2m

8LWXpg avatar Dec 19 '25 06:12 8LWXpg