xterm.js icon indicating copy to clipboard operation
xterm.js copied to clipboard

Handling transparent BG color when used as FG

Open Eugeny opened this issue 6 years ago • 19 comments

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.

Eugeny avatar Jan 16 '19 17:01 Eugeny

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

chabou avatar Jan 27 '19 17:01 chabou

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

I can make a PR

chabou avatar Jan 27 '19 17:01 chabou

I think having an invertedForeground would be a more flexible solution

Eugeny avatar Jan 27 '19 18:01 Eugeny

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).

Tyriar avatar Jan 27 '19 19:01 Tyriar

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

Eugeny avatar Jan 27 '19 19:01 Eugeny

@Eugeny That's what I mean :)

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

chabou avatar Jan 27 '19 20:01 chabou

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

sukima avatar Apr 12 '19 14:04 sukima

@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:

  • https://github.com/xtermjs/xterm.js/blob/master/src/renderer/TextRenderLayer.ts
  • https://github.com/xtermjs/xterm.js/blob/master/src/renderer/dom/DomRendererRowFactory.ts

Tyriar avatar Apr 12 '19 15:04 Tyriar

@Tyriar here's my attempt at this for the WebGL renderer: https://github.com/Eugeny/xterm.js/commit/cf4830442a76cb71af66b66cc257e11ad58cdd02

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

Eugeny avatar Oct 18 '19 21:10 Eugeny

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

@Eugeny isn't this blocked on https://github.com/xtermjs/xterm.js/issues/2252 for webgl?

Tyriar avatar Oct 19 '19 01:10 Tyriar

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

Eugeny avatar Oct 19 '19 02:10 Eugeny

We need to translate transparent to #000000 here:

https://github.com/xtermjs/xterm.js/blob/8b5c48fe878f830914248e4c1ed78e621deb16c4/addons/xterm-addon-webgl/src/atlas/WebglCharAtlas.ts#L231-L236

Tyriar avatar Nov 26 '19 16:11 Tyriar

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

Eugeny avatar Mar 16 '20 20:03 Eugeny

@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?

jerch avatar Mar 18 '20 15:03 jerch

@jerch the idea is not to make inverted FG transparent, but rather ignore the alpha part of BG: https://github.com/xtermjs/xterm.js/issues/1898#issuecomment-457948917

Eugeny avatar Mar 18 '20 15:03 Eugeny

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.

Eugeny avatar Mar 13 '21 20:03 Eugeny

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

sriramkandukuri avatar Jun 20 '21 03:06 sriramkandukuri

@Eugeny I think this should be relatively easy to fix if you want to give it a try: https://github.com/xtermjs/xterm.js/issues/1898#issuecomment-558714261

Basically something like:

if (color is transparent) {
  set to black
}

Tyriar avatar Jul 06 '21 21:07 Tyriar

@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".

Eugeny avatar Jul 10 '21 16:07 Eugeny