rust: continue reworking the API & improve documentation
- remove _IO_FILE import and usage. - create handy constructors for NcDirect & Notcurses. (but can't implement destructors for copy types…). - when possible substitute mutable pointers `*mut` for mutable references `&mut` with associated lifetimes. - new widgets module, starting with NcReader & NcReaderOptions constructorsdankamongmen/clock_nanosleep_portable
parent
965a0771d8
commit
08a0da358e
@ -1,7 +1,18 @@
|
||||
//use cstr_core::CString;
|
||||
|
||||
//use libnotcurses_sys as nc;
|
||||
use libnotcurses_sys as nc;
|
||||
|
||||
fn main() {
|
||||
|
||||
unsafe {
|
||||
// let options = nc::NotcursesOptions::new();
|
||||
// let app = nc::Notcurses::with_options(&options);
|
||||
|
||||
let app = nc::Notcurses::new();
|
||||
|
||||
|
||||
|
||||
nc::notcurses_stop(app);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,5 @@
|
||||
//! Widgets
|
||||
//!
|
||||
|
||||
mod reader;
|
||||
pub use reader::*;
|
@ -0,0 +1,52 @@
|
||||
// functions already exported by bindgen : 11
|
||||
// ------------------------------------------
|
||||
// ncreader_clear
|
||||
// ncreader_contents
|
||||
// ncreader_create
|
||||
// ncreader_destroy
|
||||
// ncreader_move_down
|
||||
// ncreader_move_left
|
||||
// ncreader_move_right
|
||||
// ncreader_move_up
|
||||
// ncreader_offer_input
|
||||
// ncreader_plane
|
||||
// ncreader_write_egc
|
||||
//
|
||||
// static inline functions total: 0
|
||||
// -------------------------------------------
|
||||
|
||||
use crate::{
|
||||
ncreader_create,
|
||||
types::{NcPlane, NcReader, NcReaderOptions},
|
||||
};
|
||||
|
||||
/// `NcReader` constructor (wraps `ncreader_create`)
|
||||
///
|
||||
/// NcReader provides freeform input in a (possibly multiline) region, supporting
|
||||
/// optional readline keybindings. takes ownership of its plane, destroying it
|
||||
/// on any error (ncreader_destroy() otherwise destroys the ncplane).
|
||||
impl NcReader {
|
||||
/// Simple `NcReader` constructor
|
||||
pub unsafe fn new<'a>(plane: &mut NcPlane) -> &'a mut Self {
|
||||
Self::with_options(plane, &NcReaderOptions::new())
|
||||
}
|
||||
|
||||
/// `NcReader` constructor with options
|
||||
pub unsafe fn with_options<'a>(plane: &mut NcPlane, options: &NcReaderOptions) -> &'a mut Self {
|
||||
&mut *ncreader_create(plane, options)
|
||||
}
|
||||
}
|
||||
|
||||
impl NcReaderOptions {
|
||||
/// `NcReaderOptions` simple constructor
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
// channels used for input
|
||||
tchannels: 0,
|
||||
// attributes used for input
|
||||
tattrword: 0,
|
||||
// bitfield of NCREADER_OPTION_*
|
||||
flags: 0,
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue