Only read key press
This commit is contained in:
parent
aa22859f25
commit
4df18bfa84
|
@ -1,5 +1,5 @@
|
|||
use clap::Parser;
|
||||
use crossterm::{event::{self, Event as CEvent}, terminal};
|
||||
use crossterm::{event::{self, Event as CEvent, KeyboardEnhancementFlags, KeyEventKind, PushKeyboardEnhancementFlags}, execute, terminal};
|
||||
use psxreadmap::{ConsoleUI, Event, EventReceiver, Terminal, load_memory_map, UIState};
|
||||
use std::{io, path::PathBuf, sync::mpsc, thread, time::{Duration, Instant}};
|
||||
use tool_helper::{Error, exit_with_error};
|
||||
|
@ -53,10 +53,11 @@ fn start_event_loop() -> EventReceiver {
|
|||
tx.send(Event::ForceRender).expect("Send ForceRender command!");
|
||||
loop {
|
||||
let timeout = tick_rate.checked_sub(last_tick.elapsed()).unwrap_or_else(|| Duration::from_secs(0));
|
||||
|
||||
if event::poll(timeout).expect("Event poll working") {
|
||||
if let CEvent::Key(key) = event::read().expect("Can read key input") {
|
||||
tx.send(Event::Input(key)).expect("Can send KeyInput");
|
||||
if key.kind == KeyEventKind::Press {
|
||||
tx.send(Event::Input(key)).expect("Can send KeyInput");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,9 +76,15 @@ fn setup_console() -> Result<Terminal, Error> {
|
|||
terminal::enable_raw_mode()?;
|
||||
|
||||
// Setup Crossterm for the Terminal
|
||||
let stdout = io::stdout();
|
||||
let stdout = {
|
||||
let mut stdout = io::stdout();
|
||||
if let Err(_) = execute!(stdout, PushKeyboardEnhancementFlags(KeyboardEnhancementFlags::REPORT_EVENT_TYPES)) {
|
||||
// When this fails it fails
|
||||
}
|
||||
stdout
|
||||
};
|
||||
let backend = CrosstermBackend::new(stdout);
|
||||
let mut terminal = Terminal::new(backend)?;
|
||||
let mut terminal = Terminal::new(backend)?;
|
||||
|
||||
terminal.clear()?;
|
||||
Ok(terminal)
|
||||
|
|
Loading…
Reference in New Issue