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

Add support for OSC 10 and 11 to set the default colors #891

Merged
merged 11 commits into from
May 24, 2019

Conversation

Jaykul
Copy link
Contributor

@Jaykul Jaykul commented May 18, 2019

Add support for OSC 10 and 11 to set the default colors

Supports setting the rgb value for the default foreground and background (but no support for querying yet, same as OSC 4)

PR Checklist

This adds support for OSC 10 to set the default foreground color and OSC 11 to set the default background color (just as if they were set in the profiles.json, except that the settings are not changes, so they can be reloaded).

I have not implemented querying (which is also mentioned in #317), so this only addresses one item in the list.

I have not really added any unit tests -- I'm happy to do so, but unsure where they should go, or what they look like. I found some mocks for the other OSC codes, and implemented those, but didn't spot tests.

src/host/getset.cpp Outdated Show resolved Hide resolved
src/host/outputStream.cpp Outdated Show resolved Hide resolved
@vapier
Copy link

vapier commented May 18, 2019

i don't think this correctly handles chaining to following OSC sequences. if you have \e]10;green;white\a, that should be the same as if you had \e]10;green\a and \e]11;white\a. seeing as how OSC 10/11 are from xterm, and xterm defines that chaining behavior, seems like it should be supported. it would chain further to OSC 12 and such if they were implemented ...

at a glance, looks like OSC 4 isn't quite handled well either, but i think that's a known bug.

src/host/getset.cpp Outdated Show resolved Hide resolved
src/terminal/adapter/ITermDispatch.hpp Show resolved Hide resolved
@Jaykul Jaykul force-pushed the dev/jaykul/SettableDefaultColors branch from 873e4c4 to 436a4d7 Compare May 18, 2019 19:27
@DHowett-MSFT
Copy link
Contributor

@Jaykul hey, congrats on being the first external person to spelunk through terminal, conpty and conhost to add a new feature! Thanks, this is really cool.

I'm requesting review from the two people who know the area best. 😄

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also make sure to add a test for these guys. The right place to do this might be in ScreenBufferTests.cpp - there are a lot of tests in there that use VT to set the colors and check them again.

I have a few minor notes about making sure there are doc comments, but otherwise great job 👍

src/cascadia/TerminalControl/TermControl.cpp Show resolved Hide resolved
src/cascadia/TerminalControl/TermControl.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalCore/TerminalApi.cpp Show resolved Hide resolved
src/terminal/adapter/adaptDispatch.cpp Show resolved Hide resolved
src/terminal/parser/OutputStateMachineEngine.cpp Outdated Show resolved Hide resolved
src/terminal/parser/OutputStateMachineEngine.hpp Outdated Show resolved Hide resolved
@ghost ghost added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels May 20, 2019
StateMachine& stateMachine = mainBuffer.GetStateMachine();

const COLORREF originalColor = gci.GetDefaultBackgroundColor();
const COLORREF testColor = RGB(0x33, 0x66, 0x99);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just on a lark: can we test things that go outside the 0-255 or 0-ff (?) range? some negative cases and some cases for longer inputs might be interesting to see

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but the parser for that isn't my code (I re-used the existing color parser).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added just a couple. How deep do you want to go? They're all just going to silently do nothing unless we find a bug in the parsers.

There should probably be (maybe there are) unit tests for the color parser already?

@Jaykul Jaykul force-pushed the dev/jaykul/SettableDefaultColors branch from 94ec7f9 to 6481719 Compare May 22, 2019 05:46
@Jaykul
Copy link
Contributor Author

Jaykul commented May 22, 2019

@vapier wrote:

i don't think this correctly handles chaining to following OSC sequences.

That's correct. It doesn't handle chaining at all. It also doesn't handle color names.

Since this was my first PR, I was trying not to rewrite, but to just add a little on top of what was there and learn how things work -- I even reused the color parser that was written for OSC 4, though it won't support color names, meaning you can only set RGB values, and not just reuse colors from your base 16 for foreground and background.

The structure of the OSC handler in the State Machine seems designed on the assumption that they are single-valued (meaning one value per escape sequence), which makes chaining basically impossible.

Basically, still to do:

  1. Rewrite the ActionOscDispatch to support chains of values
  2. Make OSC 4 support setting the whole color palette at once
  3. Make OSC 10, 11, 12 support setting all of them at once
  4. Add support for lookups ("?") to output the current value
  5. Add support for resetting colors (OSC 104..119)
  6. Rewrite the color parser to include x11 color names

Those things are definitely needed, but didn't seem necessary for a first pass.

Somewhere along the way someone will need to decide if we're going to do special colors for bold/italic/underline/blink/reverse ... and which window properties should be settable by OSC 3 😉 @oising?

@Jaykul
Copy link
Contributor Author

Jaykul commented May 22, 2019

This latest build is failing TestDbcsBisectWriteCellsBeginW but I'm not sure what that is.
I'll have to look at it tomorrow.

@vapier
Copy link

vapier commented May 22, 2019

I'm not sure if missing support for multiple parameters is worse than not supporting it at all. Not saying you need to fix the world before making any progress, but certainly both multi value sequences (OSC 4 & OSC 10+) need fixing at some point before the VT parser could be considered reliable.

Is there a document somewhere in the code base noting known deficiencies (i.e. known issues)? That'd be useful for users too.

I'm just making observations from the sidelines ... I'm not a developer for this project ;).

@zadjii-msft
Copy link
Member

I'm not sure if missing support for multiple parameters is worse than not supporting it at all.

I will say as a developer for this project and say that missing support for multiple parameters is not worse than not supporting it at all.

While we don't technically have a complete parser without support for multi-param OSC sequences, we definitely have a good enough parser without them. While we won't reliably work with 100% of scenarios, we do work well enough with 99% of scenarios that are actually used. We've been working on the VT implementation iteratively, and getting better with each release. Someday soon we may even have 100% compatibility.

I've moved this discussion to #942, so we can track adding support there.


@Jaykul That's one of those tests that's just a little flaky. I'll re-run the CI, it should go away.

@zadjii-msft
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@miniksa miniksa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, very good. Great job following the existing style/pattern as you implemented it. I fully agree that it's important to work incrementally here and get something going and then improve.

I mostly had nitpicks for a quick fix before commit and a few things that probably need to be turned into future work Issues.

Send a little cleanup revision and I'll swap to Approve and we can get this merged.

Thank you very much for your contribution!

src/cascadia/TerminalCore/TerminalDispatch.cpp Outdated Show resolved Hide resolved
src/host/outputStream.cpp Outdated Show resolved Hide resolved
src/host/ut_host/ScreenBufferTests.cpp Show resolved Hide resolved
src/host/ut_host/ScreenBufferTests.cpp Outdated Show resolved Hide resolved
src/terminal/adapter/adaptDispatch.cpp Outdated Show resolved Hide resolved
src/terminal/adapter/adaptDispatch.hpp Outdated Show resolved Hide resolved
src/terminal/adapter/ut_adapter/adapterTest.cpp Outdated Show resolved Hide resolved
src/terminal/parser/OutputStateMachineEngine.hpp Outdated Show resolved Hide resolved
@ghost ghost added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels May 22, 2019
@Jaykul Jaykul force-pushed the dev/jaykul/SettableDefaultColors branch from cf57467 to ea978ed Compare May 24, 2019 06:18
@Jaykul
Copy link
Contributor Author

Jaykul commented May 24, 2019

Rebased on current master (to handle merge issues)

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, and thanks for adding some tests :)

Copy link
Member

@miniksa miniksa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. Thank you for your contribution!

@miniksa miniksa merged commit efd6999 into microsoft:master May 24, 2019
@Jaykul Jaykul deleted the dev/jaykul/SettableDefaultColors branch May 24, 2019 19:16
@d-bingham d-bingham mentioned this pull request May 29, 2019
5 tasks
@werner-1
Copy link

werner-1 commented Sep 10, 2020

Sorry if this is the wrong place to ask, but how do I use this?
I tried printf %b '\033]11;#200000\007' in wsl to no effect.
in both Terminal and Terminal Preview

@DHowett
Copy link
Member

DHowett commented Sep 11, 2020

The color format that the xterm color OSCs take is certainly strange 😄 it's rgb:RR/GG/BB in hex.

You'll want to try printf '\033]11;rgb:20/00/00\a'

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

Successfully merging this pull request may close these issues.

Please finish support for OSC 4 and friends
10 participants