ahaoboy / ansi2

Parse ansi strings and convert them to html and svg formats
6 stars 1 forks source link

support ansi default color instead of hard coding to white #7

Open fdncred opened 1 month ago

fdncred commented 1 month ago

The point of default is that your terminal knows what text color contrasts well with your background color. So, on light terminals the text is dark and on dark terminals the text is light. I'm not sure exactly how it works because it's not necessarily index 0 (black) or 15 (white) for the color. On Dark Solarized, which has a kind of green background, it chooses a gray color, which is index 10, 11, or 12. I can submit another issue on this subject. Thanks.

The way I test this in nushell is to set my terminal to any dark theme and do this command.

$"(ansi default)Hi There(ansi reset)"

This also works.

"\e[39mHi There\e[0m"

Then I switch my terminal theme to any light colored theme and repeat the test.

Here it is in Solarized Dark image

Here it is for AtomOneLight image

Here it is for the Wez theme image

ahaoboy commented 1 month ago

vscode image

windows terminal image

There are also some subtle differences in vscode dark mode. I guess it is not to select the existing color, but to make the text color semi-transparent if the two colors are similar. Maybe this requires looking at the source code of vscode or Windows terminal.

fdncred commented 1 month ago

I think you've found a bug in WT and VSCode Terminal. 49 is definitely a background color just like 46, 45, and 44, so the background should be light with dark text. image

But I agree that the 47 and 30 rendering is weird in VSCode Terminal. 30 should be invisible on a black background, so WT looks right in that instance. I think WT is right on 47 too because it's supposed to be white background with white text, so the text should be invisible in this instance. I've definitely read reports about vscode's xterm.js terminal acts wonky sometimes.

ahaoboy commented 1 month ago

Interestingly, only the vscode terminal will display text, maybe there is a magical configuration like raw-ansi that controls this behavior

image image

https://github.com/ahaoboy/ansi2/blob/main/assets/color.ans

ahaoboy commented 1 month ago

@fdncred

hi, can you provide a specific test case and expected output? It seems that ansi2 may need to add a custom color table to support different theme colors

cat ./color.ans | ansi2 --colors=#000000,#800000,#008000,#808000,#000080,#800080,#008080,#c0c0c0,#808080,#ff0000,#00ff00,#ffff00,#0000ff,#ff00ff,#00ffff,#ffffff > color.svg
fdncred commented 1 month ago

Here's a color table I created a long time ago. colortable.ans.txt image

This one is a little crazy but has defaults in it too. sample.ans.txt This one is too large for me to capture a screenshot because it shows all colors fg, bg, and styles

Here's one with just the defaults that nushell supports. Looks like ghostty doesn't support bg 49 either. ansi_default.ans.txt image