Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: doy/rust-term
base: 65b07a461f
...
head fork: doy/rust-term
compare: 368fb132f8
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 138 additions and 1 deletion.
  1. +138 −1 src/term.rs
View
139 src/term.rs
@@ -80,6 +80,26 @@ impl Term {
self.w.reset_color();
}
+ pub fn underline (&mut self, enabled: bool) {
+ self.w.underline(enabled);
+ }
+
+ pub fn standout (&mut self, enabled: bool) {
+ self.w.standout(enabled);
+ }
+
+ pub fn reverse (&mut self, enabled: bool) {
+ self.w.reverse(enabled);
+ }
+
+ pub fn bold (&mut self, enabled: bool) {
+ self.w.bold(enabled);
+ }
+
+ pub fn blink (&mut self, enabled: bool) {
+ self.w.blink(enabled);
+ }
+
pub fn cursor (&mut self, enabled: bool) {
self.w.cursor(enabled);
}
@@ -105,10 +125,35 @@ impl Term {
struct Writer {
priv buf: ~str,
priv cleanup: bool,
+ priv state: AttrState,
+}
+
+struct AttrState {
+ fg: Option<Color>,
+ bg: Option<Color>,
+ underline: bool,
+ standout: bool,
+ reverse: bool,
+ bold: bool,
+ blink: bool,
}
fn Writer (cleanup: bool) -> Writer {
- Writer { buf: ~"", cleanup: cleanup }
+ let mut w = Writer { buf: ~"", cleanup: cleanup, state: AttrState() };
+ w.reset_attributes();
+ w
+}
+
+fn AttrState () -> AttrState {
+ AttrState {
+ fg: None,
+ bg: None,
+ underline: false,
+ standout: false,
+ reverse: false,
+ bold: false,
+ blink: false,
+ }
}
impl Writer {
@@ -126,17 +171,109 @@ impl Writer {
}
fn fg_color (&mut self, color: 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));
}
+ 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"));
+ }
+ }
+
+ 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"));
+ }
+ }
+
+ fn reverse (&mut self, enabled: bool) {
+ if self.state.reverse != enabled {
+ if self.state.reverse {
+ self.apply_state();
+ }
+ else {
+ self.buf.push_str(escape("rev"));
+ }
+ self.state.reverse = enabled;
+ }
+ }
+
+ fn bold (&mut self, enabled: bool) {
+ if self.state.bold != enabled {
+ if self.state.bold {
+ self.apply_state();
+ }
+ else {
+ self.buf.push_str(escape("bold"));
+ }
+ self.state.bold = enabled;
+ }
+ }
+
+ fn blink (&mut self, enabled: bool) {
+ if self.state.blink != enabled {
+ if self.state.blink {
+ self.apply_state();
+ }
+ else {
+ self.buf.push_str(escape("blink"));
+ }
+ self.state.blink = enabled;
+ }
+ }
+
fn reset_color (&mut self) {
+ self.state.fg = None;
+ self.state.bg = None;
self.buf.push_str(escape("op"));
}
+ fn reset_attributes (&mut self) {
+ self.state = AttrState();
+ self.apply_state();
+ }
+
+ fn apply_state (&mut self) {
+ self.buf.push_str(escape("sgr0"));
+ match self.state.fg {
+ Some(c) => self.fg_color(c),
+ None => (),
+ }
+ match self.state.bg {
+ Some(c) => self.bg_color(c),
+ None => (),
+ }
+ if self.state.underline {
+ self.underline(true);
+ }
+ if self.state.standout {
+ self.standout(true);
+ }
+ if self.state.reverse {
+ self.reverse(true);
+ }
+ if self.state.bold {
+ self.bold(true);
+ }
+ if self.state.blink {
+ self.blink(true);
+ }
+ }
+
fn cursor (&mut self, enabled: bool) {
if enabled {
self.buf.push_str(escape("civis"));

No commit comments for this range

Something went wrong with that request. Please try again.