-
Notifications
You must be signed in to change notification settings - Fork 70
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
Add option to customize last separator when auto-collapsing character vectors #639
Comments
There are several ways to do this, here are two: ❯ cli_text("foo {.or {letters[1:5]}} bar")
foo a, b, c, d, or e bar ❯ v <- cli_vec(letters[1:5], style = list("vec-last" = ", or "))
❯ cli_text("foo {v} bar")
foo a, b, c, d, or e bar |
Awesome! Thanks for the quick response! It might be worth adding to the relevant documentation article Also worth mentioning that the first solution you suggest only is a solution if you want to replace "and" with "or" cli::cli_text("foo {.or {letters[1:5]}} bar")
cli::cli_text("foo {.und {letters[1:5]}} bar") # won't work And the second solution means you won't have the convenience of the automatic character vector collapsing. |
You would need define
I am not sure what you mean, see my second example. In general, you either need to define your own class with a theme, or add the style to the vector that you want to collapse. |
I ran into this issue again today and it took me a while to remember how to define a custom x <- c("a", "b", "c")
text <- "{.und {x}}"
my_theme <- list(span.und = list("vec-sep2" = " und ", "vec-last" = ", und "))
# -- option 1: modify theme temporarily for a single div
cli::cli_div(theme = my_theme)
cli::cli_text(text)
cli::cli_end()
# > a, b, und c
# -- option 2:modify theme more permanently via user theme
options("cli.user_theme" = my_theme)
cli::cli_text(text)
# > a, b, und c Relevant sourceshttps://cli.r-lib.org/reference/inline-markup.html#collapsing-inline-vectors Line 254 in 2ddcc1a
https://cli.r-lib.org/reference/themes.html https://cli.r-lib.org/reference/cli_div.html https://cli.r-lib.org/reference/inline-markup.html |
cli_text()
andpluralize()
auto-collapse character vectors, but there is no option to configure the final separator "and":#> Will remove the pkg1, pkg2, and pkg3 packages.
This is hardcoded as
last
incli:::inline_collapse()
:It would be useful to expose a
last
argument to the user so they can override it with a language-specific separator or just a regular ','.A usable workaround is to collapse the character vector outside of the function, e.g. with
glue::collapse()
, which does have alast
argument.The text was updated successfully, but these errors were encountered: