diff options
| author | Johannes Wolf <519002+johannes-wolf@users.noreply.github.com> | 2023-05-19 16:47:25 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-19 16:47:25 +0200 |
| commit | 42f1586880d323442d7bf7cc2ec7bec70375b4d8 (patch) | |
| tree | 4466ebe6b1060efa35ba2c5197e74025d7f7b28e /cli | |
| parent | 42c3a6fa72be91c115e28e3866012b95b4d63cf4 (diff) | |
cli: Emit escape codes only if output is a tty (#1188)
Diffstat (limited to 'cli')
| -rw-r--r-- | cli/Cargo.toml | 1 | ||||
| -rw-r--r-- | cli/src/main.rs | 5 |
2 files changed, 5 insertions, 1 deletions
diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 8f90c3aa..ad08d99b 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -22,6 +22,7 @@ doc = false [dependencies] typst = { path = ".." } typst-library = { path = "../library" } +atty = "0.2" chrono = { version = "0.4", default-features = false, features = ["clock", "std"] } clap = { version = "4.2.4", features = ["derive", "env"] } codespan-reporting = "0.11" diff --git a/cli/src/main.rs b/cli/src/main.rs index 476a82ee..4e9bd43e 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -9,6 +9,7 @@ use std::io::{self, Write}; use std::path::{Path, PathBuf}; use std::process; +use atty::Stream; use clap::Parser; use codespan_reporting::diagnostic::{Diagnostic, Label}; use codespan_reporting::term::{self, termcolor}; @@ -282,7 +283,9 @@ fn status(command: &CompileSettings, status: Status) -> io::Result<()> { let color = status.color(); let mut w = StandardStream::stderr(ColorChoice::Auto); - write!(w, "{esc}c{esc}[1;1H")?; + if atty::is(Stream::Stderr) { + write!(w, "{esc}c{esc}[1;1H")?; + } w.set_color(&color)?; write!(w, "watching")?; |
