fix(cli): 未指定 --no-color 时恢复 colored 的 TTY 自动检测
set_override(!no_color) 在默认情况下无条件强制着色,导致管道/CI/ 测试捕获的输出混入 ANSI 色码,违背 ADR-0003 "color keeps colored's existing tty auto-detection" 的规定。改为仅在 --no-color 或 NO_COLOR 存在时强制关闭颜色,其余场景交给 colored 按 stdout 是否为 TTY 自动 判断:终端体验不变,管道输出恢复纯文本。
This commit is contained in:
@@ -81,9 +81,13 @@ async fn main() -> Result<()> {
|
|||||||
|
|
||||||
// Apply the global color decision before any output is produced.
|
// Apply the global color decision before any output is produced.
|
||||||
// --no-color disables colors; NO_COLOR follows the no-color.org spec
|
// --no-color disables colors; NO_COLOR follows the no-color.org spec
|
||||||
// (any presence, regardless of value, disables color).
|
// (any presence, regardless of value, disables color). Without them,
|
||||||
|
// color keeps colored's tty auto-detection (ADR-0003): piped output
|
||||||
|
// stays ANSI-free.
|
||||||
let no_color = cli.no_color || std::env::var_os("NO_COLOR").is_some();
|
let no_color = cli.no_color || std::env::var_os("NO_COLOR").is_some();
|
||||||
colored::control::set_override(!no_color);
|
if no_color {
|
||||||
|
colored::control::set_override(false);
|
||||||
|
}
|
||||||
|
|
||||||
// Resolve the decoration switch (issue 14): explicit flag > config >
|
// Resolve the decoration switch (issue 14): explicit flag > config >
|
||||||
// default; --no-color disables decorations too (ADR-0003).
|
// default; --no-color disables decorations too (ADR-0003).
|
||||||
|
|||||||
Reference in New Issue
Block a user