Skip to content

Commit ca570f6

Browse files
committed
Only output colors if colors are supported (removes burden from caller)
1 parent e6e1984 commit ca570f6

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/libextra/term.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ pub static color_bright_magenta: u8 = 13u8;
4343
pub static color_bright_cyan: u8 = 14u8;
4444
pub static color_bright_white: u8 = 15u8;
4545

46-
pub fn esc(writer: @io::Writer) { writer.write([0x1bu8, '[' as u8]); }
47-
4846
pub struct Terminal {
4947
color_supported: bool,
5048
priv out: @io::Writer,
@@ -75,12 +73,20 @@ pub impl Terminal {
7573
return Ok(Terminal {out: out, ti: inf, color_supported: cs});
7674
}
7775
fn fg(&self, color: u8) {
78-
self.out.write(expand(*self.ti.strings.find_equiv(&("setaf")).unwrap(), [Number(color as int)], [], []));
76+
if self.color_supported {
77+
self.out.write(expand(*self.ti.strings.find_equiv(&("setaf")).unwrap(),
78+
[Number(color as int)], [], []));
79+
}
7980
}
8081
fn bg(&self, color: u8) {
81-
self.out.write(expand(*self.ti.strings.find_equiv(&("setab")).unwrap(), [Number(color as int)], [], []));
82+
if self.color_supported {
83+
self.out.write(expand(*self.ti.strings.find_equiv(&("setab")).unwrap(),
84+
[Number(color as int)], [], []));
85+
}
8286
}
8387
fn reset(&self) {
84-
self.out.write(expand(*self.ti.strings.find_equiv(&("op")).unwrap(), [], [], []));
88+
if self.color_supported {
89+
self.out.write(expand(*self.ti.strings.find_equiv(&("op")).unwrap(), [], [], []));
90+
}
8591
}
8692
}

0 commit comments

Comments
 (0)