Skip to content

ANSI escape sequences in custom prompt cause visual artifact ('m' character) during syntax error recoloring #5196

Description

@normanlee

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

N/A

Summary

ANSI escape sequences returned by a custom prompt function cause character offset miscalculations during real-time syntax-error prompt recoloring, leaving an orphaned 'm' character or overwriting the prompt delimiter.

Screenshot

Image Image

Environment data

PS Version: 7.6.5
PS HostName: ConsoleHost (Windows Terminal)
PSReadLine Version: 2.4.5
PSReadLine EditMode: Windows
OS: 10.0.26100.1 (WinBuild.160101.0800)
BufferWidth: 120
BufferHeight: 30

Steps to reproduce

  1. Start PowerShell with the following prompt function:

    function prompt {
        "`e[1;33mPS `e[1;34m$pwd`e[1;32m$('>' * ($nestedPromptLevel + 1)) `e[0m"
    }
  2. Type an opening quotation mark (" or ').

Expected behavior

The prompt delimiter (>) recolors cleanly to indicate an incomplete/syntax error state without visual artifacts.

Actual behavior

An orphaned m (from the trailing \e[0m SGR sequence) is printed at the end of the prompt or overwrites the > character.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-Triage 🔍It's a new issue that core contributor team needs to triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions