NO_COLOR suppresses non-color attributes, not just color
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
Direzione di ricerca
Inizia con il percorso NO_COLOR da anstream::ColorChoice::Never passando per StripStream e StripBytes, quindi esamina anstyle::Style e csi_dispatch di anstyle-parse. Riproduci l'esempio e traccia il modo in cui i parametri SGR vengono scartati. Il lavoro è completato quando NO_COLOR preserva gli effetti non relativi al colore sopprimendo al contempo il colore, con una copertura per l'output descritto e il comportamento Never esistente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
NO_COLOR suppresses non-color attributes, not just color
Summary
When NO_COLOR is set, anstream strips all ANSI escape sequences —
bold, dim, italic, underline, reverse, strikethrough, etc. — not only
color. This diverges from no-color.org
(or its source),
whose FAQ is explicit:
Q: Should the presence of
NO_COLORdisable other styling such as
bold, underline, and italic?A: No. This standard only signals the user's intention regarding
adding ANSI color to text output.
Reproduction
NO_COLOR resolves to ColorChoice::Never → StripStream, whose
StripBytes engine (driven by anstyle_parse) discards every CSI escape
without inspecting its SGR parameters. Verified on anstream 1.0.0:
use std::io::Write as _;
let mut out = anstream::AutoStream::new(Vec::new(), anstream::ColorChoice::Never);
write!(out, "\x1b[1mbold\x1b[22m \x1b[4munderline\x1b[24m \x1b[31mred\x1b[39m").unwrap();
assert_eq!(String::from_utf8(out.into_inner()).unwrap(), "bold underline red");
Bold and underline are stripped along with the red color. Per the FAQ, only
color should be suppressed; the expected output is
\x1b[1mbold\x1b[22m \x1b[4munderline\x1b[24m red.
Suggested direction
A spec-correct color-only strip needs to distinguish color SGR parameters
from attribute parameters and re-emit only the latter. Most of the
primitives for this already live in the workspace: anstyle::Style
separates fg/bg/underline-color from effects, and anstyle-parse
already produces the SGR parameter list via csi_dispatch. The missing
piece is a decode step (param list → Style delta) so a strip adapter can
track the active style and render only effects. If a shared decoder
lived in anstyle, other consumers could reuse it for the same spec
alignment — but the shape is of course the maintainers' call.
One design point worth flagging: ColorChoice::Never is reached today for
NO_COLOR, for non-terminals, and for CLICOLOR disabled. The FAQ
constrains only the NO_COLOR case, so it may be cleanest for NO_COLOR
to resolve to a color-only path while the other Never callers keep the
full strip (pipe-to-file output today is fully flat, which is arguably
desirable for logs).
Notes
- The empty-string trigger is already handled correctly upstream:
anstyle_query::no_color()isnon_empty(NO_COLOR), soNO_COLOR=""
disables nothing, per spec. This issue is only about the scope of
suppression. - This cascades to dependents routing through
anstream(env_logger,
clapwith itscolorfeature), which would inherit the fix. crosstermis a working example of color-onlyNO_COLORhandling —
it gatesColored(fg/bg/underline-color) but emitsSetAttributes
unconditionally.- Related: #192 (env-var support context).
Versioning
I'd frame this as a bug fix (patch bump) with a one-line CHANGELOG note
acknowledging the observable output change, but defer to the project's
own version policy.
- Lingua principale
- HTML
- Stelle
- 171
- Fork
- 44
- Merge medio
- 2h 34m
- PR unite (30g)
- 6
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di rust-cli/anstyle
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
A-stream
Difficoltà 3/5 1-2 giorni Idoneità per principianti 58/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 52/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
Tutte le issue di rust-cli/anstyle
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
BasedHardware/omi#15662 · 1 commento ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
alexgorbatchev/dotfiles#107 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
from:qa priority:P2 reliability tech-debt
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
spec-kitty/spec-kitty#4874 ·
-
0. Needs triage bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
nextcloud/fulltextsearch#1011 ·