aboutsummaryrefslogtreecommitdiffstats
path: root/src/state/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/state/mod.rs')
-rw-r--r--src/state/mod.rs30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/state/mod.rs b/src/state/mod.rs
index 7b498f2..0fe9f40 100644
--- a/src/state/mod.rs
+++ b/src/state/mod.rs
@@ -6,24 +6,42 @@ use termion::input::TermRead;
pub use threads::Threads;
-pub enum State {
- Threads(Threads),
+pub struct Client {
+ states: Vec<State>,
}
-impl State {
+impl Client {
+ pub fn new(initial_state: State) -> Self {
+ Self {
+ states: vec![initial_state],
+ }
+ }
+
pub fn run<W: Write>(mut self, mut screen: W, stdin: Stdin) {
for c in stdin.keys() {
let c = c.unwrap();
// Global keybinds
match c {
- Key::Char('q') => break,
+ Key::Char('q') => {
+ self.states.pop().unwrap();
+ if self.states.is_empty() {
+ break;
+ }
+ },
_ => ()
}
- // Pass to current state
- self = match self {
+ let next_state = match self.states.last_mut().unwrap() {
State::Threads(s) => s.tick(&mut screen, c),
};
+
+ if let Some(next_state) = next_state {
+ self.states.push(next_state);
+ }
}
}
}
+
+pub enum State {
+ Threads(Threads),
+}