cli: Emit escape codes only if output is a tty (#1188)

This commit is contained in:
Johannes Wolf 2023-05-19 16:47:25 +02:00 committed by GitHub
parent 42c3a6fa72
commit 42f1586880
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 1 deletions

1
Cargo.lock generated
View File

@ -2276,6 +2276,7 @@ dependencies = [
name = "typst-cli"
version = "0.3.0"
dependencies = [
"atty",
"chrono",
"clap 4.2.5",
"clap_complete",

View File

@ -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"

View File

@ -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);
if atty::is(Stream::Stderr) {
write!(w, "{esc}c{esc}[1;1H")?;
}
w.set_color(&color)?;
write!(w, "watching")?;