Skip to content

Commit 0a06c32

Browse files
committed
errors.R: only add hyperlinks if cli supports this
1 parent 649c75c commit 0a06c32

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

R/errors.R

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@
139139
# * Use a `procsrcref` column for processed source references.
140140
# Otherwise testthat (and probably other rlang based packages), will
141141
# pick up the `srcref` column, and they expect an `srcref` object there.
142+
#
143+
# ### 3.1.0 -- 2022-10-04
144+
#
145+
# * Add ANSI hyperlinks to stack traces, if we have a recent enough
146+
# cli package that supports this.
142147

143148
err <- local({
144149

@@ -816,12 +821,18 @@ err <- local({
816821
if (is.null(ref)) return("")
817822

818823
link <- if (ref$file != "") {
819-
cli::style_hyperlink(
820-
cli::format_inline("{basename(ref$file)}:{ref$line}:{ref$col}"),
821-
paste0("file://", ref$file),
822-
params = c(line = ref$line, col = ref$col)
823-
)
824-
824+
if (Sys.getenv("R_CLI_HYPERLINK_STYLE") == "iterm") {
825+
cli::style_hyperlink(
826+
cli::format_inline("{basename(ref$file)}:{ref$line}:{ref$col}"),
827+
paste0("file://", ref$file, "#", ref$line, ":", ref$col)
828+
)
829+
} else {
830+
cli::style_hyperlink(
831+
cli::format_inline("{basename(ref$file)}:{ref$line}:{ref$col}"),
832+
paste0("file://", ref$file),
833+
params = c(line = ref$line, col = ref$col)
834+
)
835+
}
825836
} else {
826837
paste0("line ", ref$line)
827838
}

0 commit comments

Comments
 (0)