Capslock action and flx-rs matcher

This commit is contained in:
Armin Friedl 2021-11-07 11:51:48 +01:00
parent bfc7510b5e
commit bdb1520cf0
6 changed files with 45 additions and 2 deletions

7
Cargo.lock generated
View file

@ -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",

View file

@ -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"

3
sh/capslock.sh Executable file
View file

@ -0,0 +1,3 @@
#!/bin/bash
setxkbmap -option ctrl:nocaps

View file

@ -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;

27
src/matcher/flx.rs Normal file
View file

@ -0,0 +1,27 @@
use crate::roftl::Matcher;
use flx_rs::Score;
use log::debug;
pub struct FlxMatcher;
impl FlxMatcher {
pub fn new() -> Box<Self> {
Box::new(FlxMatcher{})
}
}
impl Matcher for FlxMatcher {
fn try_match(&self, haystack: &str, needle: &str) -> Option<(f64, Vec<usize>)> {
debug!{"Searching {} in {}", needle, haystack}
let res: Option<Score> = 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))
})
}
}

View file

@ -6,3 +6,7 @@ pub use skim::SkimMatcher;
mod fuse;
pub use fuse::FuseMatcher;
mod flx;
pub use flx::FlxMatcher;