mirror of
https://github.com/jht5945/finding.git
synced 2025-12-29 22:20:05 +08:00
add color print
This commit is contained in:
@@ -6,5 +6,6 @@ edition = "2018"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
argparse = "0.2.2"
|
argparse = "0.2.2"
|
||||||
|
term = "0.5.2"
|
||||||
term_size = "0.3.1"
|
term_size = "0.3.1"
|
||||||
rust_util = { git = "https://github.com/jht5945/rust_util" }
|
rust_util = { git = "https://github.com/jht5945/rust_util" }
|
||||||
|
|||||||
13
src/main.rs
13
src/main.rs
@@ -1,4 +1,5 @@
|
|||||||
extern crate argparse;
|
extern crate argparse;
|
||||||
|
extern crate term;
|
||||||
extern crate term_size;
|
extern crate term_size;
|
||||||
extern crate rust_util;
|
extern crate rust_util;
|
||||||
|
|
||||||
@@ -128,14 +129,22 @@ fn match_lines(tag: &str, content: &String, search_text: &String) {
|
|||||||
print_lastline("");
|
print_lastline("");
|
||||||
print_message(MessageType::OK, &format!("Find in {}:", tag));
|
print_message(MessageType::OK, &format!("Find in {}:", tag));
|
||||||
for i in 0..match_lines_vec.len() {
|
for i in 0..match_lines_vec.len() {
|
||||||
println!("{}: {}", match_lines_vec[i].line_number + 1, match_lines_vec[i].line_string);
|
print!("{}: ", match_lines_vec[i].line_number + 1);
|
||||||
|
let ss: Vec<&str> = match_lines_vec[i].line_string.split(search_text).collect();
|
||||||
|
for j in 0..ss.len() {
|
||||||
|
print!("{}", ss[j]);
|
||||||
|
if j < ss.len() -1 {
|
||||||
|
print_color(Some(term::color::RED), true, search_text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_text_files(large_text_file_size: &String, dir_path: &Path, search_text: &String) {
|
fn find_text_files(large_text_file_size: &String, dir_path: &Path, search_text: &String) {
|
||||||
if search_text.len() < 1 {
|
if search_text.len() < 1 {
|
||||||
print_message(MessageType::ERROR, "Param searc_text cannot be empty.");
|
print_message(MessageType::ERROR, "Param search_text cannot be empty.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let large_text_file_size_bytes = match parse_size(&large_text_file_size) {
|
let large_text_file_size_bytes = match parse_size(&large_text_file_size) {
|
||||||
|
|||||||
Reference in New Issue
Block a user