diff options
author | João Souto <joao.jpgs@hotmail.com> | 2020-03-06 13:48:38 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-06 08:48:38 -0500 |
commit | e81fb25b7aac5fcb20eeed3892eaf05d17944295 (patch) | |
tree | 71f851a7dc148909dcce506e7022fd3921ef2aae | |
parent | 9a63902db5bc33f3130c7227299cfb3b5be400ae (diff) |
Fix unwanted ANSI Reset Sequence (#4268)
-rw-r--r-- | cli/colors.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/cli/colors.rs b/cli/colors.rs index 056a6e0d0..5afd773cd 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() |