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

Consider switching to anstyle for our terminal styling and color needs #724

Closed
obi1kenobi opened this issue Mar 29, 2024 · 8 comments
Closed
Labels
A-cli Area: engine around the lints C-enhancement Category: raise the bar on expectations E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: Mentorship is available for this issue.

Comments

@obi1kenobi
Copy link
Owner

obi1kenobi commented Mar 29, 2024

Tangential comment. Please disregard since it's only for future note.*

The recommended SOTA color-related logic is to use the rust-cli/anstyle crates.*

Originally posted by @pksunkara in #721 (comment)

It seems that multiple of our dependencies already use anstyle, so we should consider switching to it as well.

@obi1kenobi obi1kenobi added A-cli Area: engine around the lints C-enhancement Category: raise the bar on expectations E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: Mentorship is available for this issue. labels Mar 29, 2024
@pksunkara
Copy link
Contributor

I can mentor on this issue.

@suaviloquence
Copy link
Contributor

Hi! Thanks for the offer to help! Would common practice be to use the anstyle-termcolor crate or refactor entirely to use the anstream crate?

@pksunkara
Copy link
Contributor

I might be wrong but I consider anstyle-termcolor to be more related to style customization logic.

The color logic we need to clean up here is more about the setup including respecting user's preferences. I have a sample boilerplate for CLIs that sets up everything related to color at https://git.sr.ht/~pksunkara/cli-clap.

There are quite a few important parts such as:

@pksunkara
Copy link
Contributor

pksunkara commented Mar 30, 2024

To answer the original question,

Since we must respect the color choices set in various ways (as described in anstyle-query), we must bring in anstream. And then have a generic output function that uses anstyle-termcolor to convert the termcolor usage to anstyle before printing. This is the way people would choose to migrate if they have a lot of places where they need to migrate.

But since, we have only a few places and also use termcolor_output to currently print that we can't easily modify, and we are bringing in anstream anyway, I would recommend the refactor to anstream crate completely.

(Feel free to ping me on Zulip if you want to chat)

@suaviloquence
Copy link
Contributor

suaviloquence commented Apr 1, 2024

just a thought while I work on this - does it make sense to also refactor to use something like the log crate for managing log levels?

so that the end application (the cli for us, and whatever binary crate uses semver-checks) sets color and logging preferences, and the library part of the crate is less aware of these preferences

@pksunkara
Copy link
Contributor

If you want to do that, I would recommend tracing instead (setup and usage)

@suaviloquence
Copy link
Contributor

suaviloquence commented Apr 19, 2024

Added in #737

@obi1kenobi
Copy link
Owner Author

Implemented in #737.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cli Area: engine around the lints C-enhancement Category: raise the bar on expectations E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: Mentorship is available for this issue.
Projects
None yet
Development

No branches or pull requests

3 participants