mirror of
https://github.com/jht5945/rust_util.git
synced 2025-12-27 15:40:03 +08:00
fix print_color unwarp issue
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "rust_util"
|
||||
version = "0.2.5"
|
||||
version = "0.2.6"
|
||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||
edition = "2018"
|
||||
description = "Hatter's Rust Util"
|
||||
|
||||
@@ -17,18 +17,22 @@ pub fn is_atty() -> bool {
|
||||
}
|
||||
|
||||
pub fn print_color(color: Option<term::color::Color>, is_bold: bool, m: &str) {
|
||||
let mut t = term::stdout().unwrap();
|
||||
if *IS_ATTY {
|
||||
if let Some(c) = color {
|
||||
t.fg(c).unwrap();
|
||||
}
|
||||
if is_bold {
|
||||
t.attr(term::Attr::Bold).unwrap();
|
||||
}
|
||||
write!(t, "{}", m).unwrap();
|
||||
t.reset().unwrap();
|
||||
} else {
|
||||
write!(t, "{}", m).unwrap();
|
||||
match term::stdout() {
|
||||
Some(mut t) => {
|
||||
if *IS_ATTY {
|
||||
if let Some(c) = color {
|
||||
t.fg(c).ok();
|
||||
}
|
||||
if is_bold {
|
||||
t.attr(term::Attr::Bold).ok();
|
||||
}
|
||||
write!(t, "{}", m).ok();
|
||||
t.reset().ok();
|
||||
} else {
|
||||
write!(t, "{}", m).ok();
|
||||
}
|
||||
},
|
||||
None => print!("{}", m),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user