diff --git a/Cargo.lock b/Cargo.lock index 3add91f..ee4b9b8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -374,6 +374,12 @@ dependencies = [ "termcolor", ] +[[package]] +name = "flx-rs" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "078541905b40af0ab9d964d367796f3b8eb009ba010c1864b9735f707188ff5b" + [[package]] name = "fnv" version = "1.0.7" @@ -1094,6 +1100,7 @@ dependencies = [ "cairo-rs", "cairo-sys-rs", "env_logger", + "flx-rs", "freedesktop_entry_parser", "fuse-rust", "fuzzy-matcher", diff --git a/Cargo.toml b/Cargo.toml index bc5db47..36f25cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,9 +18,11 @@ xcb = "0.9.0" xcb-util = {version = "0.3.0", features = ["ewmh", "icccm"]} fuzzy-matcher = "0.3.7" +fuse-rust = "0.3.0" +# Currently buggy, waiting for fix +flx-rs = "0.1.1" walkdir = "2.3.2" freedesktop_entry_parser = "1.2.0" nix = "0.23.0" -fuse-rust = "0.3.0" anyhow = "1.0.44" diff --git a/sh/capslock.sh b/sh/capslock.sh new file mode 100755 index 0000000..e31147f --- /dev/null +++ b/sh/capslock.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +setxkbmap -option ctrl:nocaps diff --git a/src/main.rs b/src/main.rs index 8e0bc91..abbb476 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ use winit::event_loop::{ControlFlow, EventLoop}; use winit::event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent::{CloseRequested, ReceivedCharacter}}; -use crate::matcher::{FuseMatcher, SkimMatcher}; +use crate::matcher::{FuseMatcher, SkimMatcher, FlxMatcher}; mod roftl; mod ui; diff --git a/src/matcher/flx.rs b/src/matcher/flx.rs new file mode 100644 index 0000000..9c75ace --- /dev/null +++ b/src/matcher/flx.rs @@ -0,0 +1,27 @@ +use crate::roftl::Matcher; + +use flx_rs::Score; +use log::debug; + +pub struct FlxMatcher; + +impl FlxMatcher { + pub fn new() -> Box { + Box::new(FlxMatcher{}) + } +} + +impl Matcher for FlxMatcher { + fn try_match(&self, haystack: &str, needle: &str) -> Option<(f64, Vec)> { + debug!{"Searching {} in {}", needle, haystack} + let res: Option = flx_rs::score(haystack, needle); + res.and_then(|score| { + let s = score.score as f64; + let i = score.indices.into_iter() + .map(|idx| idx as usize) + .collect(); + + Some((s, i)) + }) + } +} diff --git a/src/matcher/mod.rs b/src/matcher/mod.rs index 8bc5656..0969d3a 100644 --- a/src/matcher/mod.rs +++ b/src/matcher/mod.rs @@ -6,3 +6,7 @@ pub use skim::SkimMatcher; mod fuse; pub use fuse::FuseMatcher; + +mod flx; +pub use flx::FlxMatcher; +