summaryrefslogtreecommitdiffstats
path: root/src/status.rs
blob: e1556aa5abc63e9d531bc8949004df1e52f6ddf4 (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
use std::io;

use crate::screens::Screen;
use crate::skin::{self, SkinEntry};
use crossterm_style::ObjectStyle;

/// the status module manages writing information on the grey line
///  near the bottom of the screen
pub trait Status {
    fn write_status_text(&self, text: &str) -> io::Result<()>;
    fn write_status_err(&self, text: &str) -> io::Result<()>;
}

impl Screen {
    fn write_status(&self, text: &str, skin: &ObjectStyle) -> io::Result<()> {
        let mut text = String::from(text);
        text.truncate(self.w as usize - 3);
        self.goto_clear(2, self.h - 1);
        skin.print_string(" ");
        skin.print_string(&text);
        skin.print_bg();
        self.clear_line();
        skin::reset();
        Ok(())
    }
}

impl Status for Screen {
    fn write_status_err(&self, text: &str) -> io::Result<()> {
        //debug!("display error {:?}", text);
        self.write_status(text, &self.skin.status_error)
    }
    fn write_status_text(&self, text: &str) -> io::Result<()> {
        //debug!("display status {:?}", text);
        self.write_status(text, &self.skin.status_normal)
    }
}