aboutsummaryrefslogtreecommitdiffstats
path: root/examples/input.rs
blob: 49a7c55b3ecdb5351c793c1bb466bb444a457a6e (plain) (blame)
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
#[cfg(feature = "async")]
#[tokio::main]
async fn main() {
    let mut input = textmode::Input::new().await.unwrap();
    for arg in std::env::args().skip(1) {
        match arg.as_str() {
            "--disable-utf8" => input.parse_utf8(false),
            "--disable-ctrl" => input.parse_ctrl(false),
            "--disable-meta" => input.parse_meta(false),
            "--disable-special-keys" => input.parse_special_keys(false),
            "--disable-single" => input.parse_single(false),
            _ => panic!("unknown arg {}", arg),
        }
    }

    loop {
        let key = input.read_key().await.unwrap();
        if let Some(key) = key {
            print!("{:?}: ", key);
            let bytes = key.into_bytes();
            print!("{:?}\r\n", bytes);
            if bytes.contains(&3) {
                break;
            }
        } else {
            break;
        }
    }
}

#[cfg(not(feature = "async"))]
fn main() {
    let mut input = textmode::blocking::Input::new().unwrap();
    for arg in std::env::args().skip(1) {
        match arg.as_str() {
            "--disable-utf8" => input.parse_utf8(false),
            "--disable-ctrl" => input.parse_ctrl(false),
            "--disable-meta" => input.parse_meta(false),
            "--disable-special-keys" => input.parse_special_keys(false),
            "--disable-single" => input.parse_single(false),
            _ => panic!("unknown arg {}", arg),
        }
    }

    loop {
        let key = input.read_key().unwrap();
        if let Some(key) = key {
            print!("{:?}: ", key);
            let bytes = key.into_bytes();
            print!("{:?}\r\n", bytes);
            if bytes.contains(&3) {
                break;
            }
        } else {
            break;
        }
    }
}