diff options
| author | Corey Richardson <corey@octayn.net> | 2013-05-30 13:21:41 -0400 |
|---|---|---|
| committer | Corey Richardson <corey@octayn.net> | 2013-05-31 20:02:49 -0400 |
| commit | 100ee8409789edb290a1d3309f70286c6a799a7c (patch) | |
| tree | e7801436efd888383827a7f97b142aabd9b5fe01 /src | |
| parent | 1f27c6306d9f376f9b629a98f8a57c2e43e59b41 (diff) | |
| download | rust-100ee8409789edb290a1d3309f70286c6a799a7c.tar.gz rust-100ee8409789edb290a1d3309f70286c6a799a7c.zip | |
Only output colors if colors are supported (removes burden from caller)
Diffstat (limited to 'src')
| -rw-r--r-- | src/libextra/term.rs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/libextra/term.rs b/src/libextra/term.rs index eb1a0897e33..691a6b4dc62 100644 --- a/src/libextra/term.rs +++ b/src/libextra/term.rs @@ -43,8 +43,6 @@ pub static color_bright_magenta: u8 = 13u8; pub static color_bright_cyan: u8 = 14u8; pub static color_bright_white: u8 = 15u8; -pub fn esc(writer: @io::Writer) { writer.write([0x1bu8, '[' as u8]); } - pub struct Terminal { color_supported: bool, priv out: @io::Writer, @@ -75,12 +73,20 @@ pub impl Terminal { return Ok(Terminal {out: out, ti: inf, color_supported: cs}); } fn fg(&self, color: u8) { - self.out.write(expand(*self.ti.strings.find_equiv(&("setaf")).unwrap(), [Number(color as int)], [], [])); + if self.color_supported { + self.out.write(expand(*self.ti.strings.find_equiv(&("setaf")).unwrap(), + [Number(color as int)], [], [])); + } } fn bg(&self, color: u8) { - self.out.write(expand(*self.ti.strings.find_equiv(&("setab")).unwrap(), [Number(color as int)], [], [])); + if self.color_supported { + self.out.write(expand(*self.ti.strings.find_equiv(&("setab")).unwrap(), + [Number(color as int)], [], [])); + } } fn reset(&self) { - self.out.write(expand(*self.ti.strings.find_equiv(&("op")).unwrap(), [], [], [])); + if self.color_supported { + self.out.write(expand(*self.ti.strings.find_equiv(&("op")).unwrap(), [], [], [])); + } } } |
