r-lib / ansistrings

Manipulation of ANSI colored strings
Other
9 stars 5 forks source link

Incorrect translation to html colours #12

Open hadley opened 6 years ago

hadley commented 6 years ago
ansistrings::ansi_to_html(crayon::make_style("orange")("orange"))

Generates http://www.color-hex.com/color/ff87ff not http://www.color-hex.com/color/ffa500

rgb(t(col2rgb("orange")), maxColorValue = 255)
gaborcsardi commented 6 years ago

Since crayon interpolates the colors, ansi_to_html does the same. So you typically don't get the same RGB color back.

I used a free color theme to generate the RGB numbers, but this one seems to be quite far indeed. Will check.

jimhester commented 6 years ago

https://github.com/rtomayko/bcat/blob/master/lib/bcat/ansi.rb and https://github.com/rburns/ansi-to-html/blob/master/src/ansi_to_html.js are two packages in other languages doing this same conversion. Might be worth comparing their values to what we are using.

jimhester commented 6 years ago

Also here are the color translations that the IDE uses for each 256 color code for each theme in the IDE.

https://github.com/rstudio/rstudio/blob/a39dabf8cd4088fbfaf894cc1e24b12af38ee54f/src/gwt/tools/compile-themes.R#L276