aboutsummaryrefslogtreecommitdiffstats
path: root/src/term.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/term.rs')
-rw-r--r--src/term.rs65
1 files changed, 46 insertions, 19 deletions
diff --git a/src/term.rs b/src/term.rs
index d7e8fb2..374105a 100644
--- a/src/term.rs
+++ b/src/term.rs
@@ -8,9 +8,38 @@
use core::libc::c_int;
pub use ios::{cooked,cbreak,raw,echo,size};
-use info::{escape,escape2};
+use info::{escape,escape1,escape2};
use trie::Trie;
+enum Keypress {
+ KeyCharacter(char),
+ KeyBackspace,
+ KeyReturn,
+ KeyTab,
+ KeyCtrl(char),
+ KeyF(int),
+ KeyUp,
+ KeyDown,
+ KeyLeft,
+ KeyRight,
+ KeyHome,
+ KeyEnd,
+ KeyInsert,
+ KeyDelete,
+ KeyEscape,
+}
+
+enum Color {
+ ColorBlack = 0,
+ ColorRed,
+ ColorGreen,
+ ColorYellow,
+ ColorBlue,
+ ColorMagenta,
+ ColorCyan,
+ ColorWhite,
+}
+
struct Term {
priv r: Reader,
priv w: Writer,
@@ -39,6 +68,14 @@ impl Term {
self.w.move(col, row);
}
+ pub fn fg_color (&mut self, color: Color) {
+ self.w.fg_color(color);
+ }
+
+ pub fn bg_color (&mut self, color: Color) {
+ self.w.bg_color(color);
+ }
+
pub fn cursor (&mut self, enabled: bool) {
self.w.cursor(enabled);
}
@@ -84,6 +121,14 @@ impl Writer {
}
}
+ fn fg_color (&mut self, color: Color) {
+ self.buf.push_str(escape1("setaf", color as int));
+ }
+
+ fn bg_color (&mut self, color: Color) {
+ self.buf.push_str(escape1("setab", color as int));
+ }
+
fn cursor (&mut self, enabled: bool) {
if enabled {
self.buf.push_str(escape("civis"));
@@ -123,24 +168,6 @@ impl Drop for Writer {
}
}
-enum Keypress {
- KeyCharacter(char),
- KeyBackspace,
- KeyReturn,
- KeyTab,
- KeyCtrl(char),
- KeyF(int),
- KeyUp,
- KeyDown,
- KeyLeft,
- KeyRight,
- KeyHome,
- KeyEnd,
- KeyInsert,
- KeyDelete,
- KeyEscape,
-}
-
struct Reader {
priv escapes: ~Trie<Keypress>,
priv buf: ~str,