Add fuse matcher
This commit is contained in:
parent
0f4117b436
commit
c382a121a5
6 changed files with 47 additions and 4 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -420,6 +420,12 @@ version = "1.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7"
|
checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fuse-rust"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0d9ff709b73b2baf07e03076ffe6fb9a6e7309e67651d650e2775729a4fc0eaf"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-channel"
|
name = "futures-channel"
|
||||||
version = "0.3.17"
|
version = "0.3.17"
|
||||||
|
@ -1087,6 +1093,7 @@ dependencies = [
|
||||||
"cairo-sys-rs",
|
"cairo-sys-rs",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"freedesktop_entry_parser",
|
"freedesktop_entry_parser",
|
||||||
|
"fuse-rust",
|
||||||
"fuzzy-matcher",
|
"fuzzy-matcher",
|
||||||
"log",
|
"log",
|
||||||
"mlua",
|
"mlua",
|
||||||
|
|
|
@ -21,4 +21,5 @@ fuzzy-matcher = "0.3.7"
|
||||||
walkdir = "2.3.2"
|
walkdir = "2.3.2"
|
||||||
freedesktop_entry_parser = "1.2.0"
|
freedesktop_entry_parser = "1.2.0"
|
||||||
mlua = { version = "0.6", features = ["lua54", "vendored"] }
|
mlua = { version = "0.6", features = ["lua54", "vendored"] }
|
||||||
nix = "0.23.0"
|
nix = "0.23.0"
|
||||||
|
fuse-rust = "0.3.0"
|
|
@ -6,7 +6,7 @@ use winit::event_loop::{ControlFlow, EventLoop};
|
||||||
use winit::event::{ElementState, Event, KeyboardInput, VirtualKeyCode,
|
use winit::event::{ElementState, Event, KeyboardInput, VirtualKeyCode,
|
||||||
WindowEvent::{CloseRequested, ReceivedCharacter}};
|
WindowEvent::{CloseRequested, ReceivedCharacter}};
|
||||||
|
|
||||||
use crate::matcher::SkimMatcher;
|
use crate::matcher::{FuseMatcher, SkimMatcher};
|
||||||
|
|
||||||
mod roftl;
|
mod roftl;
|
||||||
mod ui;
|
mod ui;
|
||||||
|
@ -24,7 +24,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
.add_source(sources::Window::new())
|
.add_source(sources::Window::new())
|
||||||
.add_source(sources::Apps::new())
|
.add_source(sources::Apps::new())
|
||||||
.add_source(sources::LuaHost::new())
|
.add_source(sources::LuaHost::new())
|
||||||
.with_matcher(SkimMatcher::new());
|
.with_matcher(FuseMatcher::new());
|
||||||
|
|
||||||
debug!{"Source roftl sources"}
|
debug!{"Source roftl sources"}
|
||||||
roftl.source();
|
roftl.source();
|
||||||
|
|
33
src/matcher/fuse.rs
Normal file
33
src/matcher/fuse.rs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
use std::ops::Range;
|
||||||
|
|
||||||
|
use fuse_rust::Fuse;
|
||||||
|
|
||||||
|
use crate::roftl::Matcher;
|
||||||
|
|
||||||
|
fn flatten_ranges(ranges: Vec<Range<usize>>) -> Vec<usize> {
|
||||||
|
ranges.into_iter().flat_map(|range| {range.collect::<Vec<usize>>().into_iter()})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct FuseMatcher {
|
||||||
|
matcher: Fuse
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FuseMatcher {
|
||||||
|
pub fn new() -> Box<Self> {
|
||||||
|
Box::new(FuseMatcher{
|
||||||
|
matcher: Fuse::default()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Matcher for FuseMatcher {
|
||||||
|
fn try_match(&self, haystack: &str, needle: &str) -> Option<(f64, Vec<usize>)> {
|
||||||
|
match self.matcher.search_text_in_string(needle, haystack) {
|
||||||
|
Some(score) => Some((score.score, flatten_ranges(score.ranges))),
|
||||||
|
None => None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,3 +3,6 @@ pub use prefix::PrefixMatcher;
|
||||||
|
|
||||||
mod skim;
|
mod skim;
|
||||||
pub use skim::SkimMatcher;
|
pub use skim::SkimMatcher;
|
||||||
|
|
||||||
|
mod fuse;
|
||||||
|
pub use fuse::FuseMatcher;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use std::{collections::HashMap, sync::{Arc, Mutex, atomic::{AtomicUsize, Ordering}}, usize};
|
use std::{collections::HashMap, sync::{Arc, Mutex, atomic::{AtomicUsize, Ordering}}, usize};
|
||||||
|
|
||||||
|
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use rayon::{iter::{IndexedParallelIterator, IntoParallelRefIterator, IntoParallelRefMutIterator, ParallelIterator}, slice::ParallelSliceMut};
|
use rayon::{iter::{IndexedParallelIterator, IntoParallelRefIterator, IntoParallelRefMutIterator, ParallelIterator}, slice::ParallelSliceMut};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue