From 8ff7504d96a1f81d871ebfd44b6480c52d80e4c0 Mon Sep 17 00:00:00 2001 From: SidneyZhang Date: Mon, 31 Aug 2026 14:37:10 +0800 Subject: [PATCH] =?UTF-8?q?fix(cli):=20=E6=9C=AA=E6=8C=87=E5=AE=9A=20--no-?= =?UTF-8?q?color=20=E6=97=B6=E6=81=A2=E5=A4=8D=20colored=20=E7=9A=84=20TTY?= =?UTF-8?q?=20=E8=87=AA=E5=8A=A8=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit set_override(!no_color) 在默认情况下无条件强制着色,导致管道/CI/ 测试捕获的输出混入 ANSI 色码,违背 ADR-0003 "color keeps colored's existing tty auto-detection" 的规定。改为仅在 --no-color 或 NO_COLOR 存在时强制关闭颜色,其余场景交给 colored 按 stdout 是否为 TTY 自动 判断:终端体验不变,管道输出恢复纯文本。 --- src/main.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index af5907a..b7ba9cb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -81,9 +81,13 @@ async fn main() -> Result<()> { // Apply the global color decision before any output is produced. // --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(); - colored::control::set_override(!no_color); + if no_color { + colored::control::set_override(false); + } // Resolve the decoration switch (issue 14): explicit flag > config > // default; --no-color disables decorations too (ADR-0003).