cli
cli copied to clipboard
Could you highlight the use of vec-last and vec-sep in docs?
I feel like it took me way too long to stumble opon these two in cli_vec(). Shouldn't this be mentioned in here or there? I was fortunate to find this info by chance when looking at the truncation example on the inline markup article (which isn't mentioned in "Building a semantic CLI" one) and thinking "Maybe I should check this cli_vec() thingy?".
That sounds like a good idea. Would you like to submit a PR? (No pressure and no need to worry about rebuilding the docs, which is a pain in the neck.)
@gaborcsardi I can't promise anything. But if I will find a moment, am I correct that there is no global setting for these two options of collapsing vectors?
They are part of the theme, so the end user can change them with a custom theme, e.g.
options(cli.user_theme = list(body = list("vec-sep" = " + ", "vec-last" = " --- ")))
cli::cli_alert_info("These: {1:5}.")
#> ℹ These: 1 + 2 + 3 + 4 --- 5.
However, in practice I am not sure if this makes sense, because it will apply to all packages using cli (if attached to body). It does make sense in some restricted context.
Just an observation: cli_vec() is somewhat related to ansi_collapse():
x <- cli::cli_vec(names(mtcars), list("vec-trunc" = 3))
x2 <- cli::ansi_collapse(names(mtcars), trunc = 3)
str(x)
#> chr [1:11] "mpg" "cyl" "disp" "hp" "drat" "wt" "qsec" "vs" "am" "gear" ...
#> - attr(*, "cli_style")=List of 1
#> ..$ vec-trunc: num 3
str(x2)
#> chr "mpg, cyl, disp, …, gear, and carb"
cli::cli_text("Column names: {x}.")
#> Column names: mpg, cyl, disp, …, gear, and carb.
cli::cli_text("Column names: {x2}.")
#> Column names: mpg, cyl, disp, …, gear, and carb.
Created on 2024-01-30 with reprex v2.1.0
ansi_collapse() is used by the internal cli:::inline_collapse() when a cli string is rendered.