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.
fn color(&mut self, color: Color) -> io::Result<usize> {
let ansi = color.to_ansi_val();
self.csi(&[
b'3',
b'8',
b';',
b'5',
b';',
b'0' + ansi / 100,
b'0' + ansi / 10 % 10,
b'0' + ansi % 10,
b'm',
])
if ansi <= 7 {
self.csi(&[
b'3',
b'0' + ansi,
b'm',
])
} else {
self.csi(&[
b'3',
b'8',
b';',
b'5',
b';',
b'0' + ansi / 100,
b'0' + ansi / 10 % 10,
b'0' + ansi % 10,
b'm',
])
}
}
/// Set background color.
fn bg_color(&mut self, color: Color) -> io::Result<usize> {
let ansi = color.to_ansi_val();
self.csi(&[
b'4',
b'8',
b';',
b'5',
b';',
b'0' + ansi / 100,
b'0' + ansi / 10 % 10,
b'0' + ansi % 10,
b'm',
])
if ansi <= 7 {
self.csi(&[
b'4',
b'0' + ansi,
b'm',
])
} else {
self.csi(&[
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).
fn style(&mut self, mode: Style) -> io::Result<usize> {