-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[red-knot] Add --color
CLI option
#16758
base: main
Are you sure you want to change the base?
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
@@ -79,6 +79,10 @@ pub(crate) struct CheckCommand { | |||
#[arg(long)] | |||
pub(crate) output_format: Option<OutputFormat>, | |||
|
|||
//github.com/ Control when colored output is used. | |||
#[arg(long)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
#[arg(long)] | |
#[arg(long, value_name = "WHEN")] |
//github.com/ Control when colored output is used. | ||
#[derive(Copy, Clone, Hash, Debug, PartialEq, Eq, PartialOrd, Ord, Default, clap::ValueEnum)] | ||
pub(crate) enum TerminalColor { | ||
//github.com/ Automatically detect if color support is available on the terminal. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds a bit like we would actually detect if the terminal emulator supports colors. What's actually happening is just a isatty
check (+ checks for NO_COLOR
etc). So I tend to write something like
//github.com/ Automatically detect if color support is available on the terminal. | |
//github.com/ Display colors if the output goes to an interactive terminal. |
#[default] | ||
Auto, | ||
|
||
//github.com/ Always display colors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: use a full stop here as well for consistency?
//github.com/ Always display colors | |
//github.com/ Always display colors. |
One more question: Would it make sense to move this option to the top level instead of |
Absolutely. There are options that we should move and I'll move them all together |
Summary
This PR adds a new
--color
CLI option that controls whether the output should be colorized or not.This is implements part of #16727 except that it doesn't implement the persistent configuration support as initially proposed in the CLI document. I realized, that having this as a persistent configuration is somewhat awkward because we may end up writing tracing logs before we loaded and resolved the settings. Arguably, it's probably fine to color the output up to that point, but it feels like a somewhat broken experience. That's why I decided not to add the persistent configuration option for now.
Test Plan
I tested this change manually by running Red Knot with
--color=always
,--color=never
, and--color=auto
(or no argument) and verified that: