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

export ansi_string() #573

Closed
multimeric opened this issue Jan 30, 2023 · 3 comments · Fixed by #574
Closed

export ansi_string() #573

multimeric opened this issue Jan 30, 2023 · 3 comments · Fixed by #574
Labels
feature a feature request or enhancement

Comments

@multimeric
Copy link
Contributor

I'm looking for a way to take an existing character vector with ANSI control codes and treat it as a cli_ansi_string object. Now I could do this by just setting the class of the vector, but I would prefer using a public function for this. ansi_string seems to have some other encoding logic in it too. Internally it seems that you use ansi_string() to do this. Could this become part of the public API?

@gaborcsardi
Copy link
Member

We could do that. The caveat is that cli does not handle all ANSI control codes, and right now ansi_string objects only contain ANSI codes that it supports. If you can mark arbitrary strings as ansi_string objects, then that's not necessarily true any more. But I don't think this is a big danger, so we can do this. Do you want to submit a PR? No pressure at all, just asking. 😄

@gaborcsardi gaborcsardi added the feature a feature request or enhancement label Jan 30, 2023
@multimeric
Copy link
Contributor Author

The caveat is that cli does not handle all ANSI control codes, and right now ansi_string objects only contain ANSI codes that it supports. If you can mark arbitrary strings as ansi_string objects, then that's not necessarily true any more.

I take your point, but even with some missing functionality I think there will still be a better user experience when using an ansi_string object over the character class if it contains any ANSI codes. The big difference is the use of cat to print it out which is a strict improvement. Won't that just delegate the ANSI printing to the user's terminal?

Do you want to submit a PR? No pressure at all, just asking.

Yep, happy to.

@gaborcsardi
Copy link
Member

Sure, the class will get you the printing. But it is a very fragile class, and it is very easy to lose it:

❯ col_red("foobar")
<cli_ansi_string>
[1] foobar

❯ c(col_red("foobar"))
[1] "\033[31mfoobar\033[39m"

Which is something that we just need to accept.

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

Successfully merging a pull request may close this issue.

2 participants