blob: 0fe9f40910153da01845986f6b3c3dbefe871a6c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
mod threads;
use std::io::{Stdin, Write};
use termion::event::Key;
use termion::input::TermRead;
pub use threads::Threads;
pub struct Client {
states: Vec<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') => {
self.states.pop().unwrap();
if self.states.is_empty() {
break;
}
},
_ => ()
}
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),
}
|