Honor no_color config and add a global --color flag #173

Merged
stephen merged 2 commits from feat/171-color-control into main 2026-06-15 15:45:37 +00:00
Owner

Closes #171.

fj config set no_color true was accepted (no_color is in KNOWN_KEYS) but read nowhere: color was decided solely by the supports-color crate (isatty plus NO_COLOR / FORCE_COLOR), so the documented setting was a silent no-op and there was no per-invocation override.

What changed:

  • A global --color <auto|always|never> flag. always forces color on (e.g. into less -R), never strips it, auto keeps today's terminal detection. It is global = true, so it works on every command.
  • The no_color config key now feeds the decision via config::no_color_enabled, parsed leniently (1 / true / yes / on).
  • output::supports_color routes through a single resolver (supports_color_with) that applies the precedence; the env / config / tty inputs are injected so the resolver is unit-tested directly.

Precedence, highest first: --color flag > NO_COLOR / FORCE_COLOR env > no_color config > terminal detection. Documented in the README, the FAQ, and the gh-to-fj map.

Tests: the precedence resolver is covered across the flag / env / config / tty matrix, including a guard that no_color=true suppresses color. Full suite green (536 passing), clippy -D warnings clean, cargo fmt --check clean.

Closes #171. `fj config set no_color true` was accepted (`no_color` is in `KNOWN_KEYS`) but read nowhere: color was decided solely by the supports-color crate (isatty plus `NO_COLOR` / `FORCE_COLOR`), so the documented setting was a silent no-op and there was no per-invocation override. What changed: - A global `--color <auto|always|never>` flag. `always` forces color on (e.g. into `less -R`), `never` strips it, `auto` keeps today's terminal detection. It is `global = true`, so it works on every command. - The `no_color` config key now feeds the decision via `config::no_color_enabled`, parsed leniently (`1` / `true` / `yes` / `on`). - `output::supports_color` routes through a single resolver (`supports_color_with`) that applies the precedence; the env / config / tty inputs are injected so the resolver is unit-tested directly. Precedence, highest first: `--color` flag > `NO_COLOR` / `FORCE_COLOR` env > `no_color` config > terminal detection. Documented in the README, the FAQ, and the gh-to-fj map. Tests: the precedence resolver is covered across the flag / env / config / tty matrix, including a guard that `no_color=true` suppresses color. Full suite green (536 passing), clippy `-D warnings` clean, `cargo fmt --check` clean.
Honor color configuration
Some checks failed
ci / check (pull_request) Failing after 38s
ci / coverage (pull_request) Has been skipped
ci / live-e2e (pull_request) Has been skipped
3e792969fa
Fix fmt and keep config.rs out of coverage scope
All checks were successful
ci / check (pull_request) Successful in 10m24s
ci / coverage (pull_request) Successful in 2m5s
ci / live-e2e (pull_request) Successful in 1m50s
902fb6b522
The color commit tripped two CI gates:
- It was formatted with a nightly rustfmt that reorders imports; rerun
  the repo's stable `cargo fmt` so `--check` passes.
- It added a `#[cfg(test)]` module to `cli/config.rs`, which is in
  COV_IGNORE, breaking `cov_ignore_stays_in_sync_with_test_modules`.
  Drop the local truthy-parse test; the `no_color` suppression behavior
  is already covered by the precedence tests in `output`.
stephen changed title from Honor color controls to Honor no_color config and add a global --color flag 2026-06-15 15:27:27 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
rasterstate/fj!173
No description provided.