mirror of
https://github.com/jht5945/rust_util.git
synced 2025-12-27 07:30:05 +08:00
feat: v0.6.44
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "rust_util"
|
||||
version = "0.6.43"
|
||||
version = "0.6.44"
|
||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||
edition = "2018"
|
||||
description = "Hatter's Rust Util"
|
||||
|
||||
@@ -40,6 +40,12 @@ pub mod util_runtime;
|
||||
#[macro_export] macro_rules! failure {
|
||||
($($arg:tt)+) => ( rust_util::util_msg::print_error(&format!($($arg)+)); )
|
||||
}
|
||||
#[macro_export] macro_rules! println_ex {
|
||||
($($arg:tt)+) => ( rust_util::util_msg::print_ex(&format!($($arg)+), true); )
|
||||
}
|
||||
#[macro_export] macro_rules! print_ex {
|
||||
($($arg:tt)+) => ( rust_util::util_msg::print_ex(&format!($($arg)+), false); )
|
||||
}
|
||||
#[macro_export] macro_rules! debugging {
|
||||
($($arg:tt)+) => ( rust_util::util_msg::when(rust_util::util_msg::MessageType::DEBUG, || {
|
||||
rust_util::util_msg::print_debug(&format!($($arg)+))
|
||||
|
||||
@@ -14,6 +14,10 @@ pub fn set_logger_std_out(is_std_out: bool) {
|
||||
*std_out = is_std_out;
|
||||
}
|
||||
|
||||
pub fn get_logger_std_out() -> bool {
|
||||
*LOGGER_TO_STDOUT.read().unwrap()
|
||||
}
|
||||
|
||||
#[allow(clippy::upper_case_acronyms)]
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum MessageType { DEBUG, INFO, OK, WARN, ERROR }
|
||||
@@ -101,9 +105,7 @@ 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) {
|
||||
let is_std_out = {
|
||||
*LOGGER_TO_STDOUT.read().unwrap()
|
||||
};
|
||||
let is_std_out = get_logger_std_out();
|
||||
let mut lock = PRINT_MESSAGE_LOCK.lock().unwrap();
|
||||
print_color(is_std_out, color, true, h);
|
||||
if is_std_out {
|
||||
@@ -114,6 +116,22 @@ pub fn print_message_ex(color: Option<term::color::Color>, h: &str, message: &st
|
||||
*lock = ();
|
||||
}
|
||||
|
||||
pub fn print_ex(message: &str, new_line: bool) {
|
||||
if get_logger_std_out() {
|
||||
if new_line {
|
||||
println!("{}", message)
|
||||
} else {
|
||||
print!("{}", message)
|
||||
}
|
||||
} else {
|
||||
if new_line {
|
||||
eprintln!("{}", message)
|
||||
} else {
|
||||
eprint!("{}", message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print_ok(message: &str) { print_message(MessageType::OK, message); }
|
||||
|
||||
pub fn print_warn(message: &str) { print_message(MessageType::WARN, message); }
|
||||
|
||||
Reference in New Issue
Block a user