Content-Length: 334740 | pFad | http://github.com/astral-sh/ruff/pull/16758

71 [red-knot] Add `--color` CLI option by MichaReiser · Pull Request #16758 · astral-sh/ruff · GitHub
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

[red-knot] Add --color CLI option #16758

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Mar 14, 2025

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:

  • The diagnostics are or aren't colored
  • The tracing output is or isn't colored.

@AlexWaygood AlexWaygood added the red-knot Multi-file analysis & type inference label Mar 14, 2025
Copy link
Contributor

mypy_primer results

No ecosystem changes detected ✅

Copy link
Contributor

@sharkdp sharkdp left a 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)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe

Suggested change
#[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.
Copy link
Contributor

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

Suggested change
//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
Copy link
Contributor

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?

Suggested change
//github.com/ Always display colors
//github.com/ Always display colors.

@sharkdp
Copy link
Contributor

sharkdp commented Mar 14, 2025

One more question: Would it make sense to move this option to the top level instead of knot check? It seems like other sub-commands might also make use of that option in the future. uv also has it as a top-level option.

@MichaReiser
Copy link
Member Author

One more question: Would it make sense to move this option to the top level instead of knot check? It seems like other sub-commands might also make use of that option in the future. uv also has it as a top-level option.

Absolutely. There are options that we should move and I'll move them all together

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
red-knot Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/astral-sh/ruff/pull/16758

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy