Skip to content

Fallback to a default code_highlight() theme if RStudio theme is unavailable #482

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

Merged
merged 3 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ Remotes:
r-lib/rlang
Config/testthat/edition: 3
Encoding: UTF-8
RoxygenNote: 7.1.2.9000
RoxygenNote: 7.2.1.9000
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# cli (development version)

* `code_highlight` now falls to the default theme (instead of no theme) for
unknown RStudio themes (#482, @rossellhayes).

* `cli_abort()` now supplies `.frame` to `abort()`. This fixes an
issue with the `.internal = TRUE` argument (r-lib/rlang#1386).

Expand Down
10 changes: 8 additions & 2 deletions R/prettycode.R
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,14 @@ code_theme_make <- function(theme) {
code_theme_default_rstudio <- function() {
theme <- rstudioapi::getThemeInfo()$editor
if (! theme %in% names(rstudio_themes)) {
warning("cli does not know this RStudio theme: ", theme)
return(list())
if (!getOption("cli.ignore_unknown_rstudio_theme", FALSE)) {
warning(
"cli does not know this RStudio theme: '", theme, "'.",
"\nSet `options(cli.ignore_unknown_rstudio_theme = TRUE)` ",
"to suppress this warning"
)
}
return(code_theme_default_term())
}
rstudio_themes[[theme]]
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-prettycode.R
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ test_that("code_theme_default_rstudio", {
cth <- code_theme_default_rstudio(),
"cli does not know this RStudio theme"
)
expect_equal(cth, list())
expect_equal(cth, code_theme_default_term())
})

test_that("code_theme_list", {
Expand Down
5 changes: 5 additions & 0 deletions vignettes/cli-config-user.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ ANSI hyperlinks.
Set to anything else to assume no hyperlink support.
See [style_hyperlink()].

### `cli.ignore_unknown_rstudio_theme`

Set to `TRUE` to omit a warning for an unknown RStudio theme in
`code_highlight()`.

### `cli.num_colors`

Number of ANSI colors. See [num_ansi_colors()]. See also the
Expand Down