r-lib / cli

Tools for making beautiful & useful command line interfaces
https://cli.r-lib.org/
Other
625 stars 66 forks source link

With `cli::col_bg_white()`, could text be black by default? #693

Closed olivroy closed 2 weeks ago

olivroy commented 1 month ago

In light theme, it looks pretty good.

with theme = Chrome:

cli::bg_white("aaa")

image

On some dark themes, for example, using

rstudioapi::applyTheme('Cobalt')

image

text is not readable.

Could the default be tweaked a bit ? or otherwise, is there a way I can do I do this myself?

Text seems to appear white by default in most bg_*() fn, but on bg_cyan, bg_green, bg_yellow black text seems to be a better choice for readability.

trevorld commented 1 month ago

You can explicitly set both the background color and foreground color using combine_ansi_styles() e.g.

library(cli)
black_on_white <- combine_ansi_styles(bg_white, col_black)
black_on_white("aaa")

If you're terminal has "truecolor" support then instead of using the system palette "colors" you can even explicitly set the foreground/background colors using "#RRGGBB" color strings using make_ansi_style() (with combine_ansi_styles()).

gaborcsardi commented 2 weeks ago

Yeah, we set bg and fg colors independently, and I think for simplicity we should keep it that way.