`q2 render` ignores `NO_COLOR` and prints colour codes and hyperlinks in its diagnostics

未关闭 适合新手
#1,135 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
1/5
预计耗时
1 小时以内
新手友好度
88/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
rust
领域
cli

调研方向

阅读 crates/quarto/src/commands/render.rs,尤其是第 632 行附近现有的 NO_COLOR 和 stderr 终端检查,以及第 1442 行附近的诊断格式化调用。将现有的终端和颜色判断传给 format_render_diagnostics_text,不要硬编码为启用颜色。按照提供的步骤 NO_COLOR=1 q2 render index.qmd 复现;当设置了 NO_COLOR 或 stderr 被重定向时,诊断信息不含颜色或 OSC 8 转义序列,即为完成。

由索引模型根据 Issue 内容生成。

描述

Bug description

The script I use to check the dashboard from #1131 against q2 saves each render log to a file, and those logs are full of escape sequences.
With Quarto 1, NO_COLOR=1 gives me plain logs, but q2 ignores it.

q2 render already has a test for NO_COLOR and for a terminal on stderr, and uses it for the summary line with the error and warning counts:

https://github.com/quarto-dev/q2/blob/8f17e950d26c68daae6e794c5fa513a96c0dae68/crates/quarto/src/commands/render.rs#L632-L638

The diagnostics themselves are printed with colour hard-coded to true:

https://github.com/quarto-dev/q2/blob/8f17e950d26c68daae6e794c5fa513a96c0dae68/crates/quarto/src/commands/render.rs#L1442-L1445

That flag drives both the colours and the OSC 8 file links:

https://github.com/quarto-dev/q2/blob/8f17e950d26c68daae6e794c5fa513a96c0dae68/crates/quarto/src/commands/render.rs#L1740-L1742

Steps to reproduce

index.qmd, which includes a file that does not exist, so both tools stop with an error:

---
title: Hello
---

{{< include missing.qmd >}}
NO_COLOR=1 q2 render index.qmd 2>log
python3 -c "d = open('log').read(); print(d.count('\x1b['), d.count('\x1b]8;'))"
NO_COLOR=1 quarto render index.qmd 2>log
python3 -c "d = open('log').read(); print(d.count('\x1b['), d.count('\x1b]8;'))"
Actual behavior
q2 Quarto 1
stderr to a file 162 colour sequences, 2 OSC 8 links 2 colour sequences
stderr to a file, NO_COLOR=1 162 colour sequences, 2 OSC 8 links none

Quarto 1 also colours a log file, but NO_COLOR turns every escape off.
In q2 it changes nothing.

Expected behavior

No escape sequences when NO_COLOR is set, as in Quarto 1, and none when stderr is not a terminal, as the summary line already does.
Passing stderr_use_color() in place of true to format_render_diagnostics_text would cover both.

Your environment
  • q2: q2 (quarto 2) 0.43.0-nightly.20261109 (nightly built from 8f17e95), and q2 v0.42.0.
  • Quarto 1 for comparison: development build of quarto-dev/quarto-cli@fa74261.
  • OS: macOS 27.2 (arm64).
  • Terminal, no IDE.
主要语言
Rust
星标
302
派生
22
平均合并
5 小时 6 分钟
30 天内合并 PR
207

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

quarto-dev/q2 的其他 Issue

查看 quarto-dev/q2 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。