aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-04-02 01:49:02 -0500
committerJesse Luehrs <doy@tozt.net>2013-04-02 01:49:02 -0500
commitaf687db57919a249ba8f4b2ca6176bfc49648269 (patch)
tree95f8f5c13c66c128490683f144ae25d80b9a842d
parent368fb132f840f35ecaaa3e9654a3d2e781b4470c (diff)
downloadrust-term-af687db57919a249ba8f4b2ca6176bfc49648269.tar.gz
rust-term-af687db57919a249ba8f4b2ca6176bfc49648269.zip
fixup and cleanup a bit
-rw-r--r--src/term.rs71
1 files changed, 43 insertions, 28 deletions
diff --git a/src/term.rs b/src/term.rs
index 2572942..b84ed06 100644
--- a/src/term.rs
+++ b/src/term.rs
@@ -29,6 +29,7 @@ enum Keypress {
KeyEscape,
}
+#[deriving(Eq)]
enum Color {
ColorBlack = 0,
ColorRed,
@@ -171,68 +172,82 @@ impl Writer {
}
fn fg_color (&mut self, color: Color) {
- self.state.fg = Some(color);
- self.buf.push_str(escape1("setaf", color as int));
+ match self.state.fg {
+ Some(c) if c == color => {}
+ _ => {
+ self.state.fg = Some(color);
+ self.buf.push_str(escape1("setaf", color as int));
+ }
+ }
}
fn bg_color (&mut self, color: Color) {
- self.state.bg = Some(color);
- self.buf.push_str(escape1("setab", color as int));
+ match self.state.bg {
+ Some(c) if c == color => {}
+ _ => {
+ self.state.bg = Some(color);
+ self.buf.push_str(escape1("setab", color as int));
+ }
+ }
}
fn underline (&mut self, enabled: bool) {
- self.state.underline = enabled;
- if enabled {
- self.buf.push_str(escape("smul"));
- }
- else {
- self.buf.push_str(escape("rmul"));
+ if self.state.underline != enabled {
+ self.state.underline = enabled;
+ if enabled {
+ self.buf.push_str(escape("smul"));
+ }
+ else {
+ self.buf.push_str(escape("rmul"));
+ }
}
}
fn standout (&mut self, enabled: bool) {
- self.state.standout = enabled;
- if enabled {
- self.buf.push_str(escape("smso"));
- }
- else {
- self.buf.push_str(escape("rmso"));
+ if self.state.standout != enabled {
+ self.state.standout = enabled;
+ if enabled {
+ self.buf.push_str(escape("smso"));
+ }
+ else {
+ self.buf.push_str(escape("rmso"));
+ }
}
}
fn reverse (&mut self, enabled: bool) {
if self.state.reverse != enabled {
- if self.state.reverse {
- self.apply_state();
+ self.state.reverse = enabled;
+ if enabled {
+ self.buf.push_str(escape("rev"));
}
else {
- self.buf.push_str(escape("rev"));
+ self.apply_state();
}
- self.state.reverse = enabled;
}
}
fn bold (&mut self, enabled: bool) {
if self.state.bold != enabled {
- if self.state.bold {
- self.apply_state();
+ self.state.bold = enabled;
+ if enabled {
+ self.buf.push_str(escape("bold"));
}
else {
- self.buf.push_str(escape("bold"));
+ self.apply_state();
}
- self.state.bold = enabled;
}
}
fn blink (&mut self, enabled: bool) {
if self.state.blink != enabled {
- if self.state.blink {
- self.apply_state();
+ self.state.blink = enabled;
+ if enabled {
+ self.buf.push_str(escape("blink"));
}
else {
- self.buf.push_str(escape("blink"));
+ self.apply_state();
}
- self.state.blink = enabled;
}
}