Don't use crossterm type directly
All checks were successful
Cargo CI / Build and Test (pull_request) Successful in 1m59s
Cargo CI / Lint (pull_request) Successful in 1m6s

This commit is contained in:
Wojciech Kozlowski 2024-09-15 15:15:27 +02:00
parent b597edc86f
commit 11d3df8f68
3 changed files with 18 additions and 4 deletions

View File

@ -38,7 +38,7 @@ impl IAppInput for AppInputMode {
fn input(mut self, input: InputEvent) -> Self::APP { fn input(mut self, input: InputEvent) -> Self::APP {
self.input self.input
.0 .0
.handle_event(&crossterm::event::Event::Key(input)); .handle_event(&crossterm::event::Event::Key(input.into()));
self.app.input_mut().replace(self.input); self.app.input_mut().replace(self.input);
self.app self.app
} }
@ -65,10 +65,11 @@ mod tests {
use super::*; use super::*;
fn input_event(c: char) -> InputEvent { fn input_event(c: char) -> InputEvent {
InputEvent::new( crossterm::event::KeyEvent::new(
crossterm::event::KeyCode::Char(c), crossterm::event::KeyCode::Char(c),
crossterm::event::KeyModifiers::empty(), crossterm::event::KeyModifiers::empty(),
) )
.into()
} }
#[test] #[test]

View File

@ -125,7 +125,20 @@ pub trait IAppInteractMatch {
fn abort(self) -> Self::APP; fn abort(self) -> Self::APP;
} }
type InputEvent = crossterm::event::KeyEvent; pub struct InputEvent(crossterm::event::KeyEvent);
impl From<crossterm::event::KeyEvent> for InputEvent {
fn from(value: crossterm::event::KeyEvent) -> Self {
InputEvent(value)
}
}
impl From<InputEvent> for crossterm::event::KeyEvent {
fn from(value: InputEvent) -> Self {
value.0
}
}
pub trait IAppInput { pub trait IAppInput {
type APP: IApp; type APP: IApp;

View File

@ -243,7 +243,7 @@ impl<APP: IApp> IEventHandlerPrivate<APP> for EventHandler {
KeyCode::Esc => app.cancel(), KeyCode::Esc => app.cancel(),
KeyCode::Enter => app.confirm(), KeyCode::Enter => app.confirm(),
// Othey keys. // Othey keys.
_ => app.input(key_event), _ => app.input(key_event.into()),
} }
} }
} }