1
0
mirror of https://github.com/jht5945/rust_util.git synced 2025-12-28 16:10:05 +08:00
This commit is contained in:
2020-04-12 00:55:37 +08:00
parent b8da734669
commit 7811e29921
3 changed files with 11 additions and 21 deletions

View File

@@ -8,7 +8,7 @@ lazy_static! {
pub enum MessageType { INFO, OK, WARN, ERROR, DEBUG, }
pub fn is_atty() -> bool{
pub fn is_atty() -> bool {
let stdout_fileno = unsafe { libc::isatty(libc::STDOUT_FILENO as i32) };
stdout_fileno != 0
}
@@ -83,9 +83,9 @@ pub fn get_term_width_message(message: &str, left: usize) -> String {
return message.to_string();
}
let mut s = String::new();
s.push_str(&message[0..find_char_boundary(&message, w-10-5-left)]);
s.push_str(&message[0..find_char_boundary(&message, w - 10 - 5 - left)]);
s.push_str("[...]");
s.push_str(&message[find_char_boundary(&message, len-10)..]);
s.push_str(&message[find_char_boundary(&message, len - 10)..]);
s
},
}