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

Migrate from termcolor to anstream #12627

Closed
epage opened this issue Sep 6, 2023 · 2 comments · Fixed by #12751
Closed

Migrate from termcolor to anstream #12627

epage opened this issue Sep 6, 2023 · 2 comments · Fixed by #12751
Assignees
Labels
A-cli Area: Command-line interface, option parsing, etc. A-console-output Area: Terminal output, colors, progress bar, etc. C-cleanup Category: cleanup within the codebase

Comments

@epage
Copy link
Contributor

epage commented Sep 6, 2023

anstream provides the same feature set as termcolor (including legacy windows support) but with a less awkward API to work with. Instead of hand-constructing data in a special container with each step requiring setting the style, you use whatever styling library you like (e.g. color-print like in #12578) and then write to the appropriate stream, and you are done. The stream does all the rest, allowing styling to be decoupled from where it is being rendered.

So anstream would replace

  • termcolor
  • fwdansi
  • strip-ansi-escapes

Benefits

  • Lower boilerplate way to style text while leaving Shell in control (see cargo adds use of Shell::write_stderr)
  • Open the door for styling within messages
  • Lower overhead as it only intercepts when something needs changing. This will be especially true in switching from fwdansi to anstream
  • Strip API is significantly faster than strip-ansi-escapes
  • Centralize color schemes between Shell (currently using termcolor) and clap (using anstyle)
@epage epage added A-cli Area: Command-line interface, option parsing, etc. C-cleanup Category: cleanup within the codebase labels Sep 6, 2023
@epage
Copy link
Contributor Author

epage commented Sep 6, 2023

anstream should work fine for how we use termcolor / fwdansi. There is a locking bug we might run into if we do anything past that and I'm currently working on it, so I'd recommend holding off on this until then.

@weihanglo
Copy link
Member

triage: @rustbot label S-blocked-external

Since epage is working on it from dependency side.

@rustbot rustbot added the S-blocked-external Status: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fix label Sep 26, 2023
@epage epage removed the S-blocked-external Status: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fix label Sep 28, 2023
@bors bors closed this as completed in 59596f0 Sep 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cli Area: Command-line interface, option parsing, etc. A-console-output Area: Terminal output, colors, progress bar, etc. C-cleanup Category: cleanup within the codebase
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants