-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
transition to nucleo for fuzzy matching
- Loading branch information
1 parent
bc73740
commit 844f5d4
Showing
15 changed files
with
761 additions
and
982 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use nucleo::{CaseMatching, MatcherConfig}; | ||
use parking_lot::Mutex; | ||
|
||
pub static MATCHER: Mutex<Option<nucleo::Matcher>> = Mutex::new(None); | ||
|
||
/// convenicne function to easily fuzzy match | ||
/// on a (relatievly small list of inputs). This is not recommended for building a full tui | ||
/// application that can match large numbers of matches as all matching is done on the current | ||
/// thread, effectively blocking the UI | ||
pub fn fuzzy_match<T: AsRef<str>>( | ||
pattern: &str, | ||
items: impl IntoIterator<Item = T>, | ||
path: bool, | ||
) -> Vec<(T, u32)> { | ||
let mut matcher_lock = MATCHER.lock(); | ||
let matcher = matcher_lock.get_or_insert_with(nucleo::Matcher::default); | ||
matcher.config = MatcherConfig::DEFAULT; | ||
if path { | ||
matcher.config.set_match_paths(); | ||
} | ||
nucleo::fuzzy_match(matcher, pattern, items, CaseMatching::Smart) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.