Skip to content

Commit

Permalink
Merge pull request #1701 from r-lib/fix/links-wo-rstudio
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborcsardi authored Sep 29, 2022
2 parents 63dce2d + d8da03c commit e2c70e1
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ Config/testthat/edition: 3
Config/testthat/start-first: watcher, parallel*
Encoding: UTF-8
Roxygen: list(markdown = TRUE, r6 = FALSE)
RoxygenNote: 7.2.1
RoxygenNote: 7.2.1.9000
9 changes: 7 additions & 2 deletions R/local.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ local_test_context <- function(.env = parent.frame()) {
#' @export
#' @param width Value of the `"width"` option.
#' @param crayon Determines whether or not crayon (now cli) colour
#' and hyperlink styles should be applied.
#' should be applied.
#' @param unicode Value of the `"cli.unicode"` option.
#' The test is skipped if `` l10n_info()$`UTF-8` `` is `FALSE`.
#' @param rstudio Should we pretend that we're inside of RStudio?
#' @param hyperlinks Should we use ANSI hyperlinks.
#' @param lang Optionally, supply a BCP47 language code to set the language
#' used for translating error messages. This is a lower case two letter
#' [ISO 639 country code](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes),
Expand All @@ -96,6 +97,7 @@ local_reproducible_output <- function(width = 80,
crayon = FALSE,
unicode = FALSE,
rstudio = FALSE,
hyperlinks = FALSE,
lang = "en",
.env = parent.frame()) {

Expand All @@ -108,7 +110,10 @@ local_reproducible_output <- function(width = 80,
local_width(width = width, .env = .env)
withr::local_options(
crayon.enabled = crayon,
cli.hyperlink = crayon && rstudio,
cli.hyperlink = hyperlinks,
cli.hyperlink_run = hyperlinks,
cli.hyperlink_help = hyperlinks,
cli.hyperlink_vignette = hyperlinks,
cli.dynamic = FALSE,
cli.unicode = unicode,
cli.condition_width = Inf,
Expand Down
3 changes: 3 additions & 0 deletions R/reporter.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Reporter <- R6::R6Class("Reporter",
unicode = TRUE,
crayon = TRUE,
rstudio = TRUE,
hyperlinks = TRUE,

out = NULL,

Expand All @@ -60,6 +61,7 @@ Reporter <- R6::R6Class("Reporter",
self$unicode <- cli::is_utf8_output()
self$crayon <- cli::num_ansi_colors() > 1
self$rstudio <- Sys.getenv("RSTUDIO") == "1"
self$hyperlinks <- cli::ansi_hyperlink_types()[["run"]]
},

# To be used when the reporter needs to produce output inside of an active
Expand All @@ -69,6 +71,7 @@ Reporter <- R6::R6Class("Reporter",
width = self$width,
crayon = self$crayon,
rstudio = self$rstudio,
hyperlinks = self$hyperlinks,
.env = .env
)
# Can't set unicode with local_reproducible_output() because it can
Expand Down
5 changes: 4 additions & 1 deletion man/local_test_context.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/test-local.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test_that("can force cli to display RStudio style hyperlinks", {
str(cli::ansi_hyperlink_types())
})

local_reproducible_output(crayon = TRUE, rstudio = TRUE)
local_reproducible_output(crayon = TRUE, hyperlinks = TRUE, rstudio = TRUE)
expect_snapshot({
str(cli::ansi_hyperlink_types())
})
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-snapshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ test_that("errors and warnings are folded", {
})

test_that("hint is informative", {
local_reproducible_output(crayon = TRUE, rstudio = TRUE)
local_reproducible_output(crayon = TRUE, hyperlinks = TRUE, rstudio = TRUE)

expect_snapshot({
cat(snapshot_accept_hint("_default", "bar.R", reset_output = FALSE))
Expand Down

0 comments on commit e2c70e1

Please sign in to comment.