From 8787162d7c973fad5a737172be81d7cafe9348ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Wed, 28 Apr 2021 23:36:05 +0200 Subject: move main loop to state --- src/state/mod.rs | 22 ++++++++++++++++++++++ src/state/threads.rs | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) (limited to 'src/state') diff --git a/src/state/mod.rs b/src/state/mod.rs index 5313b4f..7b498f2 100644 --- a/src/state/mod.rs +++ b/src/state/mod.rs @@ -1,7 +1,29 @@ mod threads; +use std::io::{Stdin, Write}; +use termion::event::Key; +use termion::input::TermRead; + pub use threads::Threads; pub enum State { Threads(Threads), } + +impl State { + pub fn run(mut self, mut screen: W, stdin: Stdin) { + for c in stdin.keys() { + let c = c.unwrap(); + // Global keybinds + match c { + Key::Char('q') => break, + _ => () + } + + // Pass to current state + self = match self { + State::Threads(s) => s.tick(&mut screen, c), + }; + } + } +} diff --git a/src/state/threads.rs b/src/state/threads.rs index 78dc795..6ffd7e7 100644 --- a/src/state/threads.rs +++ b/src/state/threads.rs @@ -85,8 +85,8 @@ impl<'d, 'q> Threads { } if !self.threads.is_empty() { self.i = self.i.rem_euclid(self.threads.len()); - draw(&self, out); } + draw(&self, out); State::Threads(self) } } -- cgit v1.2.1