From 6c81cb3b454c3e5a023fd2cc7bf629278d37bac5 Mon Sep 17 00:00:00 2001 From: nick black Date: Fri, 27 Mar 2020 06:27:26 -0400 Subject: [PATCH] rust: use libnotcurses-sys, add test --- rust/libnotcurses-sys/Cargo.toml | 1 + rust/notcurses/Cargo.toml | 2 ++ rust/notcurses/src/lib.rs | 30 ++++++++++++++++++++++++++++-- src/colloquy/Cargo.lock | 12 ++---------- src/colloquy/Cargo.toml | 3 ++- src/colloquy/src/main.rs | 18 ++++++++++++++++++ 6 files changed, 53 insertions(+), 13 deletions(-) diff --git a/rust/libnotcurses-sys/Cargo.toml b/rust/libnotcurses-sys/Cargo.toml index f8657628a..3f8be1efd 100644 --- a/rust/libnotcurses-sys/Cargo.toml +++ b/rust/libnotcurses-sys/Cargo.toml @@ -9,6 +9,7 @@ version = "1.2.4" links = "notcurses" build = "build.rs" edition = "2018" +categories = ["external-ffi-bindings"] [dependencies] libc = "0.2.66" [build-dependencies] diff --git a/rust/notcurses/Cargo.toml b/rust/notcurses/Cargo.toml index 5f82071d1..5bd8d3c16 100644 --- a/rust/notcurses/Cargo.toml +++ b/rust/notcurses/Cargo.toml @@ -12,3 +12,5 @@ homepage = "https://nick-black.com/dankwiki/index.php/Notcurses" [dependencies] libnotcurses-sys = "^1.2.4" +libc = "0.2.66" +libc-stdhandle = ">= 0.1.0" diff --git a/rust/notcurses/src/lib.rs b/rust/notcurses/src/lib.rs index 31e1bb209..96515c58f 100644 --- a/rust/notcurses/src/lib.rs +++ b/rust/notcurses/src/lib.rs @@ -1,7 +1,33 @@ +extern crate libnotcurses_sys as ffi; + +extern { + fn libc_stdout() -> *mut ffi::_IO_FILE; +} + #[cfg(test)] mod tests { + use super::*; + #[test] - fn it_works() { - assert_eq!(2 + 2, 4); + fn create_context() { + unsafe { + let _ = libc::setlocale(libc::LC_ALL, std::ffi::CString::new("").unwrap().as_ptr()); + let opts: ffi::notcurses_options = ffi::notcurses_options { + inhibit_alternate_screen: false, + loglevel: 0, + termtype: std::ptr::null(), + retain_cursor: false, + suppress_banner: false, + no_winch_sighandler: false, + no_quit_sighandlers: false, + renderfp: std::ptr::null_mut(), + margin_t: 0, + margin_r: 0, + margin_b: 0, + margin_l: 0, + }; + let nc = ffi::notcurses_init(&opts, libc_stdout()); + ffi::notcurses_stop(nc); + } } } diff --git a/src/colloquy/Cargo.lock b/src/colloquy/Cargo.lock index 04aca6f4d..5a10672b9 100644 --- a/src/colloquy/Cargo.lock +++ b/src/colloquy/Cargo.lock @@ -102,7 +102,8 @@ name = "colloquy" version = "0.1.0" dependencies = [ "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", - "notcurses 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", + "libnotcurses-sys 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -195,14 +196,6 @@ dependencies = [ "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "notcurses" -version = "1.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libnotcurses-sys 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "peeking_take_while" version = "0.1.2" @@ -372,7 +365,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" "checksum memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" "checksum nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6" -"checksum notcurses 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ae81c8e1543e0dc8c599fd0ddecf146cc52468b6f27fffcc21a4caa6cc3d358b" "checksum peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" "checksum pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" "checksum proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "6c09721c6781493a2a492a96b5a5bf19b65917fe6728884e7c44dd0c60ca3435" diff --git a/src/colloquy/Cargo.toml b/src/colloquy/Cargo.toml index ca1fd21e6..8b9674570 100644 --- a/src/colloquy/Cargo.toml +++ b/src/colloquy/Cargo.toml @@ -9,7 +9,8 @@ description = "Notcurses-based utility for command-line TUI widgets" homepage = "https://nick-black.com/dankwiki/index.php/Notcurses" [dependencies] -notcurses = ">= 1.2.3" +libc = ">= 0.2.66" +libnotcurses-sys = ">= 1.2.3" [dependencies.clap] version = ">= 2.33.0" diff --git a/src/colloquy/src/main.rs b/src/colloquy/src/main.rs index 48793314f..25cfbdaa2 100644 --- a/src/colloquy/src/main.rs +++ b/src/colloquy/src/main.rs @@ -8,4 +8,22 @@ fn main() { eprintln!("Needed a widget type"); std::process::exit(1); } + + let _ = libc::setlocale(libc::LC_ALL, std::ffi::CString::new("").unwrap().as_ptr()); + let opts: notcurses_options = libnotcurses-sys::notcurses_options { + inhibit_alternate_screen: true, + loglevel: 0, + termtype: std::ptr::null(), + retain_cursor: false, + suppress_banner: false, + no_winch_sighandler: false, + no_quit_sighandlers: false, + renderfp: std::ptr::null_mut(), + margin_t: 0, + margin_r: 0, + margin_b: 0, + margin_l: 0, + }; + let nc = notcurses_init(&opts, libc_stdout()); + notcurses_stop(nc); }