diff --git a/src/app.rs b/src/app.rs index 5f7fa94..6254074 100644 --- a/src/app.rs +++ b/src/app.rs @@ -11,6 +11,8 @@ pub struct App { pub input: Input, /// Is the app running? pub running: bool, + /// Results from the search query + pub results: String, } impl Default for App { @@ -18,6 +20,7 @@ impl Default for App { App { input: Input::default(), running: true, + results: "".to_string(), } } } diff --git a/src/handler.rs b/src/handler.rs index 525d9bd..e11f8d4 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -6,25 +6,24 @@ use tui_input::backend::crossterm::EventHandler; /// Handles the key events and updates the state of [`App`]. pub async fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { - match key_event.code { - // Exit application on `ESC` - KeyCode::Esc => { + match key_event { + KeyEvent { + code: KeyCode::Char('c'), + modifiers: KeyModifiers::CONTROL, + .. + } => { app.quit(); } - // Exit application on `Ctrl-C` - KeyCode::Char('c') | KeyCode::Char('C') => { - if key_event.modifiers == KeyModifiers::CONTROL { - app.quit(); - } + KeyEvent { code: KeyCode::Esc, .. } => { + app.quit(); } - KeyCode::Enter => { - query_anime(app.input.to_string()).await.unwrap(); + KeyEvent { code: KeyCode::Enter, .. } => { + app.results = format!("{:#?}", query_anime(app.input.to_string()).await.unwrap().results); app.input.reset(); } _ => { app.input.handle_event(&Event::Key(key_event)); } } - Ok(()) } diff --git a/src/ui.rs b/src/ui.rs index a9f8c3a..88ed747 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -51,7 +51,7 @@ pub fn render(app: &mut App, frame: &mut Frame) { chunks[1].y + 1, ); - let messages = Paragraph::new("Another placeholder") + let messages = Paragraph::new(&*app.results) .block(Block::default().borders(Borders::ALL).title("Results")); frame.render_widget(messages, chunks[2]); }