mirror of
https://github.com/typst/typst
synced 2025-05-16 10:05:28 +08:00
parent
0214569f3a
commit
ef1bf742f6
@ -71,7 +71,7 @@ fn set_failed() {
|
||||
|
||||
/// Print an application-level error (independent from a source file).
|
||||
fn print_error(msg: &str) -> io::Result<()> {
|
||||
let mut w = StandardStream::stderr(ColorChoice::Auto);
|
||||
let mut w = color_stream();
|
||||
let styles = term::Styles::default();
|
||||
|
||||
w.set_color(&styles.header_error)?;
|
||||
@ -296,8 +296,9 @@ fn status(command: &CompileSettings, status: Status) -> io::Result<()> {
|
||||
let message = status.message();
|
||||
let color = status.color();
|
||||
|
||||
let mut w = StandardStream::stderr(ColorChoice::Auto);
|
||||
let mut w = color_stream();
|
||||
if atty::is(Stream::Stderr) {
|
||||
// Clear the terminal.
|
||||
write!(w, "{esc}c{esc}[1;1H")?;
|
||||
}
|
||||
|
||||
@ -318,6 +319,15 @@ fn status(command: &CompileSettings, status: Status) -> io::Result<()> {
|
||||
w.flush()
|
||||
}
|
||||
|
||||
/// Get stderr with color support if desirable.
|
||||
fn color_stream() -> termcolor::StandardStream {
|
||||
termcolor::StandardStream::stderr(if atty::is(Stream::Stderr) {
|
||||
ColorChoice::Auto
|
||||
} else {
|
||||
ColorChoice::Never
|
||||
})
|
||||
}
|
||||
|
||||
/// The status in which the watcher can be.
|
||||
enum Status {
|
||||
Compiling,
|
||||
|
Loading…
x
Reference in New Issue
Block a user