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