mirror of
https://github.com/ratatui/ratatui.git
synced 2025-09-29 14:04:50 +00:00
fix(examples): update input in examples to only use press events (#129)
This commit is contained in:
parent
00e8c0d1b0
commit
4842885aa6
@ -1,6 +1,6 @@
|
|||||||
use crate::{app::App, ui};
|
use crate::{app::App, ui};
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode},
|
event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEventKind},
|
||||||
execute,
|
execute,
|
||||||
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
||||||
};
|
};
|
||||||
@ -56,13 +56,15 @@ fn run_app<B: Backend>(
|
|||||||
.unwrap_or_else(|| Duration::from_secs(0));
|
.unwrap_or_else(|| Duration::from_secs(0));
|
||||||
if crossterm::event::poll(timeout)? {
|
if crossterm::event::poll(timeout)? {
|
||||||
if let Event::Key(key) = event::read()? {
|
if let Event::Key(key) = event::read()? {
|
||||||
match key.code {
|
if key.kind == KeyEventKind::Press {
|
||||||
KeyCode::Char(c) => app.on_key(c),
|
match key.code {
|
||||||
KeyCode::Left => app.on_left(),
|
KeyCode::Char(c) => app.on_key(c),
|
||||||
KeyCode::Up => app.on_up(),
|
KeyCode::Left => app.on_left(),
|
||||||
KeyCode::Right => app.on_right(),
|
KeyCode::Up => app.on_up(),
|
||||||
KeyCode::Down => app.on_down(),
|
KeyCode::Right => app.on_right(),
|
||||||
_ => {}
|
KeyCode::Down => app.on_down(),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crossterm::{
|
use crossterm::{
|
||||||
event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode},
|
event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEventKind},
|
||||||
execute,
|
execute,
|
||||||
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
||||||
};
|
};
|
||||||
@ -186,12 +186,14 @@ fn run_app<B: Backend>(
|
|||||||
.unwrap_or_else(|| Duration::from_secs(0));
|
.unwrap_or_else(|| Duration::from_secs(0));
|
||||||
if crossterm::event::poll(timeout)? {
|
if crossterm::event::poll(timeout)? {
|
||||||
if let Event::Key(key) = event::read()? {
|
if let Event::Key(key) = event::read()? {
|
||||||
match key.code {
|
if key.kind == KeyEventKind::Press {
|
||||||
KeyCode::Char('q') => return Ok(()),
|
match key.code {
|
||||||
KeyCode::Left => app.items.unselect(),
|
KeyCode::Char('q') => return Ok(()),
|
||||||
KeyCode::Down => app.items.next(),
|
KeyCode::Left => app.items.unselect(),
|
||||||
KeyCode::Up => app.items.previous(),
|
KeyCode::Down => app.items.next(),
|
||||||
_ => {}
|
KeyCode::Up => app.items.previous(),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ use ratatui::{
|
|||||||
use std::{error::Error, io};
|
use std::{error::Error, io};
|
||||||
|
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode},
|
event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEventKind},
|
||||||
execute,
|
execute,
|
||||||
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
||||||
};
|
};
|
||||||
@ -57,10 +57,12 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
|
|||||||
terminal.draw(|f| ui(f, &app))?;
|
terminal.draw(|f| ui(f, &app))?;
|
||||||
|
|
||||||
if let Event::Key(key) = event::read()? {
|
if let Event::Key(key) = event::read()? {
|
||||||
match key.code {
|
if key.kind == KeyEventKind::Press {
|
||||||
KeyCode::Char('q') => return Ok(()),
|
match key.code {
|
||||||
KeyCode::Char('p') => app.show_popup = !app.show_popup,
|
KeyCode::Char('q') => return Ok(()),
|
||||||
_ => {}
|
KeyCode::Char('p') => app.show_popup = !app.show_popup,
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crossterm::{
|
use crossterm::{
|
||||||
event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode},
|
event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEventKind},
|
||||||
execute,
|
execute,
|
||||||
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
||||||
};
|
};
|
||||||
@ -106,11 +106,13 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
|
|||||||
terminal.draw(|f| ui(f, &mut app))?;
|
terminal.draw(|f| ui(f, &mut app))?;
|
||||||
|
|
||||||
if let Event::Key(key) = event::read()? {
|
if let Event::Key(key) = event::read()? {
|
||||||
match key.code {
|
if key.kind == KeyEventKind::Press {
|
||||||
KeyCode::Char('q') => return Ok(()),
|
match key.code {
|
||||||
KeyCode::Down => app.next(),
|
KeyCode::Char('q') => return Ok(()),
|
||||||
KeyCode::Up => app.previous(),
|
KeyCode::Down => app.next(),
|
||||||
_ => {}
|
KeyCode::Up => app.previous(),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crossterm::{
|
use crossterm::{
|
||||||
event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode},
|
event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEventKind},
|
||||||
execute,
|
execute,
|
||||||
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
||||||
};
|
};
|
||||||
@ -72,11 +72,13 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
|
|||||||
terminal.draw(|f| ui(f, &app))?;
|
terminal.draw(|f| ui(f, &app))?;
|
||||||
|
|
||||||
if let Event::Key(key) = event::read()? {
|
if let Event::Key(key) = event::read()? {
|
||||||
match key.code {
|
if key.kind == KeyEventKind::Press {
|
||||||
KeyCode::Char('q') => return Ok(()),
|
match key.code {
|
||||||
KeyCode::Right => app.next(),
|
KeyCode::Char('q') => return Ok(()),
|
||||||
KeyCode::Left => app.previous(),
|
KeyCode::Right => app.next(),
|
||||||
_ => {}
|
KeyCode::Left => app.previous(),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user