diff options
Diffstat (limited to 'src/spinner.rs')
-rw-r--r-- | src/spinner.rs | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/src/spinner.rs b/src/spinner.rs index 0f436a0f..6c561c3c 100644 --- a/src/spinner.rs +++ b/src/spinner.rs @@ -4,61 +4,61 @@ use tui::{backend::Backend, Terminal}; // static SPINNER_CHARS: &[char] = &['◢', '◣', '◤', '◥']; // static SPINNER_CHARS: &[char] = &['⢹', '⢺', '⢼', '⣸', '⣇', '⡧', '⡗', '⡏']; static SPINNER_CHARS: &[char] = - &['⣷', '⣯', '⣟', '⡿', '⢿', '⣻', '⣽', '⣾']; + &['⣷', '⣯', '⣟', '⡿', '⢿', '⣻', '⣽', '⣾']; /// pub struct Spinner { - idx: usize, - active: bool, - last_char: Cell<char>, + idx: usize, + active: bool, + last_char: Cell<char>, } impl Default for Spinner { - fn default() -> Self { - Self { - idx: 0, - active: false, - last_char: Cell::new(' '), - } - } + fn default() -> Self { + Self { + idx: 0, + active: false, + last_char: Cell::new(' '), + } + } } impl Spinner { - /// increment spinner graphic by one - pub fn update(&mut self) { - self.idx += 1; - self.idx %= SPINNER_CHARS.len(); - } + /// increment spinner graphic by one + pub fn update(&mut self) { + self.idx += 1; + self.idx %= SPINNER_CHARS.len(); + } - /// - pub fn set_state(&mut self, active: bool) { - self.active = active; - } + /// + pub fn set_state(&mut self, active: bool) { + self.active = active; + } - /// draws or removes spinner char depending on `pending` state - pub fn draw<B: Backend>( - &self, - terminal: &mut Terminal<B>, - ) -> io::Result<()> { - let idx = self.idx; + /// draws or removes spinner char depending on `pending` state + pub fn draw<B: Backend>( + &self, + terminal: &mut Terminal<B>, + ) -> io::Result<()> { + let idx = self.idx; - let char_to_draw = - if self.active { SPINNER_CHARS[idx] } else { ' ' }; + let char_to_draw = + if self.active { SPINNER_CHARS[idx] } else { ' ' }; - if self.last_char.get() != char_to_draw { - self.last_char.set(char_to_draw); + if self.last_char.get() != char_to_draw { + self.last_char.set(char_to_draw); - let c = tui::buffer::Cell::default() - .set_char(char_to_draw) - .clone(); + let c = tui::buffer::Cell::default() + .set_char(char_to_draw) + .clone(); - terminal - .backend_mut() - .draw(vec![(0_u16, 0_u16, &c)].into_iter())?; + terminal + .backend_mut() + .draw(vec![(0_u16, 0_u16, &c)].into_iter())?; - tui::backend::Backend::flush(terminal.backend_mut())?; - } + tui::backend::Backend::flush(terminal.backend_mut())?; + } - Ok(()) - } + Ok(()) + } } |