Skip to content

Bug Report: What is reordering VT escape sequences in my string? #2011

@jazzdelightsme

Description

@jazzdelightsme

Environment

Windows build number: Microsoft Windows [Version 10.0.18362.239]
Windows Terminal version (if applicable): (built from latest source as of July 17th, 2019, morning)

I am working on implementing some new VT escape sequences (PR here), but I've run into a strange problem. What the sequences do (or are supposed to do) is not important here. The problem is that in certain circumstances, something is reordering VT escape sequences in my content (which is very surprising to me).

The control sequences in question are XTPUSHSGR and XTPOPSGR: [CSI]#p and [CSI]#q, respectively. Note in the string below, how there is an XTPUSHSGR sequence, then a normal SGR sequence to set the color to red, then an XTPOPSGR sequence (and then a normal SGR sequence to reset the color).

When I open OpenConsole.sln in Visual Studio 2019, with the CascadiaPackage set as the default project to debug, and then F5 to start debugging it, it launches a terminal running Windows PowerShell. When I send my string to the console, something is moving the XTPUSHSGR and XTPOPSGR sequences to the very beginning of the string!

Steps to reproduce

  1. Start OpenConsole.sln in Visual Studio 2019. Make sure CascadiaPackage is the default project, and platform is set to x64, and build the solution if necessary.
  2. F5 to start debugging a new instance. You should now have a PowerShell instance in the terminal.
  3. In the PowerShell instance in the terminal, run the following commands:
 $esc = [char] 0x1b
 $s = "Hello. Push:${esc}[#p ${esc}[91m this text is RED Pop:${esc}[#q FG should " +
      "no longer be red (unless it was red before) courtesy reset: ${esc}[0m"
  1. Set a breakpoint at TerminalControl.dll!Microsoft::Console::VirtualTerminal::StateMachine::ProcessString (the two-parameter one).
  2. In the PowerShell instance in the terminal, run the command $s to output the string.
  3. When you hit the breakpoint, observe the value of rgwch.

Expected behavior

The content of the string should be just as it was set in PowerShell.

Actual behavior

The XTPUSHSGR and XTPOPSGR sequences have been moved to the beginning of the string!

My first thought was that PowerShell must be doing something funny, but I attached windbg to the PowerShell and set a breakpoint on kernel32!WriteConsoleW, and the string passed in there is correct. So something is happening after the string has left PowerShell's hands.

Metadata

Metadata

Assignees

Labels

Area-RenderingText rendering, emoji, complex glyph & font-fallback issuesIssue-BugIt either shouldn't be doing this or needs an investigation.Needs-Tag-FixDoesn't match tag requirementsPriority-1A description (P1)Product-ConptyFor console issues specifically related to conptyResolution-Fix-CommittedFix is checked in, but it might be 3-4 weeks until a release.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions