How to convert ANSI color to RGB and in the opposite state (RGB -> ANSI)?

138 Views Asked by At

I could not find information about how I can translate ansi colors to RGB/HEX.
If you know the answer to this question or are ready to share a link, I will be very glad

I want to get the RGB color code from its ANSI encoding. The language is predominantly dart

1

There are 1 best solutions below

0
Giacomo Catenazzi On

The colours were never truly specified, so there is no one single way.

But Wikipedia has a table with common RGB values of ESC sequences on different terminals: https://en.wikipedia.org/wiki/ANSI_escape_code#Colors So you should start from there and select one terminal preference. The contrary may be easier (there are not many colours): but in such case transform RGB into HSL, and now with H you can easily separate colours.