Rust 中的终端 I/O 与进程信号处理
1. Rust 中终端 I/O 的实现
在 Rust 里实现终端 I/O 是一项重要的任务,下面我们将详细探讨如何处理用户输入、光标定位以及实现滚动功能。
1.1 监听用户按键
为了对用户输入做出响应并实现文档滚动,我们需要修改 run() 方法。同时,在底部栏记录并显示当前光标位置。以下是修改后的代码:
// src/bin/text-viewer2.rs
fn run(&mut self) {
let mut stdout = stdout().into_raw_mode().unwrap();
let stdin = stdin();
for c in stdin.keys() {
match c.unwrap() {
Key::Ctrl('q') => {
break;
}
Key::Left => {
self.dec_x();
self.show_document();
}
Key::Right => {
self.inc_x();
self.show_document();
}
Key::Up => {
订阅专栏 解锁全文
47

被折叠的 条评论
为什么被折叠?



