Skip to content

Commit

Permalink
Do not fail syntax highlighting in RStudio w/o rstudioapi
Browse files Browse the repository at this point in the history
Closes #697.
  • Loading branch information
gaborcsardi committed Jun 20, 2024
1 parent b7f8259 commit 1a7b807
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
* The `{.obj_type_friendly}` inline style now only shows the first class
name (#669 @olivroy).

* Syntax highlighting now does not fail in RStudio if the rstudioapi
package is not installed (#697).

# cli 3.6.2

* `ansi_collapse(x, trunc = 1, style = "head")` now indeed shows one
Expand Down
12 changes: 7 additions & 5 deletions R/prettycode.R
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,14 @@ code_theme_default <- function() {
if (rs$type %in% c("rstudio_console", "rstudio_console_starting")) {
opt <- code_theme_opt("cli.code_theme_rstudio")
if (!is.null(opt)) return(opt)
code_theme_default_rstudio()
} else {
opt <- code_theme_opt("cli.code_theme_terminal")
if (!is.null(opt)) return(opt)
code_theme_default_term()
if (requireNamespace("rstudioapi", quietly = TRUE)) {
return(code_theme_default_rstudio())
}
}

opt <- code_theme_opt("cli.code_theme_terminal")
if (!is.null(opt)) return(opt)
code_theme_default_term()
}

code_theme_opt <- function(option) {
Expand Down

0 comments on commit 1a7b807

Please sign in to comment.