ncurses_rs/context/
mod.rs

1use std::collections::HashMap;
2use ::window::Window;
3
4/// A context that ncurses stores data about itself in
5pub struct Context {
6    /// A list of windows in the current ncurses context
7    pub win: HashMap<String, Window>
8
9}
10
11impl Drop for Context {
12    fn drop(&mut self){
13        unsafe { 
14            echo();
15            curs_set(1);
16            nocbreak();
17            endwin();
18        }
19    }
20}
21
22#[link(name="ncurses")]
23extern {
24    fn initscr();
25    fn endwin();
26    fn refresh();
27
28    fn cbreak();
29    fn nocbreak();
30
31    fn curs_set(on: u64);
32
33    fn echo();
34    fn noecho();
35}
36
37/// Create a ncurses root window and return a context
38pub fn init() -> Context {
39    unsafe {
40        initscr(); 
41        refresh(); 
42        cbreak();
43        noecho();
44        curs_set(0);
45    }
46    Context { win: HashMap::new() }
47}