1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-22 06:09:25 -05:00

Fix unwanted ANSI Reset Sequence (#4268)

This commit is contained in:
João Souto 2020-03-06 13:48:38 +00:00 committed by GitHub
parent 9a63902db5
commit e81fb25b7a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -35,11 +35,12 @@ pub fn enable_ansi() {
} }
fn style(s: &str, colorspec: ColorSpec) -> impl fmt::Display { fn style(s: &str, colorspec: ColorSpec) -> impl fmt::Display {
if !use_color() {
return String::from(s);
}
let mut v = Vec::new(); let mut v = Vec::new();
let mut ansi_writer = Ansi::new(&mut v); 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.write_all(s.as_bytes()).unwrap();
ansi_writer.reset().unwrap(); ansi_writer.reset().unwrap();
String::from_utf8_lossy(&v).into_owned() String::from_utf8_lossy(&v).into_owned()