Files
topgrade/src/terminal.rs

30 lines
767 B
Rust
Raw Normal View History

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();
if let Some(width) = self.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));
} else {
println!("―― {} ――", message);
}
}
}