summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/src/main.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/cli/src/main.rs b/cli/src/main.rs
index df5c5c82..408fe2f2 100644
--- a/cli/src/main.rs
+++ b/cli/src/main.rs
@@ -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,