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

feat(help): Allow user-provided styled text in StyledStr #4765

Merged
merged 8 commits into from
Mar 28, 2023

Conversation

epage
Copy link
Member

@epage epage commented Mar 16, 2023

We are deferring to ANSI escape codes as our external stable API for this. Users can then choose to use owo-colors, color-print, etc as they desire and it will just work thanks to anstream.

anstream is a wrapper around stdout and stderr that will automatically decide whether to

  • pass ansi codes through (e.g. unix terminal)
  • strip codes (e.g. piped to file)
  • convert to wincon API calls (legacy Windows terminal)

By using anstream, we also respect CLICOLOR and CLICOLOR_FORCE. We might have respected NO_COLOR before via termcolor.

I ended up fixing #4431 while at it as I was wanting to debug where the fault was in case it was something to fix in anstream

See #4722
Fixes #1433
Fixes #3108

@epage epage force-pushed the anstream branch 5 times, most recently from 030c008 to c579c17 Compare March 17, 2023 01:59
@epage epage changed the title feat(help): Respect CLICOLOR, CLICOLOR_FORCE feat(help): Allow styled text Mar 17, 2023
@epage epage changed the title feat(help): Allow styled text feat(help): Allow user-provided styled text in StyledStr Mar 17, 2023
@epage epage marked this pull request as ready for review March 17, 2023 15:22
@epage epage force-pushed the anstream branch 4 times, most recently from a9ef604 to 4d2cc9b Compare March 18, 2023 00:21
@epage epage marked this pull request as draft March 18, 2023 00:43
@epage
Copy link
Member Author

epage commented Mar 20, 2023

My current thought for how to roll this out is to do it in two steps

  1. The switch to anstream
  2. The documentation changes around allowing custom styling

This would make it easier to revert the anstream change if its causing problem as we have fewer behavior guarantees around it.

However, since clap is generally used by bins which have committed lockfiles

  • It may be a while before people upgrade
  • We are more likely to fix any problems immediately and people always have the option to lock to an older version

So maybe we don't need to exercise too much caution and can merge this as-is

@epage epage marked this pull request as ready for review March 28, 2023 00:58
@epage epage merged commit 52eab28 into clap-rs:master Mar 28, 2023
@epage epage deleted the anstream branch March 28, 2023 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The header for my examples are not colored like the others Allow styled text in template
2 participants