Complete function completes common ANSI escape sequence in completion items

Open
#5,044 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp
Domain
cli

Research direction

Start by tracing PSReadLine's Complete logic using the supplied Register-ArgumentCompleter reproduction, focusing on how the common prefix is derived from ListItemText. Verify that ANSI escape sequences are not inserted into the completed command arguments, while normal completion text still works as expected.

Written by the indexing model from the issue text.

Description

Needs-Triage :mag:
Prerequisites
  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • 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
Dominant language
C#
Stars
4.4k
Forks
341
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PowerShell/PSReadLine

All issues in PowerShell/PSReadLine

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.