1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//! `input` example

#[cfg(any(test, doc))]
use crate::*;
#[cfg(not(any(test, doc)))]
use libnotcurses_sys::*;

fn main() -> NcResult<()> {
    let nc = unsafe { Nc::with_flags(NcOptions::SUPPRESS_BANNERS)? };
    let splane = unsafe { nc.stdplane() };
    splane.set_scrolling(true);

    putstrln!(splane, "Input example.\nPress any key to continue:")?;
    nc.render()?;
    let rec = nc.get_blocking(None)?;
    putstrln!(splane, "Received: {:?}\n", rec)?;

    putstrln!(
        splane,
        "Press more keys to see their input. You can exit with F1.\n"
    )?;

    let mut input = NcInput::new_empty();
    loop {
        let rec = nc.get_nblock(Some(&mut input))?;
        match rec {
            NcReceived::Char(ch) => {
                putstrln!(
                    splane,
                    "char: '{0}' \n{1:?} {2:?}\n",
                    ch,
                    input,
                    input.char()
                )?;
            }
            NcReceived::Event(ev) => {
                putstrln!(
                    splane,
                    "event: {0:?}\n  {1:?} {2:?}\n",
                    ev.name(),
                    input,
                    input.char()
                )?;
                match ev {
                    NcKey::F01 => break,
                    _ => (),
                }
            }
            NcReceived::Other(o) => {
                putstrln!(
                    splane,
                    "other (this shouldn't happen): {0:?} \n{1:?}\n",
                    o,
                    input
                )?;
            }
            _ => (),
        }
    }

    unsafe { nc.stop()? };
    Ok(())
}