commit?
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
use std::{
|
||||
fs::{metadata, read_dir},
|
||||
io::stdout,
|
||||
sync::{Arc, RwLock},
|
||||
process::exit,
|
||||
sync::{Arc, RwLock, RwLockReadGuard},
|
||||
thread::sleep,
|
||||
time::Duration,
|
||||
};
|
||||
@@ -83,22 +84,7 @@ pub fn run(path: &str, recursive: usize) {
|
||||
if processing && search_thread.is_finished() {
|
||||
let res_list = results.read().unwrap();
|
||||
execute!(stdout(), Hide, MoveTo(2, 3), Print(clear_loading.clone())).unwrap();
|
||||
|
||||
for (i, res) in res_list[0..(size.1 as usize - 4).min(res_list.len())]
|
||||
.iter()
|
||||
.enumerate()
|
||||
{
|
||||
let spaces =
|
||||
String::from_iter(vec![' '; (size.0 as usize - 4) - res.chars().count()]);
|
||||
queue!(
|
||||
stdout(),
|
||||
MoveTo(2, 3 + i as u16),
|
||||
Print(format!("{}{}", res, spaces)),
|
||||
// MoveTo(2, 3),
|
||||
// Print(format!("{} ", res_list.len())),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
print_list(res_list, size.1 as usize, size.1 as usize);
|
||||
queue!(stdout(), Show).unwrap();
|
||||
processing = false;
|
||||
}
|
||||
@@ -123,6 +109,21 @@ pub fn stop() {
|
||||
execute!(stdout(), Show, LeaveAlternateScreen,).unwrap();
|
||||
}
|
||||
|
||||
fn print_list(res_list: RwLockReadGuard<'_, Vec<String>>, height: usize, width: usize) {
|
||||
for (i, res) in res_list[0..(height - 4).min(res_list.len())]
|
||||
.iter()
|
||||
.enumerate()
|
||||
{
|
||||
let spaces = String::from_iter(vec![' '; (width - 4) - res.chars().count()]);
|
||||
queue!(
|
||||
stdout(),
|
||||
MoveTo(2, 3 + i as u16),
|
||||
Print(format!("{}{}", res, spaces)),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn print_frame(width: usize, height: usize) {
|
||||
let spaces = String::from_iter(vec![' '; width - 2]);
|
||||
let lines = String::from_iter(vec!['─'; width - 2]);
|
||||
@@ -184,8 +185,9 @@ fn get_files(list: &mut Vec<String>, path: &str, recursive: usize) {
|
||||
);
|
||||
}
|
||||
} else {
|
||||
for e in read_dir(path)
|
||||
.unwrap()
|
||||
match read_dir(path) {
|
||||
Ok(dirs) => {
|
||||
for e in dirs
|
||||
.map(|x| x.unwrap().file_name().to_str().unwrap().to_string())
|
||||
.collect::<Vec<String>>()
|
||||
{
|
||||
@@ -199,4 +201,16 @@ fn get_files(list: &mut Vec<String>, path: &str, recursive: usize) {
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
stop();
|
||||
eprintln!("Error reading {}: {}", path, err);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
// for e in read_dir(path)
|
||||
// .unwrap()
|
||||
// .map(|x| x.unwrap().file_name().to_str().unwrap().to_string())
|
||||
// .collect::<Vec<String>>()
|
||||
// {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user