Skip to content
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

Pass ANSI Escape Sequences up to the Console #406

Closed
austinwagner opened this issue May 20, 2016 · 20 comments
Closed

Pass ANSI Escape Sequences up to the Console #406

austinwagner opened this issue May 20, 2016 · 20 comments
Labels

Comments

@austinwagner
Copy link

Currently ConEmu cannot process escape codes generated by applications running under the Windows Subsystem for Linux because they are processed before they can reach ConEmu (as stated in Maximus5/ConEmu#573). These sequences should be passed along to be handled at the console level.

@musm
Copy link

musm commented Jul 8, 2016

Desperately needed. I mean apple fanboys always try to show off with fancy iterm2, while I hide in the corner living in an 8-bit world.

@rfc1459
Copy link

rfc1459 commented Aug 4, 2016

This not only breaks (potential) 256 color support, but also causes serious issues with basic ANSI functionality (arrow keys among other things - which have been worked around in ConEmu).

Simple reproducer for ANSI reverse:

printf "Normal\n\x1b[7mReverse\x1b[0m\nNormal\n"

The "reverse" sequence is silently swallowed and interpreted locally by the console emulation layer before it can reach ConEmu, so in plain bash.exe it would display "Reverse" with fg/bg swapped, but in ConEmu fg and bg are not swapped.

If you want a more complex reproducer, fire up aptitude in both plain bash.exe and ConEmu: the former will correctly highlight the current item, the latter won't because aptitude uses ANSI reverse for the current item.

@ysc3839
Copy link

ysc3839 commented Oct 7, 2016

The bash.exe uses SetConsoleMode setted ENABLE_VIRTUAL_TERMINAL_PROCESSING (MSDN). And we can get original ANSI sequences after disable it.
1

@Maximus5
Copy link

We can't get original ANSI. They are written directly into conhost memory. That means one console line would have few chars instead of full line of data.

@antitoxic
Copy link

I am also looking forward this. ref: #345 (comment)

@ysc3839 how do I do this? Are you sure it's possible?

@ysc3839
Copy link

ysc3839 commented Oct 19, 2016

@antitoxic I hooked SetConsoleMode then clear the ENABLE_VIRTUAL_TERMINAL_PROCESSING bit. But ConEmu can't process them.

@be5invis
Copy link

@Maximus5 We should push for the official PTY API, instead of hooking.

@Maximus5
Copy link

There would be no new API. Example of the answer: #345 (comment)

@be5invis
Copy link

@Maximus5 It’s the API for implementing an alternative terminal, instead of an API for writing text in 24 bit colors (or something like that).

@be5invis
Copy link

cf. #1117

@zadjii-msft
Copy link
Member

I agree with @be5invis. Hooking is bad. If you want to hook the console to make your own, then you can go ahead and parse the VT sequences yourself too :p

@Maximus5
Copy link

Unless Microsoft would provide official way to implement pty interface, the hooking is only possible technique.
And of course, it has no sense to read VT sequences from console surface because: a) third-party terminal (ConEmu) can't realize what was a sequence and what was some RAW data; b) unprocessed VT sequences takes a lot more cells than processes, so "full screen" applications like Vim would not work at all.

@zadjii-msft
Copy link
Member

a) you'd have to implement a VT parser, and have your own mechanism for determining if it's enabled or not. No, technically there's no way to determine if the output is a sequence or not, but that's because most terminals just assume that it is.

b) That they do. you'd have to assume that the conhost buffer is garbage, and manage it all on your own.

Again, we're not supporting hooking, and in the most general and vague way possible, we'll have some things to announce in the future that you'll all be very happy about, but we've got a lot to do before that

@Maximus5
Copy link

a) VT parser was implemented in ConEmu years ago. But any application may write to conhost buffer via WriteConsoleOutput. And these sequences are not valid VT sequences. Without hooking or the imaginary pty API ConEmu can't distinct them.

b) I can't. Due to a). And disability to understand are sequences were enabled or disabled. Without hooking I can't restrict bash to turn on 0x200 flag, and even if it would be dropped by ConEmu hooks, there would be absolutely no guarantee that some other application, attached to this console, is not trying to use native WinAPI instead of VT.

So, when it really would be possible, I'll be happy to go of hooking, but till than there is no other way. If you are interested in, hooking is used for many other things in ConEmu. For example, GetConsoleWindow have to return ConEmu window instead of conhost, otherwise applications would work improperly when they use console HWND.

@be5invis
Copy link

@zadjii-msft So, to avoid hooking, we NEED a PTY API which makes us able to implement an alternative console host, and things like tmux. This thing is missing since the creation of Windows. It's been 30 years, bro.

nta added a commit to nta/clink that referenced this issue Nov 6, 2016
@rdeforest
Copy link

rdeforest commented Jul 10, 2017

Was going to submit a bug but it would have been a dupe of this one I think. I too see problems in aptitude as of Windows build 16237. I'd include a screenshot, but it's so easy to repro it would add nothing.

If the bug isn't obvious as soon as you run aptitude, try navigating (down arrow or 'j' or whatever).

Edit for correction: the problem I'm having may be slightly different. Text is ending up in the wrong locations so that in the aptitude example (the only program I've seen so far with the behavior) the "New Packages" heading is drawn on line 3, the cursor is on line 4, and when I navigate the headings are re-drawn one line down as they are highlighted and de-highlighted. Looks like a cursor position surprise of some sort. Also this happens in and out of GNU Screen.

@bitcrazed
Copy link
Contributor

Thanks for the discussion.

Closing this issue since:

  1. We're working on a feature that will remedy this issue for @Maximus5 & others
  2. This is the WSL issues repo, but this is an issue in Console which has its own Console GitHub Repo
  3. GitHub doesn't allow issues to be moved between repos, preserving posters' identity :(

If you have further asks/issues, please file new issues on our Console GitHub Repo.

@samvv
Copy link

samvv commented Jan 17, 2024

@bitcrazed What feature were you referring to? I'm still not able to create true colors using WSL 2 and Ubuntu 22.04.

@zadjii-msft
Copy link
Member

@samvv How have you tried so far? RGB color support has shipped in the console for like, 5 years now. curl https://raw.githubusercontent.com/csdvrx/sixel-testsuite/master/ansi-vte52.sh | bash will get you something like:

image

If you're still having troubles, I'd recommend opening a new issue over on the Terminal repo.

@samvv
Copy link

samvv commented Jan 17, 2024

Thanks for the link. I'll be sure to check it tomorrow and open a new issue if it still is relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests