aboutsummaryrefslogtreecommitdiffstats
path: root/src/term.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-03-21 01:14:23 -0500
committerJesse Luehrs <doy@tozt.net>2013-03-21 01:14:23 -0500
commit50db2cec5f96d2f26ab5363a1beb870ed6482abc (patch)
tree3e3668fcdf96ead4e06dbf176b6b2a17bd5175de /src/term.rs
parent0896e60afd21c9c6724fb06c6328bb890c4f911d (diff)
downloadrust-term-50db2cec5f96d2f26ab5363a1beb870ed6482abc.tar.gz
rust-term-50db2cec5f96d2f26ab5363a1beb870ed6482abc.zip
turn this into an object
Diffstat (limited to 'src/term.rs')
-rw-r--r--src/term.rs58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/term.rs b/src/term.rs
index a2cd24f..faceb12 100644
--- a/src/term.rs
+++ b/src/term.rs
@@ -3,6 +3,64 @@
#[crate_type = "lib"];
pub use ios::{cooked,cbreak,raw,echo,size,isatty};
+use info::{init,escape,escape2};
+
+struct Writer {
+ priv cleanup: bool,
+ priv alternate: bool,
+}
+
+pub fn Writer (cleanup: bool) -> Writer {
+ init();
+ Writer { cleanup: cleanup, alternate: false }
+}
+
+impl Writer {
+ pub fn clear (&self) {
+ io::print(escape("clear"));
+ }
+
+ pub fn move (&self, col: uint, row: uint) {
+ if col == 0u && row == 0u {
+ io::print(escape("home"));
+ }
+ else {
+ io::print(escape2("cup", row as int, col as int));
+ }
+ }
+
+ pub fn cursor (&self, enabled: bool) {
+ if enabled {
+ io::print(escape("civis"));
+ }
+ else {
+ io::print(escape("cnorm"));
+ }
+ }
+
+ pub fn alternate_screen (&mut self, enable: bool) {
+ if enable {
+ io::print(escape("smcup"));
+ self.alternate = true;
+ }
+ else {
+ io::print(escape("rmcup"));
+ self.alternate = false;
+ }
+ }
+}
+
+impl Drop for Writer {
+ fn finalize (&self) {
+ if self.cleanup {
+ if self.alternate {
+ io::print(escape("rmcup"));
+ }
+ io::print(escape("sgr0"));
+ io::print(escape("cnorm"));
+ }
+ }
+}
pub mod ios;
pub mod info;