1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
use ::context::Context; pub struct Window { /// the height of the window in characters height: u64, /// the width of the window in characters width: u64, /// the x-coordinate that the window starts at x: u64, /// the y-coordinate that the window starts at y: u64, /// the pointer to the actual window in memory pub ptr: *const u64 } #[link(name="ncurses")] extern { fn newwin(lines: u64, cols: u64, x: u64, y: u64) -> *const u64; fn delwin(ptr: *const u64); fn wrefresh(ptr: *const u64); } impl Window { /// Create a window and add it to the specified windowing context /// # Arguments /// /// * `name` - the name to register the window under /// * `height` - the height of the window /// * `width` - the width of the window /// * `x` - the starting x coordinate /// * `y` - the starting y coordinate /// * `context` - the ncurses context to create a window for pub fn create_win(name: String, height:u64, width:u64, x:u64, y:u64, context: &mut Context) { unsafe { // get the pointer from ncurses let ptr = newwin(height, width, x, y); // refresh the window to allow unbuffered output wrefresh(ptr); // add the window to the context for usage context.win.insert(name.clone(), Window { height, width, x, y, ptr} ); } } } impl Drop for Window { /// Clean up the window by removing it fn drop(&mut self) { unsafe { delwin(self.ptr); } } }