From 9dc847c8b58d835247a828c25b9e6bc04d601eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?joseLu=C3=ADs?= Date: Thu, 20 Aug 2020 16:40:15 +0200 Subject: [PATCH] rust: add simple wrapper over ncdirect_init --- rust/examples/direct-image.rs | 7 +--- rust/src/direct.rs | 71 +++++++++++++++++++++++++++++++++++ rust/src/lib.rs | 2 + 3 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 rust/src/direct.rs diff --git a/rust/examples/direct-image.rs b/rust/examples/direct-image.rs index 3a53e9d11..b50ca7937 100644 --- a/rust/examples/direct-image.rs +++ b/rust/examples/direct-image.rs @@ -2,14 +2,9 @@ use cstr_core::CString; use libnotcurses_sys as nc; -extern "C" { - fn libc_stdout() -> *mut nc::_IO_FILE; -} - fn main() { unsafe { - let _ = libc::setlocale(libc::LC_ALL, CString::new("").unwrap().as_ptr()); - let ncd: *mut nc::ncdirect = nc::ncdirect_init(std::ptr::null(), libc_stdout()); + let ncd = nc::ncdirect_start(); render_image(&mut *ncd, nc::ncblitter_e_NCBLIT_1x1); render_image(&mut *ncd, nc::ncblitter_e_NCBLIT_2x1); diff --git a/rust/src/direct.rs b/rust/src/direct.rs new file mode 100644 index 000000000..60df59bb9 --- /dev/null +++ b/rust/src/direct.rs @@ -0,0 +1,71 @@ +// functions already exported by bindgen : 30 +// ------------------------------------------ +// ncdirect_bg +// ncdirect_bg_default +// ncdirect_bg_palindex +// ncdirect_box +// ncdirect_canopen_images +// ncdirect_canutf8 +// ncdirect_clear +// ncdirect_cursor_disable +// ncdirect_cursor_down +// ncdirect_cursor_enable +// ncdirect_cursor_left +// ncdirect_cursor_move_yx +// ncdirect_cursor_pop +// ncdirect_cursor_push +// ncdirect_cursor_right +// ncdirect_cursor_up +// ncdirect_cursor_yx +// ncdirect_dim_x +// ncdirect_dim_y +// ncdirect_double_box +// ncdirect_fg +// ncdirect_fg_default +// ncdirect_fg_palindex +// ncdirect_hline_interp +// ncdirect_init +// ncdirect_palette_size +// ncdirect_printf_aligned +// ncdirect_putstr +// ncdirect_render_image +// ncdirect_rounded_box +// ncdirect_stop +// ncdirect_styles_off +// ncdirect_styles_on +// ncdirect_styles_set +// ncdirect_vline_interp +// + +use crate as ffi; +use ffi::ncdirect; + +extern "C" { + fn libc_stdout() -> *mut ffi::_IO_FILE; +} + +/// A simple ncdirect_init() wrapper +/// +/// Initialize a direct-mode notcurses context on the tty. +/// +/// Direct mode supportes a limited subset of notcurses routines, +/// and neither supports nor requires notcurses_render(). +/// This can be used to add color and styling to text in the standard output paradigm. +/// Returns NULL on error, including any failure initializing terminfo. +pub unsafe fn ncdirect_start() -> *mut ncdirect { + ffi::ncdirect_init(core::ptr::null(), libc_stdout()) +} + + +#[cfg(test)] +mod test { + // use super::ffi; + // use serial_test::serial; + /* + #[test] + #[serial] + fn () { + } + */ +} + diff --git a/rust/src/lib.rs b/rust/src/lib.rs index db074ae21..7f9c4a5c1 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -16,6 +16,7 @@ mod macros; mod cells; mod channel; +mod direct; mod key; mod keycodes; mod nc; @@ -25,6 +26,7 @@ mod plane; mod types; pub use cells::*; pub use channel::*; +pub use direct::*; pub use key::*; pub use keycodes::*; pub use nc::*;