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

Migrate ui_*() functionality to use cli #956

Closed
jennybc opened this issue Dec 8, 2019 · 6 comments · Fixed by #1956
Closed

Migrate ui_*() functionality to use cli #956

jennybc opened this issue Dec 8, 2019 · 6 comments · Fixed by #1956
Labels
tooling 🔨 Internal usethis tooling upkeep maintenance, infrastructure, and similar

Comments

@jennybc
Copy link
Member

jennybc commented Dec 8, 2019

See notes here: r-lib/cli#68

and the transition guide: https://cli.r-lib.org/dev/articles/usethis-ui.html

@hadley
Copy link
Member

hadley commented Mar 14, 2020

Also related to #673

@hadley hadley added feature a feature request or enhancement tooling 🔨 Internal usethis tooling labels Mar 14, 2020
@GegznaV
Copy link
Contributor

GegznaV commented Apr 5, 2020

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?

@hadley
Copy link
Member

hadley commented Apr 5, 2020

@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.

@hadley hadley added upkeep maintenance, infrastructure, and similar and removed feature a feature request or enhancement labels Jan 17, 2023
@olivroy
Copy link
Contributor

olivroy commented Dec 5, 2023

@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!

@jennybc
Copy link
Member Author

jennybc commented Dec 5, 2023

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".

@olivroy
Copy link
Contributor

olivroy commented Dec 5, 2023

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

  1. Deprecate ui_stop() (for cli::cli_abort()), ui_warn() (cli::cli_warn), ui_inform() for ui_cli_inform().
  2. Convert existing ui_stop() to cli::cli_abort() with c().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tooling 🔨 Internal usethis tooling upkeep maintenance, infrastructure, and similar
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants