Skip to content

Commit

Permalink
poll added
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacperacy committed Mar 3, 2024
1 parent 927fd27 commit 0e40aac
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
use std::time::Duration;

use crossterm::{
event::{read, Event::Key, KeyCode},
event::{poll, read, Event::Key, KeyCode, KeyEvent},
terminal::{disable_raw_mode, enable_raw_mode},
};

fn main() {
let _ = enable_raw_mode();
loop {
if let Ok(Key(key)) = read() {
if key.code == KeyCode::Char('q') {
let mut c: Option<KeyEvent> = None;

if let Ok(true) = poll(Duration::from_millis(100)) {
if let Ok(Key(key)) = read() {
c = Some(key);
}
}

if let Some(c) = c {
println!("{c:?}\r");
if c.code == KeyCode::Char('q') {
break;
} else {
println!("{:?}\r", key);
}
} else {
println!("No input\r");
}
}
let _ = disable_raw_mode();
Expand Down

0 comments on commit 0e40aac

Please sign in to comment.