aboutsummaryrefslogtreecommitdiffstats
path: root/src/screen.rs
blob: 5fedee13f62d29b50e3a9f38a451fb6babbbc991 (plain) (blame)
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
use libc;

enum ScreenImpl {}
pub struct Screen {
    pub rows: u32,
    pub cols: u32,

    screen_impl: *mut ScreenImpl,
}

impl Screen {
    pub fn new(rows: u32, cols: u32) -> Screen {
        let screen_impl = unsafe {
            vt100_screen_new(rows as libc::c_int, cols as libc::c_int)
        };
        Screen {
            rows: rows,
            cols: cols,
            screen_impl: screen_impl,
        }
    }
}

impl Drop for Screen {
    fn drop(&mut self) {
        unsafe { vt100_screen_delete(self.screen_impl) };
    }
}

extern "C" {
    fn vt100_screen_new(rows: libc::c_int, cols: libc::c_int) -> *mut ScreenImpl;
    fn vt100_screen_delete(screen: *mut ScreenImpl);
}

#[cfg(test)]
mod tests {
    #[test]
    fn ffi() {
        let ptr = unsafe { super::vt100_screen_new(24, 80) };
        assert!(!ptr.is_null());
        unsafe { super::vt100_screen_delete(ptr) };
    }
}