Search in current dir
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn fzs(pattern: &str, list: &mut [&str]) {
|
pub fn fzs(pattern: &str, list: &mut Vec<String>) {
|
||||||
list.sort_by_key(|x| distance(pattern, x));
|
list.sort_by_key(|x| distance(pattern, x));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::{
|
use std::{
|
||||||
// io::stdout,
|
// io::stdout,
|
||||||
sync::{Arc, RwLock},
|
sync::{Arc, RwLock},
|
||||||
thread::{self, JoinHandle}, // time::Duration,
|
thread::{self, JoinHandle},
|
||||||
};
|
};
|
||||||
|
|
||||||
use self::fuzzy::fzs;
|
use self::fuzzy::fzs;
|
||||||
@@ -9,18 +9,24 @@ use self::fuzzy::fzs;
|
|||||||
pub mod fuzzy;
|
pub mod fuzzy;
|
||||||
|
|
||||||
pub fn test(
|
pub fn test(
|
||||||
|
list: Vec<String>,
|
||||||
input: Arc<RwLock<(Vec<char>, String)>>,
|
input: Arc<RwLock<(Vec<char>, String)>>,
|
||||||
result: Arc<RwLock<Vec<String>>>,
|
result: Arc<RwLock<Vec<String>>>,
|
||||||
) -> JoinHandle<()> {
|
) -> JoinHandle<()> {
|
||||||
let list = [
|
// let list = [
|
||||||
"pear",
|
// "pear",
|
||||||
"tree",
|
// "tree",
|
||||||
"platypus",
|
// "platypus",
|
||||||
"building",
|
// "building",
|
||||||
"test",
|
// "test",
|
||||||
"lime",
|
// "lime",
|
||||||
"stationary",
|
// "stationary",
|
||||||
];
|
// ];
|
||||||
|
|
||||||
|
// let list = read_dir(".")
|
||||||
|
// .unwrap()
|
||||||
|
// .map(|x| x.unwrap().file_name().to_str().unwrap().to_string())
|
||||||
|
// .collect::<Vec<String>>();
|
||||||
|
|
||||||
let mut list2 = list;
|
let mut list2 = list;
|
||||||
|
|
||||||
@@ -28,6 +34,6 @@ pub fn test(
|
|||||||
let pattern = String::from_iter(input.read().unwrap().0.clone());
|
let pattern = String::from_iter(input.read().unwrap().0.clone());
|
||||||
|
|
||||||
fzs(pattern.as_str(), &mut list2);
|
fzs(pattern.as_str(), &mut list2);
|
||||||
*result.write().unwrap() = list2.map(|x| x.to_string()).to_vec();
|
*result.write().unwrap() = list2;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use std::{
|
use std::{
|
||||||
|
fs::read_dir,
|
||||||
io::stdout,
|
io::stdout,
|
||||||
sync::{Arc, RwLock},
|
sync::{Arc, RwLock},
|
||||||
thread::sleep,
|
thread::sleep,
|
||||||
@@ -53,7 +54,12 @@ pub fn run() {
|
|||||||
|
|
||||||
start_get_input(size.0 as usize, input.clone(), cont.clone(), cursor.clone());
|
start_get_input(size.0 as usize, input.clone(), cont.clone(), cursor.clone());
|
||||||
|
|
||||||
let mut search_thread = test(input.clone(), results.clone());
|
let list = read_dir(".")
|
||||||
|
.unwrap()
|
||||||
|
.map(|x| x.unwrap().file_name().to_str().unwrap().to_string())
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
|
||||||
|
let mut search_thread = test(list.clone(), input.clone(), results.clone());
|
||||||
|
|
||||||
let mut last_input = String::new();
|
let mut last_input = String::new();
|
||||||
|
|
||||||
@@ -62,11 +68,14 @@ pub fn run() {
|
|||||||
if String::from_iter(input.read().unwrap().clone().0).as_str() != last_input.as_str()
|
if String::from_iter(input.read().unwrap().clone().0).as_str() != last_input.as_str()
|
||||||
&& search_thread.is_finished()
|
&& search_thread.is_finished()
|
||||||
{
|
{
|
||||||
search_thread = test(input.clone(), results.clone());
|
search_thread = test(list.clone(), input.clone(), results.clone());
|
||||||
}
|
let res_list = results.read().unwrap();
|
||||||
|
for (i, res) in res_list[0..(size.1 as usize - 4).min(res_list.len())]
|
||||||
for (i, res) in results.read().unwrap().iter().enumerate() {
|
.iter()
|
||||||
let spaces = String::from_iter(vec![' '; (size.0 as usize - 4) - res.chars().count()]);
|
.enumerate()
|
||||||
|
{
|
||||||
|
let spaces =
|
||||||
|
String::from_iter(vec![' '; (size.0 as usize - 4) - res.chars().count()]);
|
||||||
queue!(
|
queue!(
|
||||||
stdout(),
|
stdout(),
|
||||||
MoveTo(2, 3 + i as u16),
|
MoveTo(2, 3 + i as u16),
|
||||||
@@ -74,6 +83,8 @@ pub fn run() {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
queue!(
|
queue!(
|
||||||
stdout(),
|
stdout(),
|
||||||
MoveTo(2, 1),
|
MoveTo(2, 1),
|
||||||
|
|||||||
Reference in New Issue
Block a user