microsoft / node-pty

Fork pseudoterminals in Node.JS
Other
1.47k stars 242 forks source link

Some ANSI sequences are treated strangely on Windows #475

Closed Mr-Wallet closed 3 years ago

Mr-Wallet commented 3 years ago

Environment details

Issue description

I'd like my terminal program to do some kind of wizardry whenever XTerm.js sees a specific output from any source whatsoever. So I choose some ANSI code which is specified and unlikely to be used by anything else, say... ESC [ 1234 z. I try outputting this in my PowerShell prompt.

What I've noticed is that any code like this, when it's first output, is shifted to the far left of the line on which it appears before it even reaches XTerm. Furthermore, on PTY resize events that trigger a redraw of the screen, the code is entirely absent. This is completely different from Mac/Linux, where the character appears exactly where written, and persists across resize events. This issue is present in the data callback from node-pty, so it doesn't seem like an XTerm problem.

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?

What I would hope is that the behavior on Windows is consistent with that of Is this yet another limitation of conpty? Am I failing to set a configuration option? Is this an issue with node-pty itself? Is PowerShell meddling with its own output? Thanks for any guidance you can offer.

jerch commented 3 years ago

My closest guess is ConPty - it kinda acts as an intermediate emulator rewriting things to get the transition from classical direct console buffer access to a pty-like data stream done. Chances are high that it would discard unknown things. node-pty itself does not further alter the data it receives from the OS interface provided by ConPty.

For ConPty issues or window-terminal in general maybe try asking here: https://github.com/microsoft/terminal.

Mr-Wallet commented 3 years ago

I had a feeling but I didn't want to take this all the way there without finding out what node-pty was up to. I'm still learning the exact distinctions and what each part of this stack is responsible for. It took me a lot of debugging to talk myself out of opening an issue on XTerm.js first. 😅 Thank you for confirming that node-pty isn't doing any of its own manipulations.

Tyriar commented 3 years ago

For anything that might be conpty the best approach is testing it out in Windows Terminal, if it works there it means one of these:

Let's close this but feel free to comment if you don't see it in WT.