Use 8-color mode when possible.

This commit is contained in:
Jeremy Soller 2016-03-17 11:27:03 -06:00 committed by Ticki
parent b288548756
commit cd59514615
1 changed files with 39 additions and 22 deletions

View File

@ -96,32 +96,49 @@ pub trait TermWrite {
/// Set foreground color. /// Set foreground color.
fn color(&mut self, color: Color) -> io::Result<usize> { fn color(&mut self, color: Color) -> io::Result<usize> {
let ansi = color.to_ansi_val(); let ansi = color.to_ansi_val();
self.csi(&[ if ansi <= 7 {
b'3', self.csi(&[
b'8', b'3',
b';', b'0' + ansi,
b'5', b'm',
b';', ])
b'0' + ansi / 100, } else {
b'0' + ansi / 10 % 10, self.csi(&[
b'0' + ansi % 10, b'3',
b'm', b'8',
]) b';',
b'5',
b';',
b'0' + ansi / 100,
b'0' + ansi / 10 % 10,
b'0' + ansi % 10,
b'm',
])
}
} }
/// Set background color. /// Set background color.
fn bg_color(&mut self, color: Color) -> io::Result<usize> { fn bg_color(&mut self, color: Color) -> io::Result<usize> {
let ansi = color.to_ansi_val(); let ansi = color.to_ansi_val();
self.csi(&[
b'4', if ansi <= 7 {
b'8', self.csi(&[
b';', b'4',
b'5', b'0' + ansi,
b';', b'm',
b'0' + ansi / 100, ])
b'0' + ansi / 10 % 10, } else {
b'0' + ansi % 10, self.csi(&[
b'm', b'4',
]) b'8',
b';',
b'5',
b';',
b'0' + ansi / 100,
b'0' + ansi / 10 % 10,
b'0' + ansi % 10,
b'm',
])
}
} }
/// Set rendition mode (SGR). /// Set rendition mode (SGR).
fn style(&mut self, mode: Style) -> io::Result<usize> { fn style(&mut self, mode: Style) -> io::Result<usize> {