From 3ba6bd4ae0d52d43b2bb4ffda76720e1316dae27 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 25 Jan 2015 12:07:45 +0100 Subject: vtcol.rs: clear screen upon exit --- vtcol.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/vtcol.rs b/vtcol.rs index a98afa8..b0bff7d 100644 --- a/vtcol.rs +++ b/vtcol.rs @@ -228,12 +228,29 @@ 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); } -- cgit v1.2.3