2018-05-31 16:00:01 +03:00
|
|
|
use std::cmp::{max, min};
|
|
|
|
|
use termion;
|
|
|
|
|
use termion::color;
|
|
|
|
|
|
|
|
|
|
pub struct Terminal {
|
|
|
|
|
width: Option<u16>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Terminal {
|
|
|
|
|
pub fn new() -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
width: termion::terminal_size().map(|(w, _)| w).ok(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn print_separator<P: AsRef<str>>(&self, message: P) {
|
|
|
|
|
let message = message.as_ref();
|
2018-06-04 23:23:25 +03:00
|
|
|
match self.width {
|
|
|
|
|
Some(width) => {
|
|
|
|
|
print!("\n{}―― {} ", color::Fg(color::LightWhite), message);
|
|
|
|
|
let border = max(2, min(80, width as usize) - 3 - message.len());
|
|
|
|
|
for _ in 0..border {
|
|
|
|
|
print!("―");
|
|
|
|
|
}
|
|
|
|
|
println!("{}", color::Fg(color::Reset));
|
|
|
|
|
}
|
|
|
|
|
None => {
|
|
|
|
|
println!("―― {} ――", message);
|
2018-05-31 16:00:01 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-03 16:43:53 +03:00
|
|
|
|
|
|
|
|
pub fn print_warning<P: AsRef<str>>(&self, message: P) {
|
2018-06-04 23:23:25 +03:00
|
|
|
let message = message.as_ref();
|
|
|
|
|
|
|
|
|
|
match self.width {
|
|
|
|
|
Some(_) => {
|
|
|
|
|
println!(
|
|
|
|
|
"{}{}{}",
|
|
|
|
|
color::Fg(color::LightYellow),
|
|
|
|
|
message,
|
|
|
|
|
color::Fg(color::Reset)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
None => {
|
|
|
|
|
println!("{}", message);
|
|
|
|
|
}
|
2018-06-03 16:43:53 +03:00
|
|
|
}
|
|
|
|
|
}
|
2018-05-31 16:00:01 +03:00
|
|
|
}
|