Skip to content

Commit

Permalink
Turning off ANSI also turns off hyperlinks
Browse files Browse the repository at this point in the history
Closes #447.
  • Loading branch information
gaborcsardi committed Apr 21, 2022
1 parent 3d98c15 commit f9d5319
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

* `ansi_*()` functions support ANSI hyperlinks again (#444).

* Turning off ANSI colors via the `cli.num_colors` option or the
`R_CLI_NUM_COLORS` or the `NO_COLOR` environment variable now also turns off
ANSI hyperlinks (#447).

# cli 3.2.0

## Breaking change
Expand Down
9 changes: 9 additions & 0 deletions R/ansi-hyperlink.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ ansi_has_hyperlink_support <- function() {
enabled <- Sys.getenv("R_CLI_HYPERLINKS", "")
if (isTRUE(as.logical(enabled))){ return(TRUE) }

## If ANSI support is off, then this is off as well
opt <- as.integer(getOption("cli.num_colors", NULL))[1]
if (!is.na(opt) && opt == 1) return(FALSE)
env <- as.integer(Sys.getenv("R_CLI_NUM_COLORS", ""))[1]
if (!is.na(env) && env == 1) return(FALSE)
cray_opt <- as.logical(getOption("crayon.enabled", NULL))[1]
if (!is.na(cray_opt) && !cray_opt) return(FALSE)
if (!is.na(Sys.getenv("NO_COLOR", NA_character_))) return(FALSE)

## environment variable used by RStudio
enabled <- Sys.getenv("RSTUDIO_CLI_HYPERLINKS", "")
if (isTRUE(as.logical(enabled))){ return(TRUE) }
Expand Down

0 comments on commit f9d5319

Please sign in to comment.