mirror of
https://github.com/jht5945/rust_util.git
synced 2025-12-27 15:40:03 +08:00
add print_color,print_color_and_flush
This commit is contained in:
17
src/lib.rs
17
src/lib.rs
@@ -120,15 +120,26 @@ pub fn new_box_error(m: &str) -> Box<dyn std::error::Error> {
|
|||||||
|
|
||||||
pub enum MessageType { INFO, OK, WARN, ERROR, }
|
pub enum MessageType { INFO, OK, WARN, ERROR, }
|
||||||
|
|
||||||
pub fn print_message_ex(color: Option<term::color::Color>, h: &str, message: &str) {
|
pub fn print_color(color: Option<term::color::Color>, is_bold: bool, m: &str) {
|
||||||
let mut t = term::stdout().unwrap();
|
let mut t = term::stdout().unwrap();
|
||||||
match color {
|
match color {
|
||||||
Some(c) => t.fg(c).unwrap(),
|
Some(c) => t.fg(c).unwrap(),
|
||||||
None => (),
|
None => (),
|
||||||
}
|
}
|
||||||
t.attr(term::Attr::Bold).unwrap();
|
if is_bold {
|
||||||
write!(t, "{}", h).unwrap();
|
t.attr(term::Attr::Bold).unwrap();
|
||||||
|
}
|
||||||
|
write!(t, "{}", m).unwrap();
|
||||||
t.reset().unwrap();
|
t.reset().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn print_color_and_flush(color: Option<term::color::Color>, is_bold: bool, m: &str) {
|
||||||
|
print_color(color, is_bold, m);
|
||||||
|
flush_stdout();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn print_message_ex(color: Option<term::color::Color>, h: &str, message: &str) {
|
||||||
|
print_color(color, true, h);
|
||||||
println!(" {}", message);
|
println!(" {}", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user