aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-04-01 22:52:45 -0500
committerJesse Luehrs <doy@tozt.net>2013-04-01 22:52:45 -0500
commit65b07a461f23385b3a6d1eab28135c55fef8b447 (patch)
tree6df4321172c66ef74423c19cd589e30151b3d04f
parent8dcdcdb964895df998ea06e84acd5577e2fe31b6 (diff)
downloadrust-term-65b07a461f23385b3a6d1eab28135c55fef8b447.tar.gz
rust-term-65b07a461f23385b3a6d1eab28135c55fef8b447.zip
add reset_color method
-rw-r--r--src/term.rs8
-rw-r--r--test/rl.rs34
2 files changed, 31 insertions, 11 deletions
diff --git a/src/term.rs b/src/term.rs
index 374105a..908d601 100644
--- a/src/term.rs
+++ b/src/term.rs
@@ -76,6 +76,10 @@ impl Term {
self.w.bg_color(color);
}
+ pub fn reset_color (&mut self) {
+ self.w.reset_color();
+ }
+
pub fn cursor (&mut self, enabled: bool) {
self.w.cursor(enabled);
}
@@ -129,6 +133,10 @@ impl Writer {
self.buf.push_str(escape1("setab", color as int));
}
+ fn reset_color (&mut self) {
+ self.buf.push_str(escape("op"));
+ }
+
fn cursor (&mut self, enabled: bool) {
if enabled {
self.buf.push_str(escape("civis"));
diff --git a/test/rl.rs b/test/rl.rs
index 4787c78..9355f8d 100644
--- a/test/rl.rs
+++ b/test/rl.rs
@@ -1,6 +1,6 @@
extern mod term;
use term::{KeyCharacter,KeyEscape,KeyUp,KeyDown,KeyLeft,KeyRight,KeyF};
-use term::{Color,ColorWhite,ColorRed};
+use term::{Color,ColorRed};
fn term_app (body: &fn (r: &mut term::Term)) {
do term::ios::preserve {
@@ -10,24 +10,36 @@ fn term_app (body: &fn (r: &mut term::Term)) {
}
}
-fn draw_map (term: &mut term::Term, color: Color, rows: uint, cols: uint) {
- term.fg_color(color);
+fn draw_map (term: &mut term::Term, color: Option<Color>,
+ rows: uint, cols: uint) {
+ match color {
+ Some(c) => term.fg_color(c),
+ None => term.reset_color(),
+ }
for uint::range(0, rows) |i| {
term.move(0, i);
term.write(str::repeat(".", cols));
}
}
-fn draw_character (term: &mut term::Term, color: Color, x: uint, y: uint) {
+fn draw_character (term: &mut term::Term, color: Option<Color>,
+ x: uint, y: uint) {
term.move(x, y);
- term.fg_color(color);
+ match color {
+ Some(c) => term.fg_color(c),
+ None => term.reset_color(),
+ }
term.write("@");
term.move(x, y);
}
-fn draw_ground (term: &mut term::Term, color: Color, x: uint, y: uint) {
+fn draw_ground (term: &mut term::Term, color: Option<Color>,
+ x: uint, y: uint) {
term.move(x, y);
- term.fg_color(color);
+ match color {
+ Some(c) => term.fg_color(c),
+ None => term.reset_color(),
+ }
term.write(".");
}
@@ -37,12 +49,12 @@ fn main () {
do term_app |term| {
let mut (x, y) = (0u, 0u);
let mut cursor = true;
- let mut color = ColorWhite;
+ let mut color = None;
draw_map(term, color, rows, cols);
loop {
- draw_character(term, ColorWhite, x, y);
+ draw_character(term, None, x, y);
let k = match term.read() {
Some(key) => key,
None => break,
@@ -58,11 +70,11 @@ fn main () {
KeyCharacter('l') | KeyRight if x < cols - 1 => { x += 1 }
KeyF(1) => {
- color = ColorRed;
+ color = Some(ColorRed);
draw_map(term, color, rows, cols);
}
KeyF(6) => {
- color = ColorWhite;
+ color = None;
draw_map(term, color, rows, cols);
}