mirror of
https://github.com/jht5945/finding.git
synced 2025-12-29 22:20:05 +08:00
fix linux width
This commit is contained in:
33
src/main.rs
33
src/main.rs
@@ -20,6 +20,30 @@ Written by Hatter Jiang
|
|||||||
"#, VERSION);
|
"#, VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_term_width() -> Option<usize> {
|
||||||
|
match term_size::dimensions() {
|
||||||
|
None => None,
|
||||||
|
Some((w, _h)) => Some(w),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_term_width_message(message: &str, left: usize) -> String {
|
||||||
|
match get_term_width() {
|
||||||
|
None => message.to_string(),
|
||||||
|
Some(w) => {
|
||||||
|
let len = message.len();
|
||||||
|
if w > len {
|
||||||
|
return message.to_string();
|
||||||
|
}
|
||||||
|
let mut s = String::new();
|
||||||
|
s.push_str(&message[0..w-10-5-left]);
|
||||||
|
s.push_str("[...]");
|
||||||
|
s.push_str(&message[len-10..]);
|
||||||
|
s
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn find_huge_files(huge_file_size: &String, dir_path: &Path) {
|
fn find_huge_files(huge_file_size: &String, dir_path: &Path) {
|
||||||
let huge_file_size_bytes = match parse_size(&huge_file_size) {
|
let huge_file_size_bytes = match parse_size(&huge_file_size) {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@@ -47,20 +71,13 @@ fn find_huge_files(huge_file_size: &String, dir_path: &Path) {
|
|||||||
}, &|p| {
|
}, &|p| {
|
||||||
match p.to_str() {
|
match p.to_str() {
|
||||||
None => (),
|
None => (),
|
||||||
Some(p_str) => print_lastline(&format!("Scanning: {}", p_str)),
|
Some(p_str) => print_lastline(&get_term_width_message(&format!("Scanning: {}", p_str), 10)),
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}).unwrap_or(());
|
}).unwrap_or(());
|
||||||
print_lastline("");
|
print_lastline("");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_term_width() -> Option<usize> {
|
|
||||||
match term_size::dimensions() {
|
|
||||||
None => None,
|
|
||||||
Some((w, _h)) => Some(w),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut version = false;
|
let mut version = false;
|
||||||
let mut target = String::from("text");
|
let mut target = String::from("text");
|
||||||
|
|||||||
Reference in New Issue
Block a user