From: Huck Boles Date: Tue, 30 May 2023 02:01:02 +0000 (-0500) Subject: refactored: actions to separate module X-Git-Url: https://git.huck.website/?a=commitdiff_plain;h=0c50d88a93bab296181713e4f9155d6ac4648ab4;p=cellseq.git refactored: actions to separate module --- diff --git a/src/graphics.rs b/src/graphics.rs index 8e19bf6..404232a 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -1,9 +1,13 @@ +mod actions; mod keys; +mod layout; mod map; mod point; mod selector; +pub use actions::*; pub use keys::*; +pub use layout::*; pub use map::*; pub use point::*; pub use selector::*; diff --git a/src/graphics/actions.rs b/src/graphics/actions.rs new file mode 100644 index 0000000..8db825e --- /dev/null +++ b/src/graphics/actions.rs @@ -0,0 +1,56 @@ +use super::*; +use crossterm::event::{poll, read, Event}; + +#[derive(Debug)] +pub enum Action { + None, + Move(Direction), + Transport(Clock), + Channel(usize), + Select, + SelectArea, + Reload, + Randomize, + Exit, + Help, + Edit, +} + +#[derive(Debug)] +pub enum Clock { + Stop, + Start, + Pause, + Faster(usize), + Slower(usize), +} + +#[derive(Debug)] +pub enum Direction { + Up, + Down, + Left, + Right, +} + +pub fn action_loop(speed: usize) -> Result<()> { + loop { + if poll(Duration::from_millis(speed.try_into()?))? { + if let Event::Key(key) = read()? { + match key_event(key) { + Action::None => continue, + Action::Exit => crate::exit()?, + Action::Move(_direction) => todo!(), + Action::Channel(_channel) => todo!(), + Action::Transport(_clock) => todo!(), + Action::Edit => todo!(), + Action::Select => todo!(), + Action::SelectArea => todo!(), + Action::Reload => todo!(), + Action::Randomize => todo!(), + Action::Help => todo!(), + } + } + } + } +} diff --git a/src/graphics/keys.rs b/src/graphics/keys.rs index bfb8d04..36b13e9 100644 --- a/src/graphics/keys.rs +++ b/src/graphics/keys.rs @@ -1,55 +1,6 @@ -use crossterm::{ - event::{poll, read, Event, KeyCode, KeyEvent, KeyModifiers}, - execute, queue, terminal, -}; -use eyre::Result; -use std::time::Duration; +use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; -pub fn action_loop(speed: usize) -> Result<()> { - loop { - if poll(Duration::from_millis(speed.try_into()?))? { - if let Event::Key(key) = read()? { - match key_event(key) { - Action::None => continue, - Action::Exit => crate::exit()?, - x => println!("{:?}", x), - } - } - } - } -} - -#[derive(Debug)] -pub enum Action { - None, - Move(Direction), - Resize(Direction), - Transport(Clock), - Channel(usize), - Select, - SelectArea, - Reload, - Randomize, - Exit, - Help, -} - -#[derive(Debug)] -pub enum Clock { - Stop, - Start, - Pause, - Faster(usize), - Slower(usize), -} - -#[derive(Debug)] -pub enum Direction { - Up, - Down, - Left, - Right, -} +use super::*; pub fn key_event(event: KeyEvent) -> Action { match event.modifiers { @@ -110,15 +61,7 @@ pub fn match_ctl_key(key: KeyCode) -> Action { pub fn match_shift_key(key: KeyCode) -> Action { match key { - KeyCode::Up => Action::Resize(Direction::Up), - KeyCode::Down => Action::Resize(Direction::Down), - KeyCode::Right => Action::Resize(Direction::Right), - KeyCode::Left => Action::Resize(Direction::Left), KeyCode::Char(c) => match c { - 'J' => Action::Resize(Direction::Down), - 'K' => Action::Resize(Direction::Up), - 'H' => Action::Resize(Direction::Left), - 'L' => Action::Resize(Direction::Right), 'R' => Action::Randomize, _ => Action::None, },