我正在尝试 Rust,到目前为止我真的很喜欢它。我正在开发一个需要从用户那里获取箭头键输入的工具。到目前为止,我已经得到了一些半工作的东西:如果我按住某个键一段时间,相关的函数就会被调用。然而,这远非瞬时的。
到目前为止我所得到的:
let mut stdout = io::stdout().into_raw_mode();
let mut stdin = termion::async_stdin();
// let mut stdin = io::stdin();
let mut it = stdin.keys(); //iterator object
loop {
//copied straight from GitLab: https://gitlab.redox-os.org/redox-os/termion/-/issues/168
let b = it.next();
match b {
Some(x) => match x {
Ok(k) => {
match k {
Key::Left => move_cursor(&mut cursor_char, -1, &enc_chars, &mpt, &status),
Key::Right => move_cursor(&mut cursor_char, 1, &enc_chars, &mpt, &status),
Key::Ctrl('c') => break,
_ => {}
}
},
_ => {}
},
None …Run Code Online (Sandbox Code Playgroud)