ansilove / libansilove

Library for converting ANSI, ASCII, and other formats to PNG
https://www.ansilove.org
BSD 2-Clause "Simplified" License
61 stars 13 forks source link

xterm-256color support #17

Open cmang opened 4 months ago

cmang commented 4 months ago

It would be nice for libansilove to support these escape codes for the xterm-256color palette.

Examples of ANSI editors that export ANSI to this format include Durdraw, which also does Ansilove exporting. This would allow Durdraw to export PNG and GIF files in 256 color, instead of just 16 color. This would also allow sites like 16colo.rs to view these files correctly.

I am looking at the source code... I think the trick would be something like:

1: In config.h: Add the xterm-256color palette as 8-bit hex values 2: In ansi.c: Add interpreters for the 256 color escape codes, the palette generator, and any other logic to deal with color values larger than 16. 3: ??? 4: profit!

If I get some time I will give it a try, or if someone else wants to. This can probably be considered a duplicate of issue https://github.com/ansilove/ansilove/issues/43.

Thanks!

cmang commented 4 months ago

Here is an example 256 color ANSI file with CP437 encoding: xmas-cp437.zip

And how it should look:

Screenshot 2024-07-15 at 3 14 17 PM
cmang commented 4 months ago

A resource for xterm-256 palette information: https://www.ditig.com/publications/256-colors-cheat-sheet

Note that colors 0-15 are not standard. The ones listed there do not match VGA colors. I think they might be the default colors when using classic OG xterm. However, terminals can (and do) set colors 0-15 to however they like, with no real standard.

Personally I think it would be fine for colors 0-15 to use the VGA colors instead of the nonstandard xterm default. I am pretty sure this is what the Linux console uses, and this is how I configure my terminals. This also improves standard DOS/CP437 ANSI art compatibility.

For now, in my little libansilove fork, I am copying colors 0-15 from Ansilove's VGA palette for use in the 256 color palette, instead of using colors 0-15 from the link above.