summaryrefslogtreecommitdiffstats
path: root/src/spinner.rs
blob: d523b8a03d9ad8498fa4150e93d2265b7155ee48 (plain)
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
//! the thing which shows we're waiting for a long task
//! Executed during the do_pending_tasks of the states

use std::io::{self, Write};
use termion::color;

use crate::screens::Screen;

pub trait Spinner {
    fn write_spinner(&mut self, spinning: bool) -> io::Result<()>;
}

impl Spinner for Screen {
    fn write_spinner(&mut self, spinning: bool) -> io::Result<()> {
        let y = self.h - 1;
        write!(
            self.stdout,
            "{}{}{}{}{}{}",
            termion::cursor::Goto(1, y),
            color::Bg(color::AnsiValue::grayscale(2)),
            color::Fg(color::AnsiValue::grayscale(10)),
            if spinning { "⌛" } else { " " },
            color::Bg(color::Reset),
            color::Fg(color::Reset),
        )?;
        self.stdout.flush()?;
        Ok(())
    }
}