Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cli links with line numbers and .href #601

Open
olivroy opened this issue May 12, 2023 · 0 comments
Open

Cli links with line numbers and .href #601

olivroy opened this issue May 12, 2023 · 0 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@olivroy
Copy link
Contributor

olivroy commented May 12, 2023

Hello,

I am trying to use cli hyperlinks to line numbers with .href

# With .Rprofile existing 
# link works
cli::cli_bullets("{.file ~/.Rprofile}")
#> ~/.Rprofile 
# link works and takes me to line 4
cli::cli_bullets("{.file ~/.Rprofile:4}")
#> .Rprofile:4
# works and shows a link 
cli::cli_bullets("{.href [R profile](file://~/.Rprofile)}")
#> R profile
# link does not work
cli::cli_bullets("{.href [R profile line 1](file://~/.Rprofile:498)}")
#> R profile line 1

I get an error message that says No such file ~.Rprofile:498 does not exist. (in a prompt)
It may be out of scope, but from what I understand in the docs, it should be working.,

Running with RStudio 2023.03.0, Windows, and latest cli.

Edit: Ignore the other question ( I see that this is supported only outside RStudio https://cli.r-lib.org/reference/links.html#default-handler

Opening files outside RStudio within RStudio with cli hyperlink does not work.

# creates output, but clicking on the link does not work in RStudio.
cli::cli_text("{.file path/to/excel.xslx"})
#> path/to/excel.xlsx

Edit 2: Maybe a suggestion not to create a link (underline it ) to show that it won't open. for Excel file for example..

It seems that roxygen2 uses

  link <- cli::style_hyperlink(
    paste0(basename(file), ":", line),
    paste0("file://", file),
    params = c(line = line, col = 1)
  )

Another workaround that keeps the blue for file hyperlink is

withr::with_dir(
  "R",
  cli::format_inline("{.file path-under-r.R:8}") |> cat()
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants