usethis
usethis copied to clipboard
Migrate ui_*() functionality to use cli
See notes here: https://github.com/r-lib/cli/issues/68
and the transition guide: https://cli.r-lib.org/dev/articles/usethis-ui.html
Also related to #673
Does this mean that some ui_*()
functions are going to deprecate (soon)? And if I have a package that uses this kind of functions, I have to replace them with alternatives in cli?
@GegznaV given that we haven't done it yet and we're likely to leave the existing functions in some capacity, no. But I would recommend to switching to cli.
@jennybc Is the plan to modify the implementation of the ui_*()
functions or to switch to cli directly inside each message?
Currently
ui_oops("
Found legacy {ui_field('Author')} and/or {ui_field('Maintainer')} field ")
ui_field <- function(x) {
x <- crayon::green(x)
x <- glue_collapse(x, sep = ", ")
x
}
ui_oops <- function(x, .envir = parent.frame()) {
x <- glue_collapse(x, "\n")
x <- glue(x, .envir = .envir)
ui_bullet(x, crayon::red(cli::symbol$cross))
}
plan 1 : use cli directly
cli::cli_alert_danger("Found {.field Author} and/or {.field Maintainer} field")
plan 2: Modify ui_*()
functions to use cli
ui_field <- function(x) {
x <- cli::col_green(x)
x <- glue_collapse(x, sep = ", ")
x
}
ui_field <- function(x) {
cli::format_inline("{.field {x}}")
}
Or something else?
I'd like to look into this because, it would be cool to have clickable URLs and take advantage of {.run hyperlinks.
I have sketched something locally that mostly works. I will work on this again soon, but awaiting any guidance in any case!
I was planning on doing this myself rather soon, as I too am growing increasingly sad about usethis not having the modern goodies cli provides. And my plan is to leave the ui_*()
functions in place, but to replace their guts.
One reason (I suspect there are others) to do it this way is that we still need to honor the usethis.quiet
option, so wrapping cli functions inside ui_*()
gives us continued access to that "switch".
Ok! makes sense. The only thing that may be problematic is that usethis relies heavily on glue for the changes of lines.
In cli, it is always better to wrap each line on their own bullet.
I think that something that may be more complex would be the indentation or line breaks the are handled differently in glue vs cli.
ui_stop("
Unable to discover a GitHub personal access token
A token is required in order to fork {ui_value('repo_spec')}
Call {ui_code('hint')} for help configuring a token")
#> Error: Unable to discover a GitHub personal access token
#> A token is required in order to fork 'repo_spec'
#>
#> Call `hint` for help configuring a token
Created on 2023-12-05 with reprex v2.0.2
cli_abort()
does not preserve the line changes (except for the two line change)
cli::cli_abort("
Unable to discover a GitHub personal access token
A token is required in order to fork {usethis::ui_value('repo_spec')}
Call {usethis::ui_code('hint')} for help configuring a token")
#> Error:
#> ! Unable to discover a GitHub personal access
#> token A token is required in order to fork
#> 'repo_spec'
#>
#> Call `hint` for help configuring a token
ideas
- Deprecate
ui_stop()
(for cli::cli_abort()),ui_warn()
(cli::cli_warn),ui_inform()
forui_cli_inform()
. - Convert existing ui_stop() to cli::cli_abort() with
c()
.