cli
cli copied to clipboard
Feature request : `cli_glue()`
Hi,
The inline markup features in {cli} are wonderful, and it would be very sad to limit their reach to only printing.
For instance, I would love to be able to use formats, pluralization, and collapsing in free text vectors (to use in the package {officer} in my case).
For now, I'm using a custom function but it might not be very stable and powerful, and I'm sure an official version would be a much-appreciated feature:
library(cli)
cli_glue = function(x) cli_fmt(cli_text(x), collapse=TRUE, strip_newline=TRUE) |> stringr::str_replace_all("\n", " ")
x = cli_glue("All letters in lower case: {letters}")
x
#> [1] "All letters in lower case: a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, ..., y, and z"
Created on 2023-05-22 with reprex v2.0.2
You might say that this is out of the scope of {cli} which is all about printing. It would be in the scope of {glue}, but all those features lie in {cli}. It would be quite surprising that this is in the scope of no package IMHO.
I believe this will be possible soon, with the ongoing redesign of cli.
I think this is what format_inline() is for:
cli::format_inline("All letters in lower case: {letters}")
#> [1] "All letters in lower case: a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, …, y, and z"
Created on 2024-02-28 with reprex v2.1.0