From e81fb25b7aac5fcb20eeed3892eaf05d17944295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Souto?= Date: Fri, 6 Mar 2020 13:48:38 +0000 Subject: [PATCH] Fix unwanted ANSI Reset Sequence (#4268) --- cli/colors.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cli/colors.rs b/cli/colors.rs index 056a6e0d0f..5afd773cd5 100644 --- a/cli/colors.rs +++ b/cli/colors.rs @@ -35,11 +35,12 @@ pub fn enable_ansi() { } fn style(s: &str, colorspec: ColorSpec) -> impl fmt::Display { + if !use_color() { + return String::from(s); + } let mut v = Vec::new(); let mut ansi_writer = Ansi::new(&mut v); - if use_color() { - ansi_writer.set_color(&colorspec).unwrap(); - } + ansi_writer.set_color(&colorspec).unwrap(); ansi_writer.write_all(s.as_bytes()).unwrap(); ansi_writer.reset().unwrap(); String::from_utf8_lossy(&v).into_owned()