use lazy_static::lazy_static;
use std::io::Write;
use std::sync::Mutex;
fn status_lock<F>(f: F)
where
F: FnOnce(),
{
lazy_static! {
static ref LOCK: Mutex<()> = Mutex::new(());
}
let _guard = LOCK.lock();
f();
}
fn print_status_header() {
print!("copter: ");
}
fn print_color(s: &str, fg: term::color::Color) {
if !really_print_color(s, fg) {
print!("{}", s);
}
fn really_print_color(s: &str, fg: term::color::Color) -> bool {
if let Some(ref mut t) = term::stdout() {
if t.fg(fg).is_err() {
return false;
}
let _ = t.attr(term::Attr::Bold);
if write!(t, "{}", s).is_err() {
return false;
}
let _ = t.reset();
}
true
}
}
pub fn status(s: &str) {
status_lock(|| {
print_status_header();
println!("{}", s);
});
}
pub fn print_error(msg: &str) {
println!();
print_color("error", term::color::BRIGHT_RED);
println!(": {}", msg);
println!();
}