Skip to content

ConPTY translating [49m to [m escape sequence #362

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

Closed
brads55 opened this issue Jan 27, 2019 · 6 comments
Closed

ConPTY translating [49m to [m escape sequence #362

brads55 opened this issue Jan 27, 2019 · 6 comments
Labels
Area-VT Virtual Terminal sequence support Product-Conpty For console issues specifically related to conpty Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.

Comments

@brads55
Copy link

brads55 commented Jan 27, 2019

  • Your Windows build number: (Type ver at a Windows Command Prompt)

Microsoft Windows [Version 10.0.17763.292]

  • What you're doing and what's happening: (Copy & paste specific commands and their output, or include screen shots)

When using the new ConPTY feature it seems there is some behind the scenes optimisation happening surrounding colours that is assuming colour state. For example when using the default background/foreground escape sequences ([49m/[39m), they are either getting removed or changed into a reset sequence ([m), this make it difficult to write a frontend to ConPTY that wants to for example have a window background colour that isn't one of the colours specified by the escape sequences. (i.e. where [m and [49m would do different things).

And example of this is at https://github.com/brads55/conpty-testcase (based on the EchoCon sample), where the following can be seen:

testcase

I also suspect this is the cause of #293.

  • What's wrong / what should be happening instead:

It would be great if either these optimisations didn't happen or there was at least a way of disabling them in order to get the real raw escape sequences.

@DHowett-MSFT
Copy link
Contributor

Hey @brads55, thanks for reporting this! I think this is operating mostly as-expected.

Since CSI 49m is "default background", and the only color you've changed is the background (so far), it's functionally identical to CSI m (reset all attributes).

If you set 32;43m, followed by 49m, you do get a 49m out the other side:

Code:

    wchar_t szCommand[]{ L"bash -c \"echo '\x1b[32;41mABCD\x1b[49mEFGH'\"" };

output

^[[32m^[[41mABCD^[[49mEFGH

This optimization shouldn't have any observable side effects.

#293 is caused by our current inability to support a color outside the palette as the default color; this should be somewhat improved in 19H1, but it won't be perfect yet. I'll add a more detailed comment over there.

@brads55
Copy link
Author

brads55 commented Jan 28, 2019

Hm, that was perhaps a bad example of what I'm seeing. There is certainly something strange going on with what I'm doing as there are seemingly missing colour codes in the output of what I have when compared to a non-conpty terminal. I'll dig into this a bit more and try and come up with a better example (or prove myself wrong!).

@miniksa miniksa added Product-Conhost For issues in the Console codebase Product-Conpty For console issues specifically related to conpty Area-VT Virtual Terminal sequence support and removed Product-Conhost For issues in the Console codebase labels Jan 28, 2019
@zadjii-msft
Copy link
Member

If I had to guess, I'd think that maybe you're emitting something like 37m or 40m, and that's silently getting translated to 39m/49m (or maybe even 0m). In that case, your client app would say "I would like to write text with a foreground of dark white" (37m), but the conpty's "default foreground" color is also set to "dark white", so conpty then emits "I want default foreground text" (39m).

Part of the trick here is that conpty can't just emit the raw escape sequences that are written to it, because it's possible that another attached client is using the Console API to query the state of the console buffer, so we need to both process the VT sequences written to us, then render the effects of both the VT sequences and the API calls to whoever is attached to the conpty side of the console.

@brads55
Copy link
Author

brads55 commented Jan 28, 2019

I haven't had chance to check yet but yes that does seem like exactly what is happening, since what I'm essentially trying to do is exactly what the above comment in the link DHowett-MSFT made describes, that is, set the default background colour to a colour outside of the normal palette.

I see it was noted that this is fixed in 19H1 but not enabled for ConPTY, is this likely to change or will this not be fixed for ConPTY until after 19H1? (I also suppose there is no workaround for this in the mean time?)

@brads55
Copy link
Author

brads55 commented Jan 28, 2019

Looking at this again, yes this is indeed what is happening, a [40m is being removed. Hence this is issue is just a duplicate of #293.

@DHowett-MSFT DHowett-MSFT added the Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing. label Feb 6, 2019
@DHowett-MSFT
Copy link
Contributor

@brads55, thanks for confirming! I'll close this out as a dupe then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-VT Virtual Terminal sequence support Product-Conpty For console issues specifically related to conpty Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.
Projects
None yet
Development

No branches or pull requests

4 participants