summaryrefslogtreecommitdiffstats
path: root/src/status.rs
blob: 4acd16784188ffa878023622cf88a249b7760b44 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//! the status module manages writing information on the grey line
//!  near the bottom of the screen

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

use crate::screens::Screen;

pub trait Status {
    fn write_status_text(&mut self, text: &str) -> io::Result<()>;
    fn write_status_err(&mut self, text: &str) -> io::Result<()>;
}

impl Status for Screen {
    fn write_status_err(&mut self, text: &str) -> io::Result<()> {
        let y = self.h - 1;
        let mut text = String::from(text);
        text.truncate(self.w as usize - 2);
        write!(
            self.stdout,
            "{}{}{}{} {}{}{}",
            termion::cursor::Goto(2, y),
            color::Bg(color::AnsiValue::grayscale(2)),
            color::Fg(color::Red),
            termion::clear::CurrentLine,
            text,
            color::Bg(color::Reset),
            color::Fg(color::Reset),
        )?;
        self.stdout.flush()?;
        Ok(())
    }
    fn write_status_text(&mut self, text: &str) -> io::Result<()> {
        let y = self.h - 1;
        let mut text = String::from(text);
        text.truncate(self.w as usize - 2);
        write!(
            self.stdout,
            "{}{}{} {}{}",
            termion::cursor::Goto(2, y),
            color::Bg(color::AnsiValue::grayscale(2)),
            termion::clear::CurrentLine,
            text,
            color::Bg(color::Reset),
        )?;
        self.stdout.flush()?;
        Ok(())
    }
}