notcurses/rust/examples/full-input.rs
joseLuís a880eaf018 rust: new NcMenu PoC example & more error refactoring.
- new example poc-menu (WIP).
- improve constructors for NcMenu*.
- divide NcMenu* methods into submodules.
- fix return type for NcPlane constructors.
- use NcResult on functions returning references.
- fix a couple of Notcurses methods.
- add more NcChannelPair methods.
- refactor NcInput constructors.
- rename error_ptr![] to error_ref_mut![]
- new macro cstring_mut![].
- new error_ref![] macro.
- update examples & tests.
- bump version in readme.
2020-12-26 20:29:06 +01:00

44 lines
894 B
Rust

//! Input
//!
//! https://github.com/dankamongmen/notcurses/blob/master/USAGE.md#input
//!
use libnotcurses_sys::*;
fn main() -> NcResult<()> {
let nc = Notcurses::with_flags(
NCOPTION_SUPPRESS_BANNERS
| NCOPTION_NO_WINCH_SIGHANDLER
| NCOPTION_NO_QUIT_SIGHANDLERS
)?;
// doesn't seem to be necessary:
// let ready = unsafe { notcurses_inputready_fd(nc) };
// println!("{}", ready);
println!("Exit with F1\n");
let mut input = NcInput::new_empty();
loop {
let key = notcurses_getc_nblock(nc, &mut input);
if key as i32 != -1 {
println!("'{0}' ({1:x})\n{2:?}", key, key as u32, input);
}
rsleep![nc, 0, 10];
match key {
NCKEY_F01 => break,
_ => (),
}
}
println!("\nExiting...");
rsleep![nc, 1, 500];
nc.stop()?;
Ok(())
}