Skip to content

Commit

Permalink
Better detection if hyperlink can be used in a terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
phgrosjean committed Aug 11, 2023
1 parent 262c22b commit 3c8bf98
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
18 changes: 11 additions & 7 deletions R/aka.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,23 @@ seealso = NULL, example = NULL, url = NULL) {
obj
}

# Internal object to cache the type of hyperlink that can be used
.hyperlink_type <- {
# Internal function to cache the type of hyperlink that can be used
.hyperlink_type <- function() {
if (rlang::is_interactive() && cli::ansi_has_hyperlink_support()) {
types <- cli::ansi_hyperlink_types()
if (isTRUE(types$help)) {
"help"
res <- "help"
} else if (isTRUE(types$href)) {
"href"
res <- "href"
} else {
"none"
res <- "none"
}
} else {
"none"
res <- "none"
}
if (is.null(getOption("hyperlink_type")))
options(hyperlink_type = res)
res
}

#' @export
Expand All @@ -78,7 +81,8 @@ seealso = NULL, example = NULL, url = NULL) {
#' help page in the Help tab.
#' @param ... Further arguments (not used yet)
#' @method print aka
print.aka <- function(x, hyperlink_type = .hyperlink_type, ...) {
print.aka <- function(x, hyperlink_type = getOption("hyperlink_type",
default = .hyperlink_type()), ...) {
src <- attr(comment(x), "src")
link <- switch(hyperlink_type,
help = {
Expand Down
6 changes: 5 additions & 1 deletion man/aka.Rd

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

0 comments on commit 3c8bf98

Please sign in to comment.