mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-08 01:10:23 +00:00
6049e07d27
- made const NotcursesOptions constructors. - refactor Notcurses constructors to return NcResult. - pass NotcursesOptions by value, since it's Copy. - update tests. - add helper modules for Notcurses & NcPlane. - new initialization functions to be used in tests. - BONUS: - refactor NcDirect - update examples.
44 lines
884 B
Rust
44 lines
884 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();
|
|
|
|
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, 100];
|
|
|
|
match key {
|
|
NCKEY_F01 => break,
|
|
_ => (),
|
|
}
|
|
}
|
|
|
|
println!("\nExiting...");
|
|
|
|
rsleep![nc, 1000];
|
|
nc.stop()?;
|
|
Ok(())
|
|
}
|