]> git.huck.website - cellseq.git/commitdiff
refactored: actions to separate module
authorHuck Boles <huck@huck.website>
Tue, 30 May 2023 02:01:02 +0000 (21:01 -0500)
committerHuck Boles <huck@huck.website>
Tue, 30 May 2023 02:01:02 +0000 (21:01 -0500)
src/graphics.rs
src/graphics/actions.rs [new file with mode: 0644]
src/graphics/keys.rs

index 8e19bf6d5ce6b39c7e63bd210c3deb5c9747b191..404232a984c909abb42ae3d148e7e7830914c45b 100644 (file)
@@ -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 (file)
index 0000000..8db825e
--- /dev/null
@@ -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!(),
+                }
+            }
+        }
+    }
+}
index bfb8d043a9ba41ca635c9d29c5e3636b95ae08ca..36b13e991bdc39965e8ce176f4c74f802985c417 100644 (file)
@@ -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,
         },