summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <phg42.2a@gmail.com>2015-01-25 12:07:45 +0100
committerPhilipp Gesang <phg42.2a@gmail.com>2015-01-25 12:08:28 +0100
commit3ba6bd4ae0d52d43b2bb4ffda76720e1316dae27 (patch)
tree5917475889e622c44d507a4f8d0c35f786bc5024
parent4d73b5a4e92cbd200cbcdc35b120b44bef7743e5 (diff)
downloadvtcol-3ba6bd4ae0d52d43b2bb4ffda76720e1316dae27.tar.gz
vtcol.rs: clear screen upon exit
-rw-r--r--vtcol.rs22
1 files changed, 20 insertions, 2 deletions
diff --git a/vtcol.rs b/vtcol.rs
index a98afa8..b0bff7d 100644
--- a/vtcol.rs
+++ b/vtcol.rs
@@ -229,11 +229,28 @@ get_console_fd
}
fn
+write_to_term (fd : fd_t, buf : &str)
+{
+ let len = buf.len() as u32;
+ let raw = std::ffi::CString::from_slice(buf.as_bytes());
+ unsafe { libc::write(fd, raw.as_ptr() as *const libc::c_void, len) };
+}
+
+fn
+clear_term (fd : fd_t)
+{
+ let clear : &str = "\x1b[2J";
+ let cursor : &str = "\x1b[1;1H";
+ write_to_term(fd, clear);
+ write_to_term(fd, cursor);
+}
+
+fn
main ()
{
let color_set : [[&str; 7]; PALETTE_SIZE];
- //let mut pal : Palette = Palette::new(&DEFAULT_COLORS);
- let mut pal : Palette = Palette::new(&SOLARIZED_COLORS);
+ let mut pal : Palette = Palette::new(&DEFAULT_COLORS);
+ //let mut pal : Palette = Palette::new(&SOLARIZED_COLORS);
println!("{}", pal);
//println!("{:?}", pal);
let fd = get_console_fd(None).unwrap();
@@ -242,5 +259,6 @@ main ()
if unsafe { ioctl(fd, PIO_CMAP, std::mem::transmute(&mut pal)) } < 0 {
panic!("PIO_CMAP, ioctl failed to insert new palette")
}
+ clear_term(fd);
}