diff options
author | Andrew Gallant <jamslam@gmail.com> | 2017-01-13 19:02:55 -0500 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2017-01-13 19:03:03 -0500 |
commit | a7d0e4066870178f8529382fe273ce1ce580741d (patch) | |
tree | d2dd826f522b273843cfacf906e5f783d33f131a /termcolor | |
parent | 7a951f103a2abeba5af53905e168a09179704b48 (diff) |
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)
Diffstat (limited to 'termcolor')
-rw-r--r-- | termcolor/src/lib.rs | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/termcolor/src/lib.rs b/termcolor/src/lib.rs index 8b434d97..b90bb276 100644 --- a/termcolor/src/lib.rs +++ b/termcolor/src/lib.rs @@ -787,37 +787,46 @@ impl<W: io::Write> Ansi<W> { 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!(), } } |