-
Notifications
You must be signed in to change notification settings - Fork 166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for terminal attribute control (ANSI ESC sequences and terminal detection) #140
Comments
winpty scrapes a console's 2D buffer and renders what's visible into terminal escapes. If the Windows console doesn't interpret an escape sequence, then it is drawn into the 2D buffer, and by the time winpty sees an escape character drawn in a cell, it is too late to interpret a command sequence. For example, suppose we have:
The console app:
When the app is run in an ordinary Windows console, the window looks like this (a
Both escape sequences occupy cells in the 2D buffer, and the first one has wrapped around. With winpty, this console window still exists, but is normally hidden. (It can be made visible by setting the environment variable One simple failure mode is that winpty sets the cursor position to line 2, column 13. If it doesn't escape the escape character on line 2, then the cursor will appear to be several cells after the end of the The bigger problem is that winpty also inserts control characters / escape sequences before/after each line. I suspect it would insert a clear-rest-of-line sequence before the winpty generally tries to make the terminal look like the underlying console buffer, so if programs have broken output, like the ones you've linked to, then the programs are usually at fault. They will also have broken output when they're run in a normal console. Fixing them is usually straightforward. The conventional fix is to use
The child program isn't directly running under the terminal, though. It's running inside a Windows console. winpty translates terminal input into |
Thank you for elaboration, understood. I was imaginating that winpty would intercept invocations of WriteConsole* which would be a different base situation. |
Intercepting the APIs would let winpty do a better job (and have lower CPU consumption and latency). I'm not sure there's a reliable way to do that.
With Cygwin, the escape interpretation happens in the Cygwin/MSYS DLL, so the problem can happen if the program running under winpty isn't a Cygwin executable.
Yes. A program may need to be modified to enable the |
@rprichard @mintty I stumbled into this issues because of some issues I'm seeing in my console-based app (more details in perlang-org/perlang#285). The short version:
What you write about here:
...could this be (part of) the solution in my case? 🤔 As noted, the ANSI colour sequences work correctly when executed outside of |
If you run a current version of cygwin on Windows 10, you shouldn't need winpty anymore. If you run MSYS, I suggest to enable ConPTY support by setting MSYS=enable_pcon before starting a terminal; I will add a hint to the wiki. |
Thanks, I tried enabling this now but it doesn't seem to make any difference. I still get the same .NET exception ( The Git Bash I'm using seems to use mintty 3.1.0 (x86_64-pc-msys). It's a fairly old Git for Windows I think ( Do note though (second screenshot in perlang-org/perlang#285) that ANSI colors actually work already, but I guess the "does not have a console" issue should also go away if I manage to get ConPTY support properly enabled? 🤔 A side note which I've experienced is that my app seems to behave differently when compiled as a regular debug/release build with "AnyCPU" vs when I compile it in Release mode, targeting x86-64 specifically and enabling more "release-oriented" flags in the compilation. In the latter case, I don't seem to be detecting the fact that stdin is redirected correctly, so I wonder if something weird is going on here... |
I do not know whether ConPTY catches a low-level attempt to do I/O in a way deliberately incompatible with terminals, you'll need to try. I also don't know whether you environment supports the invocation |
With that in place, everything works perfectly in Git Bash. No more WinPTY hack needed! 🎉 However, when executing Git Bash in the Windows Terminal, ANSI sequences are not being parsed correctly for some super-odd reason: Anyway, this is in no way related to MinTTY, as this is just Thanks for your help, it was really helpful. 👍 |
(Hmm, my problem could be a permutation of git-for-windows/git#2483. I'll ask there for advice.) |
Apparently winpty transforms ESC characters on purpose (#47 and e.g. microsoft/vscode#22616 (comment)).
However, this raises problems with native Windows tools that try to apply ANSI features, esp. colour attributes (e.g. #104 (comment) or git-for-windows/git#1470 (comment)).
The intrinsic use case for winpty is to use it in a traditional terminal and support terminal features for native tools. If such a tool thinks it’s running within such a terminal, it may employ ANSI escapes on purpose. Therefore I think winpty should not filter ESC or unset TERM (#106), at least not by default.
I also don’t understand your statement in fusesource/jansi#64 (comment):
because it’s the nature of the terminal to interpret ANSI controls, and also it’s in contradiction to your previous stance in #35 (comment):
So as suggested from my description, I’m asking to please revert this transformation and pass through ESC controls as well as the TERM environment variable transparently by default; an option may change both simultaneously.
The text was updated successfully, but these errors were encountered: