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

Handling transparent BG color when used as FG #1898

Open
Eugeny opened this issue Jan 16, 2019 · 19 comments · Fixed by #2560
Open

Handling transparent BG color when used as FG #1898

Eugeny opened this issue Jan 16, 2019 · 19 comments · Fixed by #2560

Comments

@Eugeny
Copy link
Member

Eugeny commented Jan 16, 2019

Nano displays its shortcuts with FG/BG colors reversed:
image

However, when theme BG is transparent, following happens:
image

The solution could be to have a separate flag that will render characters with no background as if background were transparent instead of theme.backgroundColor, but will still use the actual color for inverted elements.

@chabou
Copy link
Contributor

chabou commented Jan 27, 2019

I think it could work if alpha is forced to 1 when using background color as inverted foreground color.

@chabou
Copy link
Contributor

chabou commented Jan 27, 2019

Or do you want a new invertedForeground in theme (defaulted to backgroundColor)?

I can make a PR

@Eugeny
Copy link
Member Author

Eugeny commented Jan 27, 2019

I think having an invertedForeground would be a more flexible solution

@Tyriar
Copy link
Member

Tyriar commented Jan 27, 2019

I think it could work if alpha is forced to 1 when using background color as inverted foreground color.

In the interest of keeping the API simpler/slimmer I think this option would work fine, unless there's a real case where an alpha of 1 doesn't make sense (we already force alpha 1 on cells with background when background transparency is on).

@Eugeny
Copy link
Member Author

Eugeny commented Jan 27, 2019

@Tyriar if you mean forcing the alpha component of backgroundColor to 1 while keeping its RGB as is, I'm in.

@chabou
Copy link
Contributor

chabou commented Jan 27, 2019

@Eugeny That's what I mean :)

@Tyriar I'll try to work on a PR with this solution soon.

@sukima
Copy link

sukima commented Apr 12, 2019

@chabou What is the status of this? How can we help? This issue is blocker for me!

@Tyriar
Copy link
Member

Tyriar commented Apr 12, 2019

@sukima we're just waiting on a PR for this if you want to work on it. The proposal above is to when the bg color is used as the fg then always force alpha to be 1 (opaque). This will need to be handled in both canvas and dom renderers:

@Eugeny
Copy link
Member Author

Eugeny commented Oct 18, 2019

@Tyriar here's my attempt at this for the WebGL renderer: Eugeny@cf48304

However, even though the color logic is fine, it leads to the reverse text looking "chipped" - see here:
image

@Tyriar
Copy link
Member

Tyriar commented Oct 19, 2019

I made a comment earlier but deleted it as it wasn't even using your branch... 🤦‍♂

@Eugeny isn't this blocked on #2252 for webgl?

@Eugeny
Copy link
Member Author

Eugeny commented Oct 19, 2019

This needs to be done for both renderers - I just started with the webgl one for no specific reason.

@Tyriar
Copy link
Member

Tyriar commented Nov 26, 2019

We need to translate transparent to #000000 here:

const bg = this._config.colors.background.css;
if (bg.length === 9) {
// Remove bg alpha channel if present
return bg.substr(0, 7);
}
return bg;

@Tyriar Tyriar reopened this Nov 26, 2019
@Tyriar Tyriar added this to the 4.3.0 milestone Nov 26, 2019
@Tyriar Tyriar modified the milestones: 4.3.0, 4.4.0 Dec 5, 2019
@Tyriar Tyriar self-assigned this Dec 5, 2019
@Tyriar Tyriar removed this from the 4.4.0 milestone Feb 3, 2020
@Eugeny
Copy link
Member Author

Eugeny commented Mar 16, 2020

Hey guys, is there anything I could do to help you fix this in the WebGL renderer as well?

@jerch
Copy link
Member

jerch commented Mar 18, 2020

@Tyriar
On a sidenote: Since we somehow support transparent already for BG, we could extend official support for it in SGR by allowing SGR 48 : 1. The 1 is meant as transparent following the official specs. Not sure though about FG here, no clue how we could even draw that with the DOM renderer (while other renderers could use erase masks). Also, full transparency seems not very useful for FG to me, to begin with. How is a transparent BG supposed to be translated into FG for inverted colors?

@Eugeny
Copy link
Member Author

Eugeny commented Mar 18, 2020

@jerch the idea is not to make inverted FG transparent, but rather ignore the alpha part of BG: #1898 (comment)

@Eugeny
Copy link
Member Author

Eugeny commented Mar 13, 2021

Could anyone who knows his way around the renderer take a second look at this? It's pretty much prevents widespread adoption of the webgl renderer.

@sriramkandukuri
Copy link

Hi, Any update on this, webgl still has the issue.

@Tyriar
Copy link
Member

Tyriar commented Jul 6, 2021

@Eugeny I think this should be relatively easy to fix if you want to give it a try: #1898 (comment)

Basically something like:

if (color is transparent) {
  set to black
}

@Eugeny
Copy link
Member Author

Eugeny commented Jul 10, 2021

@Tyriar the color was already #00000000 at that point. There seems to be some weird handling specifically for #000 in place:

When _getForegroundCss() == '#000000':

image

When _getForegroundCss() == '#010101':

image

When _getForegroundCss() == '#808080':

image

Note how higher values make the text less "deep fried".

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

Successfully merging a pull request may close this issue.

6 participants