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

Allow theming with arbitrary CSS color strings #1346

Merged
merged 3 commits into from
Mar 30, 2018

Conversation

bgw
Copy link
Member

@bgw bgw commented Mar 22, 2018

This mostly worked before, but clearColor made the assumption that the colors were always in #RRGGBB format. See the discussion here: #1327 (comment)

This changes the internal representation of a color so that we hold onto into an object containing the original css string along with an RGBA value encoded as a 32-bit uint. clearColor can then use that RGBA representation.

Additionally, this deduplicates some code between ColorManager and Terminal. Terminal was generating the 256 ansi colors the same way ColorManager was, so this just makes Terminal use the same constant.

256 colors still works:

and so does the 24-bit color approximation:

The static char atlas looks sane, so clearColor is working:

We can change the theme using arbitrary css strings:

And clearColor still works properly, but now using a pink background:

@mofux
Copy link
Contributor

mofux commented Mar 22, 2018

Really nice PR, this is addressing one of the bigger areas of concern, thanks!

If I'm reading the code correctly, passing alpha values like rgba(255,255,255,0.5) will result in a color with the alpha removed, no? This shouldn't be a big problem in general, except for the selection color that needs some alpha at the moment to not hide the characters underneath.

There's also one test failling:

Error: Not implemented: HTMLCanvasElement.prototype.getContext (without installing the canvas npm package) undefined
      1) "before each" hook for "should fill all colors with values"

@@ -2233,38 +2233,6 @@ function wasMondifierKeyOnlyEvent(ev: KeyboardEvent): boolean {
* ANSI color code.
*/

// Colors 0-15 + 16-255
// Much thanks to TooTallNate for writing this.
const vcolors: number[][] = (function(): number[][] {
Copy link
Member

Choose a reason for hiding this comment

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

I've wanted this gone for a long time 😛

@Tyriar
Copy link
Member

Tyriar commented Mar 22, 2018

This looks great, I haven't tested the code but if everything works fine and the tests pass then I'm 👍

@bgw
Copy link
Member Author

bgw commented Mar 23, 2018

I've fixed the test, and amended the commit!

If I'm reading the code correctly, passing alpha values like rgba(255,255,255,0.5) will result in a color with the alpha removed, no?

This parses alpha channels.

This shouldn't be a big problem in general, except for the selection color that needs some alpha at the moment to not hide the characters underneath.

Selections work as expected. They're partially transparent.

@@ -17,261 +17,272 @@ describe('ColorManager', () => {
dom = new jsdom.JSDOM('');
window = dom.window;
document = window.document;
(<any>window).HTMLCanvasElement.prototype.getContext = () => ({
Copy link
Member Author

Choose a reason for hiding this comment

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

It might make sense to pull in node-canvas (which JSDom integrates with) as a dev dependency if we want to test more rendering-related codepaths, but this works for now.

Copy link
Member

Choose a reason for hiding this comment

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

I want to improve the testing situation, I was thinking about puppeteer but I'm not sure if that's the right tool for the job thinking about it some more. #1247

This mostly worked before, but clearColor made the assumption that the
colors were always in #RRBBGG format. See the discussion here:
xtermjs#1327 (comment)

This changes the internal representation of a color so that we hold onto
into an object containing the original css string along with an RGBA
value encoded as a 32-bit uint. clearColor can then use that RGBA
representation.

Additionally, this deduplicates some code between ColorManager and
Terminal. Terminal was generating the 256 ansi colors the same way
ColorManager was, so this just makes Terminal use the same constant.
@bgw
Copy link
Member Author

bgw commented Mar 30, 2018

I merged bgw#2 (Block transparent colors without allowTransparency) into this PR, and I'm not aware of any outstanding issues, so I think this is ready to be merged.

I'll do the node-canvas stuff as a separate PR once this stuff lands.

@Tyriar
Copy link
Member

Tyriar commented Mar 30, 2018

Thanks @bgw 👍

@Tyriar Tyriar merged commit d4b75e4 into xtermjs:master Mar 30, 2018
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.

3 participants