From a7d0e4066870178f8529382fe273ce1ce580741d Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Fri, 13 Jan 2017 19:02:55 -0500 Subject: [PATCH] Use basic SGR sequences when possible. In Emacs, its terminal apparently doesn't support "extended" sets of foreground/background colors. Unless we need to set an "intense" color, we should instead use one of the eight basic color codes. Also, remove the "intense" setting from the default set of colors. It doesn't do much anyway and enables the default color settings to work in Emacs out of the box. Fixes #182 (again) --- src/args.rs | 1 - termcolor/src/lib.rs | 51 ++++++++++++++++++++++++++------------------ 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/args.rs b/src/args.rs index 6030964..eeccb18 100644 --- a/src/args.rs +++ b/src/args.rs @@ -707,7 +707,6 @@ impl<'a> ArgMatches<'a> { "path:fg:magenta".parse().unwrap(), "line:fg:green".parse().unwrap(), "match:fg:red".parse().unwrap(), - "match:style:intense".parse().unwrap(), "match:style:bold".parse().unwrap(), ]; for spec_str in self.values_of_lossy_vec("colors") { diff --git a/termcolor/src/lib.rs b/termcolor/src/lib.rs index 8b434d9..b90bb27 100644 --- a/termcolor/src/lib.rs +++ b/termcolor/src/lib.rs @@ -787,37 +787,46 @@ impl Ansi { c: &Color, intense: bool, ) -> io::Result<()> { - macro_rules! w { - ($selfie:expr, $fg:expr, $clr:expr) => { - if $fg { - $selfie.write_str(concat!("\x1B[38;5;", $clr, "m")) + macro_rules! write_intense { + ($clr:expr) => { + if fg { + self.write_str(concat!("\x1B[38;5;", $clr, "m")) } else { - $selfie.write_str(concat!("\x1B[48;5;", $clr, "m")) + self.write_str(concat!("\x1B[48;5;", $clr, "m")) + } + } + } + macro_rules! write_normal { + ($clr:expr) => { + if fg { + self.write_str(concat!("\x1B[3", $clr, "m")) + } else { + self.write_str(concat!("\x1B[4", $clr, "m")) } } } if intense { match *c { - Color::Black => w!(self, fg, "8"), - Color::Blue => w!(self, fg, "12"), - Color::Green => w!(self, fg, "10"), - Color::Red => w!(self, fg, "9"), - Color::Cyan => w!(self, fg, "14"), - Color::Magenta => w!(self, fg, "13"), - Color::Yellow => w!(self, fg, "11"), - Color::White => w!(self, fg, "15"), + Color::Black => write_intense!("8"), + Color::Blue => write_intense!("12"), + Color::Green => write_intense!("10"), + Color::Red => write_intense!("9"), + Color::Cyan => write_intense!("14"), + Color::Magenta => write_intense!("13"), + Color::Yellow => write_intense!("11"), + Color::White => write_intense!("15"), Color::__Nonexhaustive => unreachable!(), } } else { match *c { - Color::Black => w!(self, fg, "0"), - Color::Blue => w!(self, fg, "4"), - Color::Green => w!(self, fg, "2"), - Color::Red => w!(self, fg, "1"), - Color::Cyan => w!(self, fg, "6"), - Color::Magenta => w!(self, fg, "5"), - Color::Yellow => w!(self, fg, "3"), - Color::White => w!(self, fg, "7"), + Color::Black => write_normal!("0"), + Color::Blue => write_normal!("4"), + Color::Green => write_normal!("2"), + Color::Red => write_normal!("1"), + Color::Cyan => write_normal!("6"), + Color::Magenta => write_normal!("5"), + Color::Yellow => write_normal!("3"), + Color::White => write_normal!("7"), Color::__Nonexhaustive => unreachable!(), } }