mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-10 01:29:05 -04:00
rust: add getc_blocking()
This commit is contained in:
parent
f29404616b
commit
9d7d7ebd8a
@ -4,23 +4,21 @@
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
||||
|
||||
use std::ffi::CStr;
|
||||
|
||||
extern {
|
||||
fn libc_stdout() -> *mut _IO_FILE;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
extern {
|
||||
fn libc_stdout() -> *mut _IO_FILE;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_notcurses_version() {
|
||||
unsafe {
|
||||
let c_str = unsafe {
|
||||
let s = notcurses_version();
|
||||
assert!(!s.is_null());
|
||||
CStr::from_ptr(s)
|
||||
std::ffi::CStr::from_ptr(s)
|
||||
};
|
||||
let r_str = c_str.to_str().unwrap();
|
||||
println!("rust-bound notcurses v{}", r_str);
|
||||
@ -32,7 +30,7 @@ mod tests {
|
||||
unsafe {
|
||||
let _ = libc::setlocale(libc::LC_ALL, std::ffi::CString::new("").unwrap().as_ptr());
|
||||
let opts: notcurses_options = notcurses_options {
|
||||
inhibit_alternate_screen: false,
|
||||
inhibit_alternate_screen: true,
|
||||
loglevel: 0,
|
||||
termtype: std::ptr::null(),
|
||||
retain_cursor: false,
|
||||
|
@ -1,13 +1,21 @@
|
||||
extern crate libnotcurses_sys as ffi;
|
||||
|
||||
extern {
|
||||
fn libc_stdout() -> *mut ffi::_IO_FILE;
|
||||
pub fn getc_blocking(_n: *mut ffi::notcurses, _ni: &mut ffi::ncinput) -> u32 {
|
||||
unsafe {
|
||||
let mut sigmask: ffi::sigset_t = std::mem::zeroed();
|
||||
ffi::sigemptyset(&mut sigmask);
|
||||
return ffi::notcurses_getc(_n, std::ptr::null(), &mut sigmask, _ni);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
extern {
|
||||
static stdout: *mut ffi::_IO_FILE;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_context() {
|
||||
unsafe {
|
||||
@ -26,7 +34,7 @@ mod tests {
|
||||
margin_b: 0,
|
||||
margin_l: 0,
|
||||
};
|
||||
let nc = ffi::notcurses_init(&opts, libc_stdout());
|
||||
let nc = ffi::notcurses_init(&opts, stdout);
|
||||
ffi::notcurses_stop(nc);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user