diff options
author | Philipp Gesang <phg42.2a@gmail.com> | 2015-01-25 12:07:45 +0100 |
---|---|---|
committer | Philipp Gesang <phg42.2a@gmail.com> | 2015-01-25 12:08:28 +0100 |
commit | 3ba6bd4ae0d52d43b2bb4ffda76720e1316dae27 (patch) | |
tree | 5917475889e622c44d507a4f8d0c35f786bc5024 | |
parent | 4d73b5a4e92cbd200cbcdc35b120b44bef7743e5 (diff) | |
download | vtcol-3ba6bd4ae0d52d43b2bb4ffda76720e1316dae27.tar.gz |
vtcol.rs: clear screen upon exit
-rw-r--r-- | vtcol.rs | 22 |
1 files changed, 20 insertions, 2 deletions
@@ -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); } |