Color-code construct doctor output - #1072
Merged
Merged
Conversation
Doctor's report is long — 40+ findings on a healthy machine — and every row currently reads with the same weight, so the two warnings that actually matter are as visually loud as the twenty-six `[ok]` lines around them. Severity is the whole point of the command; make it scannable. Adds `crates/cli/src/ansi.rs`: a `ColorChoice` (auto/always/never) that resolves to a `Palette` of basic ANSI-16 SGR codes. The TUI's `color` module can't serve this — it's ratatui-only, and its 24-bit quantization exists for a backend a plain subcommand never touches. Sticking to the 16 basic colors also means the user's terminal profile owns the hues, which sidesteps the Apple Terminal truecolor breakage documented in spec 0111. Color is strictly additive. `render` takes the palette as a parameter and pads *before* wrapping tokens in escape codes, so column math never sees an escape byte; the tests assert that stripping SGR codes from a styled render reproduces the plain one byte for byte. Every severity is still stated in words on the line it colors, so nothing is lost to a pipe, a redirect, `NO_COLOR`, or a paste into an issue — `auto` turns itself off for all of those, and `--json` is never styled. Updates spec 0168's rendering consequences accordingly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
construct doctorprints 40+ findings on a healthy machine, all in the sameweight. The two warnings that matter read exactly as loud as the twenty-six
[ok]lines around them — which defeats the point of a command whose entireoutput is organized by severity.
What changed
New
crates/cli/src/ansi.rs: aColorChoice(auto/always/never)that resolves to a
Paletteof basic ANSI-16 SGR codes.[ok]green ·[info]dim ·[warn]yellow ·[error]red · sectiontitles bold ·
fix:markers cyan · note lines dim.verdict is green or red.
The TUI's
colormodule can't serve this: it's ratatui-only, and its 24-bitquantization exists for a backend a plain subcommand never touches. Staying
inside the 16 basic colors also hands the hues to the user's own terminal
profile, which sidesteps the Apple Terminal truecolor breakage documented in
spec 0111 and keeps the report legible on a light background.
Color is strictly additive
This is the invariant the diff is built around, and the one worth reviewing:
rendertakes the palette as a parameter and stays pure.format!(\"{styled:<WIDTH\$}\")would pad to the byte width and shear the column the moment styling is on;
there's a regression test pinned to that specific mistake.
nothing is carried by color alone.
byte for byte — asserted both as a unit test and end-to-end against the
real subprocess.
autoturns itself off for a non-tty stdout,NO_COLOR, andTERM=dumb;--jsonis never styled under any flag.Tests
crates/cli/src/ansi.rs— 6 unit tests on the gating truth table(tty /
NO_COLORpresent-vs-empty /TERM=dumb/ explicit overrides).crates/cli/src/doctor.rs— 3 new: strip-equals-plain over a report withall four severities, per-severity SGR codes, and the padding-outside-escapes
guard. The 7 pre-existing render tests are unchanged apart from taking
Palette::PLAIN, which proves the plain output did not move.crates/e2e/tests/doctor.rs—a_redirected_report_carries_no_escape_codes_unless_asked:runs the real binary with stdout on a pipe, which is the case
automustdetect and a unit test can't reach.
All 7 e2e + 1266 CLI tests pass.
Spec
Spec 0168's rendering consequence used to read "output is plain ASCII and
pipe-friendly." Replaced with the two rules that now hold: color is an
accelerant and never the carrier of a distinction, and it follows platform
convention (
NO_COLOR, an explicit flag, off for machine output, basicpalette only).
Verifying
Before/after screenshots of the same report (identical layout, color the only
difference) are on the reviewer's machine at
/tmp/doctor-before-crop.pngand/tmp/doctor-after-crop.png— GitHub markdown can't render ANSI, so theescape-stripped equality is asserted by the tests instead.