1
0
mirror of https://github.com/jht5945/rust_util.git synced 2025-12-29 08:30:04 +08:00

add print message lock

This commit is contained in:
2020-04-12 12:06:00 +08:00
parent 7811e29921
commit 854f619518

View File

@@ -1,9 +1,11 @@
use std::{ use std::{
io::{self, Write}, io::{self, Write},
sync::{Arc, Mutex},
}; };
lazy_static! { lazy_static! {
pub static ref IS_ATTY: bool = is_atty(); pub static ref IS_ATTY: bool = is_atty();
static ref PRINT_MESSAGE_LOCK: Arc<Mutex<usize>> = Arc::new(Mutex::new(0));
} }
pub enum MessageType { INFO, OK, WARN, ERROR, DEBUG, } pub enum MessageType { INFO, OK, WARN, ERROR, DEBUG, }
@@ -35,8 +37,10 @@ pub fn print_color_and_flush(color: Option<term::color::Color>, is_bold: bool, m
} }
pub fn print_message_ex(color: Option<term::color::Color>, h: &str, message: &str) { pub fn print_message_ex(color: Option<term::color::Color>, h: &str, message: &str) {
let mut lock = PRINT_MESSAGE_LOCK.lock().unwrap();
print_color(color, true, h); print_color(color, true, h);
println!(" {}", message); println!(" {}", message);
*lock += 1;
} }
pub fn print_message(mt: MessageType, message: &str) { pub fn print_message(mt: MessageType, message: &str) {