Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: set options(cli.code_theme) #87

Open
rossellhayes opened this issue Jun 15, 2022 · 2 comments
Open

Feature request: set options(cli.code_theme) #87

rossellhayes opened this issue Jun 15, 2022 · 2 comments

Comments

@rossellhayes
Copy link
Contributor

rossellhayes commented Jun 15, 2022

If cli::code_highlight() is called in RStudio with an unrecognized theme (i.e. a non-builtin theme), it signals a warning and doesn't highlight the code:

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}

This can be avoided by setting options("cli.code_theme"). Here's an example for the theme "base16 Gruvbox dark, soft {rsthemes}":

options(cli.code_theme = list(
  reserved = "#D3869B",
  number = "#FE8019",
  null = "#D65D0E",
  operator = "#8EC07C",
  call = NULL,
  string = "#B8BB26",
  comment = "#BDAE93",
  bracket = list(
    "#8EC07C",
    "#83A598",
    "#FABD2F",
    "#FE8019",
    "#FB4934",
    "#B8BB26",
    "#D3869B"
  )
))

Is it possible to use data from rsthemes to set options("cli.code_theme") when calling use_theme_*()?

@gadenbuie
Copy link
Owner

Ah this would be super cool but it's a lot harder than it looks. rsthemes helps build the .rstheme CSS file used by RStudio, using scss stylesheets. Older versions of themes, like all the base16 themes, were made in pure scss. Newer themes are built via rstheme() but the process is similar: rstheme() orchestrates scss variables and stylesheets.

All this to say, rsthemes doesn't have a reliable source of data for the colors used in a theme other than the .rstheme stylesheet. So we'd have to go parse that to figure out the colors. But this stylesheet is equally available to the RStudio IDE... so in short I think that https://github.com/rstudio/rstudio is probably in a better position to provide this feature.

I'm going to keep it open though in case any ideas occur to me.

@rossellhayes
Copy link
Contributor Author

rossellhayes commented Jun 15, 2022

That makes sense, I think I'll explore how to parse that .rstheme file, at least for my own private use!

Also this will be a smaller concern after r-lib/cli#481

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants