cli icon indicating copy to clipboard operation
cli copied to clipboard

Could you highlight the use of vec-last and vec-sep in docs?

Open mkalamarz opened this issue 2 years ago • 4 comments
trafficstars

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

mkalamarz avatar Jul 11 '23 22:07 mkalamarz

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 avatar Jul 12 '23 07:07 gaborcsardi

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

mkalamarz avatar Jul 12 '23 21:07 mkalamarz

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.

gaborcsardi avatar Jul 13 '23 07:07 gaborcsardi

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.

salim-b avatar Jan 30 '24 16:01 salim-b