Skip to main content

time_rs/lib/
throbber.rs

1#[derive(Debug, Clone, Copy)]
2enum ThrobberState {
3    One = 0,
4    Two,
5    Three,
6    Four,
7}
8
9impl ThrobberState {
10    fn next(&self) -> ThrobberState {
11        use ThrobberState::*;
12        match *self {
13            One => Two,
14            Two => Three,
15            Three => Four,
16            Four => One,
17        }
18    }
19}
20
21#[derive(Debug, Clone)]
22pub struct Throbber {
23    state: ThrobberState,
24}
25
26impl Throbber {
27    pub fn new() -> Throbber {
28        Throbber {
29            state: ThrobberState::One,
30        }
31    }
32
33    pub fn tick(&mut self) {
34        self.state = self.state.next()
35    }
36
37    pub fn get_state_string(&self) -> &str {
38        match self.state {
39            ThrobberState::One => "-",
40            ThrobberState::Two => "\\",
41            ThrobberState::Three => "|",
42            ThrobberState::Four => "/",
43        }
44    }
45}