Skip to content

Commit 1a7b807

Browse files
committed
Do not fail syntax highlighting in RStudio w/o rstudioapi
Closes #697.
1 parent b7f8259 commit 1a7b807

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
* The `{.obj_type_friendly}` inline style now only shows the first class
99
name (#669 @olivroy).
1010

11+
* Syntax highlighting now does not fail in RStudio if the rstudioapi
12+
package is not installed (#697).
13+
1114
# cli 3.6.2
1215

1316
* `ansi_collapse(x, trunc = 1, style = "head")` now indeed shows one

R/prettycode.R

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,14 @@ code_theme_default <- function() {
240240
if (rs$type %in% c("rstudio_console", "rstudio_console_starting")) {
241241
opt <- code_theme_opt("cli.code_theme_rstudio")
242242
if (!is.null(opt)) return(opt)
243-
code_theme_default_rstudio()
244-
} else {
245-
opt <- code_theme_opt("cli.code_theme_terminal")
246-
if (!is.null(opt)) return(opt)
247-
code_theme_default_term()
243+
if (requireNamespace("rstudioapi", quietly = TRUE)) {
244+
return(code_theme_default_rstudio())
245+
}
248246
}
247+
248+
opt <- code_theme_opt("cli.code_theme_terminal")
249+
if (!is.null(opt)) return(opt)
250+
code_theme_default_term()
249251
}
250252

251253
code_theme_opt <- function(option) {

0 commit comments

Comments
 (0)