aboutsummaryrefslogtreecommitdiffstats
path: root/src/ffi.rs
blob: 284a98ca7b879601d12047cd509e6b3e97b0beb2 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use libc;

use types;

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

    pub fn vt100_screen_process_string(
        screen: *mut types::ScreenImpl,
        buf: *const libc::c_char,
        len: libc::size_t,
    ) -> libc::c_int;
    pub fn vt100_screen_get_string_plaintext(
        screen: *mut types::ScreenImpl,
        start: *const types::Loc,
        end: *const types::Loc,
        outp: *mut *mut libc::c_char,
        outlen: *mut libc::size_t,
    );
    pub fn vt100_screen_get_string_formatted(
        screen: *mut types::ScreenImpl,
        start: *const types::Loc,
        end: *const types::Loc,
        outp: *mut *mut libc::c_char,
        outlen: *mut libc::size_t,
    );

    pub fn vt100_screen_set_window_size(
        screen: *mut types::ScreenImpl,
        rows: libc::c_int,
        cols: libc::c_int,
    );
    pub fn vt100_screen_set_scrollback_length(
        screen: *mut types::ScreenImpl,
        rows: libc::c_int,
    );

    pub fn vt100_screen_cell_at(
        screen: *mut types::ScreenImpl,
        row: libc::c_int,
        col: libc::c_int,
    ) -> *mut types::CellImpl;

    // XXX: these wrappers (and all of ffi.c) only exist because rust can't
    // handle bitfields yet - once it can, these should be removed
    pub fn vt100_wrapper_screen_hide_cursor(screen: *mut types::ScreenImpl) -> libc::c_int;
    pub fn vt100_wrapper_screen_application_keypad(screen: *mut types::ScreenImpl) -> libc::c_int;
    pub fn vt100_wrapper_screen_application_cursor(screen: *mut types::ScreenImpl) -> libc::c_int;
    pub fn vt100_wrapper_screen_mouse_reporting_press(screen: *mut types::ScreenImpl) -> libc::c_int;
    pub fn vt100_wrapper_screen_mouse_reporting_press_release(screen: *mut types::ScreenImpl) -> libc::c_int;
    pub fn vt100_wrapper_screen_mouse_reporting_button_motion(screen: *mut types::ScreenImpl) -> libc::c_int;
    pub fn vt100_wrapper_screen_mouse_reporting_sgr_mode(screen: *mut types::ScreenImpl) -> libc::c_int;
    pub fn vt100_wrapper_screen_bracketed_paste(screen: *mut types::ScreenImpl) -> libc::c_int;
    pub fn vt100_wrapper_screen_visual_bell(screen: *mut types::ScreenImpl) -> libc::c_int;
    pub fn vt100_wrapper_screen_audible_bell(screen: *mut types::ScreenImpl) -> libc::c_int;
    pub fn vt100_wrapper_screen_update_title(screen: *mut types::ScreenImpl) -> libc::c_int;
    pub fn vt100_wrapper_screen_update_icon_name(screen: *mut types::ScreenImpl) -> libc::c_int;
    pub fn vt100_wrapper_screen_dirty(screen: *mut types::ScreenImpl) -> libc::c_int;
    pub fn vt100_wrapper_screen_clear_visual_bell(screen: *mut types::ScreenImpl);
    pub fn vt100_wrapper_screen_clear_audible_bell(screen: *mut types::ScreenImpl);
    pub fn vt100_wrapper_screen_clear_update_title(screen: *mut types::ScreenImpl);
    pub fn vt100_wrapper_screen_clear_update_icon_name(screen: *mut types::ScreenImpl);
    pub fn vt100_wrapper_screen_clear_dirty(screen: *mut types::ScreenImpl);
    pub fn vt100_wrapper_cell_is_wide(cell: *mut types::CellImpl) -> libc::c_int;
    pub fn vt100_wrapper_cell_attrs_bold(cell: *mut types::CellAttrs) -> libc::c_int;
    pub fn vt100_wrapper_cell_attrs_italic(cell: *mut types::CellAttrs) -> libc::c_int;
    pub fn vt100_wrapper_cell_attrs_underline(cell: *mut types::CellAttrs) -> libc::c_int;
    pub fn vt100_wrapper_cell_attrs_inverse(cell: *mut types::CellAttrs) -> libc::c_int;
}

#[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) };
    }
}