Some ANSI sequences (including "inert" ones) are not output as-is #13775

Open
opened 2026-01-31 03:51:47 +00:00 by claunia · 0 comments
Owner

Originally created by @Mr-Wallet on GitHub (May 11, 2021).

Windows Terminal version (or Windows build number)

10.0.19041.0

Other Software

No response

Steps to reproduce

Apologies if this is the wrong place to ask this, I was directed from node-pty. I'm trying to hack on top of PowerShell in a JS environment using XTerm.js.

I've been experimenting a lot with ANSI escape sequences and I notice that lots of stuff gets omitted or mangled in highly unpredictable ways. I was hoping for some guidance on why this is happening and what can be done about it, and I'll provide the simplest possible example:

I'd like my terminal program to do some kind of wizardry whenever node-pty outputs a specific ANSI sequence. So I choose some ANSI code which is specified and unlikely to be used by anything else, e.g. ESC [ 1234 z. I try outputting this in my PowerShell Prompt.

Expected Behavior

The behavior on Windows is consistent with that of Mac/Linux shells; the code should appear where it's output, and ideally should persist across resize events.

Actual Behavior

The code is shifted to the far left of the line on which it appears. (If the code is inserted multiple times, all instances are sorted to the far left of the line.) Furthermore, on PTY resize events that trigger a redraw of the screen, the escape code is entirely absent (i.e. even the line on which it appeared can no longer be located simply by looking at the output).

It could be PowerShell, but it's hard to tell since the default terminal that comes with Windows doesn't play very nicely. At any rate it seems suspicious that it would be PS; dropping codes entirely, I could believe, but re-arranging its own stdout? To what end? Using Microsoft Terminal directly, I don't really know how to get at the internals well enough to see what's going on; certainly no codes end up in my clipboard when I try to copy the output.

Is this a limitation of conpty? I notice a lot of other mangling, especially of graphical (SGR) codes. Is every problem with ANSI codes not getting from PowerShell to node-pty essentially the same issue? Does it all come back to #2661 which seems to get linked from almost every issue about ANSI codes? (I'm still very new to these technologies, so sorry if that issue completely explains things and I've simply failed to comprehend.)

Thanks very much for any guidance you can provide on this.

Originally created by @Mr-Wallet on GitHub (May 11, 2021). ### Windows Terminal version (or Windows build number) 10.0.19041.0 ### Other Software _No response_ ### Steps to reproduce Apologies if this is the wrong place to ask this, I was directed from `node-pty`. I'm trying to hack on top of PowerShell in a JS environment using `XTerm.js`. I've been experimenting a lot with ANSI escape sequences and I notice that _lots_ of stuff gets omitted or mangled in highly unpredictable ways. I was hoping for some guidance on why this is happening and what can be done about it, and I'll provide the simplest possible example: I'd like my terminal program to do some kind of wizardry whenever `node-pty` outputs a specific ANSI sequence. So I choose some ANSI code which is specified and unlikely to be used by anything else, e.g. `ESC [ 1234 z`. I try outputting this in my PowerShell `Prompt`. ### Expected Behavior The behavior on Windows is consistent with that of Mac/Linux shells; the code should appear where it's output, and ideally should persist across resize events. ### Actual Behavior The code is shifted to the far left of the line on which it appears. (If the code is inserted multiple times, all instances are sorted to the far left of the line.) Furthermore, on PTY resize events that trigger a redraw of the screen, the escape code is entirely absent (i.e. even the line on which it appeared can no longer be located simply by looking at the output). It could be PowerShell, but it's hard to tell since the default terminal that comes with Windows doesn't play very nicely. At any rate it seems suspicious that it would be PS; dropping codes entirely, I could believe, but re-arranging its own stdout? To what end? Using Microsoft Terminal directly, I don't really know how to get at the internals well enough to see what's going on; certainly no codes end up in my clipboard when I try to copy the output. Is this a limitation of conpty? I notice a lot of other mangling, especially of graphical (SGR) codes. Is every problem with ANSI codes not getting from PowerShell to `node-pty` essentially the same issue? Does it all come back to #2661 which seems to get linked from almost every issue about ANSI codes? (I'm still very new to these technologies, so sorry if that issue completely explains things and I've simply failed to comprehend.) Thanks very much for any guidance you can provide on this.
claunia added the Needs-TriageNeeds-Tag-Fix labels 2026-01-31 03:51:47 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#13775