nucleo/matcher/src/config.rs

56 lines
1.7 KiB
Rust
Raw Normal View History

2023-07-20 00:09:51 +00:00
use crate::chars::CharClass;
use crate::score::BONUS_BOUNDARY;
2023-07-17 15:26:27 +00:00
2023-07-20 00:09:51 +00:00
#[non_exhaustive]
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
pub struct MatcherConfig {
2023-07-20 14:03:31 +00:00
pub delimiter_chars: &'static [u8],
2023-07-17 15:26:27 +00:00
/// Extra bonus for word boundary after whitespace character or beginning of the string
2023-07-27 20:08:06 +00:00
pub(crate) bonus_boundary_white: u16,
2023-07-17 15:26:27 +00:00
2023-07-27 20:08:06 +00:00
/// Extra bonus for word boundary after slash, colon, semi-colon, and comma
pub(crate) bonus_boundary_delimiter: u16,
2023-07-20 14:03:31 +00:00
pub initial_char_class: CharClass,
2023-07-30 02:52:44 +00:00
/// Whether to normalize latin script characters to ASCII (enabled by default)
2023-07-17 15:26:27 +00:00
pub normalize: bool,
2023-07-20 00:09:51 +00:00
/// whether to ignore casing
pub ignore_case: bool,
2023-07-17 15:26:27 +00:00
}
impl MatcherConfig {
pub const DEFAULT: Self = {
MatcherConfig {
2023-07-20 14:03:31 +00:00
delimiter_chars: b"/,:;|",
bonus_boundary_white: BONUS_BOUNDARY + 2,
bonus_boundary_delimiter: BONUS_BOUNDARY + 1,
2023-07-20 14:03:31 +00:00
initial_char_class: CharClass::Whitespace,
2023-07-30 02:52:44 +00:00
normalize: true,
2023-07-20 00:09:51 +00:00
ignore_case: true,
2023-07-17 15:26:27 +00:00
}
};
}
impl MatcherConfig {
pub fn set_match_paths(&mut self) {
2023-07-30 14:51:49 +00:00
// compared to fzf we include
2023-07-17 15:26:27 +00:00
if cfg!(windows) {
2023-07-30 14:51:49 +00:00
self.delimiter_chars = b"/:\\";
2023-07-17 15:26:27 +00:00
} else {
2023-07-30 14:51:49 +00:00
self.delimiter_chars = b"/:";
2023-07-17 15:26:27 +00:00
}
self.bonus_boundary_white = BONUS_BOUNDARY;
2023-07-20 14:03:31 +00:00
self.initial_char_class = CharClass::Delimiter;
2023-07-17 15:26:27 +00:00
}
pub const fn match_paths(mut self) -> Self {
if cfg!(windows) {
2023-07-20 14:03:31 +00:00
self.delimiter_chars = b"/\\";
2023-07-17 15:26:27 +00:00
} else {
2023-07-20 14:03:31 +00:00
self.delimiter_chars = b"/";
2023-07-17 15:26:27 +00:00
}
self.bonus_boundary_white = BONUS_BOUNDARY;
2023-07-20 14:03:31 +00:00
self.initial_char_class = CharClass::Delimiter;
2023-07-17 15:26:27 +00:00
self
}
}