diff options
author | Jesse Luehrs <doy@tozt.net> | 2013-03-21 01:14:23 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2013-03-21 01:14:23 -0500 |
commit | 50db2cec5f96d2f26ab5363a1beb870ed6482abc (patch) | |
tree | 3e3668fcdf96ead4e06dbf176b6b2a17bd5175de /src/term.rs | |
parent | 0896e60afd21c9c6724fb06c6328bb890c4f911d (diff) | |
download | rust-term-50db2cec5f96d2f26ab5363a1beb870ed6482abc.tar.gz rust-term-50db2cec5f96d2f26ab5363a1beb870ed6482abc.zip |
turn this into an object
Diffstat (limited to 'src/term.rs')
-rw-r--r-- | src/term.rs | 58 |
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; |