chore: move input handling to pure method

This commit is contained in:
Jeremy Wall 2024-11-22 18:57:57 -05:00
parent 25a8160f0a
commit a70a1451c1
2 changed files with 4 additions and 3 deletions

View File

@ -1,6 +1,7 @@
use std::{path::PathBuf, process::ExitCode}; use std::{path::PathBuf, process::ExitCode};
use clap::Parser; use clap::Parser;
use crossterm::event;
use ratatui; use ratatui;
use ui::Workspace; use ui::Workspace;
@ -23,7 +24,7 @@ fn run(terminal: &mut ratatui::DefaultTerminal, args: Args) -> anyhow::Result<Ex
loop { loop {
terminal.draw(|frame| ui::render::draw(frame, &mut ws))?; terminal.draw(|frame| ui::render::draw(frame, &mut ws))?;
if let Some(code) = ws.handle_input()? { if let Some(code) = ws.handle_input(event::read()?)? {
return Ok(code); return Ok(code);
} }
} }

View File

@ -163,10 +163,10 @@ impl<'ws> Workspace<'ws> {
} }
/// Handle input in our ui loop. /// Handle input in our ui loop.
pub fn handle_input(&mut self) -> Result<Option<ExitCode>> { pub fn handle_input(&mut self, evt: Event) -> Result<Option<ExitCode>> {
// TODO(jwall): We probably want to separate this out into // TODO(jwall): We probably want to separate this out into
// a pure function so we can script various testing scenarios. // a pure function so we can script various testing scenarios.
if let Event::Key(key) = event::read()? { if let Event::Key(key) = evt {
let result = match self.state.modality() { let result = match self.state.modality() {
Modality::Navigate => self.handle_navigation_input(key)?, Modality::Navigate => self.handle_navigation_input(key)?,
Modality::CellEdit => self.handle_edit_input(key)?, Modality::CellEdit => self.handle_edit_input(key)?,