r-lib / cli

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

Feature request: fallback to a default `code_highlight()` theme if RStudio theme is unavailable #481

Closed rossellhayes closed 2 years ago

rossellhayes commented 2 years ago

If you try to use code_highlight() in RStudio when using a theme that is not included in code_theme_list(), you receive a warning message and the code is returned unhighlighted:

cli::code_highlight("1 + 1")
#> [1] "1 + 1"
#> Warning message:
#> In code_theme_default_rstudio() :
#>   cli does not know this RStudio theme: a11y-dark {rsthemes}

It would be preferable to fallback to a default theme if cli does not recognize the current RStudio theme: perhaps to cli:::code_theme_default_term() or "Textmate (default)". The warning message could be preserved and could also indicate that the user can choose a code highlighting theme using options().

gaborcsardi commented 2 years ago

Thanks, makes sense. Do you want to submit a PR? No pressure. :)

rossellhayes commented 2 years ago

Sure, I can put that together!