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

Aperta Adatta ai principianti
#1,135 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
88/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
cli

Direzione di ricerca

Leggi crates/quarto/src/commands/render.rs, in particolare il controllo esistente di NO_COLOR e del terminale di stderr vicino alla riga 632 e la chiamata di formattazione della diagnostica vicino alla riga 1442. Passa la decisione esistente sul terminale e sul colore a format_render_diagnostics_text invece di attivare il colore in modo fisso. Riproduci il problema con i passaggi forniti NO_COLOR=1 q2 render index.qmd; il lavoro è completato quando la diagnostica non contiene sequenze di escape per il colore né OSC 8 se NO_COLOR è impostato o stderr è reindirizzato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.
Lingua principale
Rust
Stelle
302
Fork
22
Merge medio
5h 6m
PR unite (30g)
207

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di quarto-dev/q2

Tutte le issue di quarto-dev/q2

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.