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,6 +96,13 @@ 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();
if ansi <= 7 {
self.csi(&[
b'3',
b'0' + ansi,
b'm',
])
} else {
self.csi(&[ self.csi(&[
b'3', b'3',
b'8', b'8',
@ -108,9 +115,18 @@ pub trait TermWrite {
b'm', 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();
if ansi <= 7 {
self.csi(&[
b'4',
b'0' + ansi,
b'm',
])
} else {
self.csi(&[ self.csi(&[
b'4', b'4',
b'8', b'8',
@ -123,6 +139,7 @@ pub trait TermWrite {
b'm', 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> {
self.rendition(mode as u8) self.rendition(mode as u8)