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

Feature request : cli_glue() #606

Open
DanChaltiel opened this issue May 22, 2023 · 2 comments
Open

Feature request : cli_glue() #606

DanChaltiel opened this issue May 22, 2023 · 2 comments
Labels
feature a feature request or enhancement

Comments

@DanChaltiel
Copy link
Contributor

DanChaltiel commented May 22, 2023

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.

@gaborcsardi gaborcsardi added the feature a feature request or enhancement label May 22, 2023
@gaborcsardi
Copy link
Member

I believe this will be possible soon, with the ongoing redesign of cli.

@wurli
Copy link

wurli commented Feb 28, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants