Enum broot::pattern::SearchMode
source · pub enum SearchMode {
NameExact,
NameFuzzy,
NameRegex,
NameTokens,
PathExact,
PathFuzzy,
PathRegex,
PathTokens,
ContentExact,
ContentRegex,
}
Expand description
a valid combination of SearchObject and SearchKind, determine how a pattern will be used
Variants§
NameExact
NameFuzzy
NameRegex
NameTokens
PathExact
PathFuzzy
PathRegex
PathTokens
ContentExact
ContentRegex
Implementations§
source§impl SearchMode
impl SearchMode
sourcepub fn prefix(self, con: &AppContext) -> String
pub fn prefix(self, con: &AppContext) -> String
Return the prefix to type, eg “/” in standard for a name-regex, “” for a name-fuzzy, and “ep” for a path-exact
Examples found in repository?
src/help/help_search_modes.rs (line 18)
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
pub fn search_mode_help(mode: SearchMode, con: &AppContext) -> SearchModeHelp {
let prefix = mode.prefix(con);
let description = format!(
"{} search on {}",
match mode.kind() {
SearchKind::Exact => "exact string",
SearchKind::Fuzzy => "fuzzy",
SearchKind::Regex => "regex",
SearchKind::Tokens => "tokens",
},
match mode.object() {
SearchObject::Name => "file name",
SearchObject::Path => "sub path",
SearchObject::Content => "file content",
},
);
let example = match mode {
SearchMode::NameExact => format!("`{prefix}feat` matches *help_features.rs*"),
SearchMode::NameFuzzy => format!("`{prefix}conh` matches *DefaultConf.hjson*"),
SearchMode::NameRegex => format!("`{prefix}rs$` matches *build.rs*"),
SearchMode::NameTokens => format!("`{prefix}fea,he` matches *HelpFeature.java*"),
SearchMode::PathExact => format!("`{prefix}te\\/do` matches *website/docs*"),
SearchMode::PathFuzzy => format!("`{prefix}flam` matches *src/flag/mod.rs*"),
SearchMode::PathRegex => format!(r#"`{prefix}\d{{3}}.*txt` matches *dir/a123/b.txt*"#),
SearchMode::PathTokens => format!("`{prefix}help,doc` matches *website/docs/help.md*"),
SearchMode::ContentExact => format!("`{prefix}find(` matches a file containing *a.find(b);*"),
SearchMode::ContentRegex => format!("`{prefix}find/i` matches a file containing *A::Find(b)*"),
};
SearchModeHelp {
prefix,
description,
example,
}
}
More examples
src/help/help_state.rs (line 171)
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
fn display(
&mut self,
w: &mut W,
disc: &DisplayContext,
) -> Result<(), ProgramError> {
let con = &disc.con;
let mut text_area = disc.state_area.clone();
text_area.pad_for_max_width(120);
if text_area != self.text_area {
self.dirty = true;
self.text_area = text_area;
}
if self.dirty {
disc.panel_skin.styles.default.queue_bg(w)?;
disc.screen.clear_area_to_right(w, &disc.state_area)?;
self.dirty = false;
}
let mut expander = help_content::expander();
expander.set("version", env!("CARGO_PKG_VERSION"));
let config_paths: Vec<String> = con.config_paths.iter()
.map(|p| p.to_string_lossy().to_string())
.collect();
for path in &config_paths {
expander.sub("config-files")
.set("path", path);
}
let verb_rows = super::help_verbs::matching_verb_rows(&self.pattern, con);
for row in &verb_rows {
let sub = expander
.sub("verb-rows")
.set_md("name", row.name())
.set_md("shortcut", row.shortcut())
.set("key", &row.verb.keys_desc);
if row.verb.description.code {
sub.set("description", "");
sub.set("execution", &row.verb.description.content);
} else {
sub.set_md("description", &row.verb.description.content);
sub.set("execution", "");
}
}
let mode_help;
if let Ok(default_mode) = con.search_modes.search_mode(None) {
mode_help = super::search_mode_help(default_mode, con);
expander
.sub("default-search")
.set_md("default-search-example", &mode_help.example);
}
let search_rows: Vec<SearchModeHelp> = SEARCH_MODES
.iter()
.map(|mode| super::search_mode_help(*mode, con))
.collect();
for row in &search_rows {
expander
.sub("search-mode-rows")
.set("search-prefix", &row.prefix)
.set("search-type", &row.description)
.set_md("search-example", &row.example);
}
let nr_prefix = SearchMode::NameRegex.prefix(con);
let ce_prefix = SearchMode::ContentExact.prefix(con);
expander
.set("nr-prefix", &nr_prefix)
.set("ce-prefix", &ce_prefix);
let features = super::help_features::list();
expander.set(
"features-text",
if features.is_empty() {
"This release was compiled with no optional feature enabled."
} else {
"This release was compiled with those optional features enabled:"
},
);
for feature in &features {
expander
.sub("features")
.set("feature-name", feature.0)
.set("feature-description", feature.1);
}
let text = expander.expand();
let fmt_text = FmtText::from_text(
&disc.panel_skin.help_skin,
text,
Some((self.text_area.width - 1) as usize),
);
let mut text_view = TextView::from(&self.text_area, &fmt_text);
self.scroll = text_view.set_scroll(self.scroll);
Ok(text_view.write_on(w)?)
}
sourcepub fn object(self) -> SearchObject
pub fn object(self) -> SearchObject
Examples found in repository?
src/help/help_search_modes.rs (line 27)
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
pub fn search_mode_help(mode: SearchMode, con: &AppContext) -> SearchModeHelp {
let prefix = mode.prefix(con);
let description = format!(
"{} search on {}",
match mode.kind() {
SearchKind::Exact => "exact string",
SearchKind::Fuzzy => "fuzzy",
SearchKind::Regex => "regex",
SearchKind::Tokens => "tokens",
},
match mode.object() {
SearchObject::Name => "file name",
SearchObject::Path => "sub path",
SearchObject::Content => "file content",
},
);
let example = match mode {
SearchMode::NameExact => format!("`{prefix}feat` matches *help_features.rs*"),
SearchMode::NameFuzzy => format!("`{prefix}conh` matches *DefaultConf.hjson*"),
SearchMode::NameRegex => format!("`{prefix}rs$` matches *build.rs*"),
SearchMode::NameTokens => format!("`{prefix}fea,he` matches *HelpFeature.java*"),
SearchMode::PathExact => format!("`{prefix}te\\/do` matches *website/docs*"),
SearchMode::PathFuzzy => format!("`{prefix}flam` matches *src/flag/mod.rs*"),
SearchMode::PathRegex => format!(r#"`{prefix}\d{{3}}.*txt` matches *dir/a123/b.txt*"#),
SearchMode::PathTokens => format!("`{prefix}help,doc` matches *website/docs/help.md*"),
SearchMode::ContentExact => format!("`{prefix}find(` matches a file containing *a.find(b);*"),
SearchMode::ContentRegex => format!("`{prefix}find/i` matches a file containing *A::Find(b)*"),
};
SearchModeHelp {
prefix,
description,
example,
}
}
sourcepub fn kind(self) -> SearchKind
pub fn kind(self) -> SearchKind
Examples found in repository?
src/help/help_search_modes.rs (line 21)
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
pub fn search_mode_help(mode: SearchMode, con: &AppContext) -> SearchModeHelp {
let prefix = mode.prefix(con);
let description = format!(
"{} search on {}",
match mode.kind() {
SearchKind::Exact => "exact string",
SearchKind::Fuzzy => "fuzzy",
SearchKind::Regex => "regex",
SearchKind::Tokens => "tokens",
},
match mode.object() {
SearchObject::Name => "file name",
SearchObject::Path => "sub path",
SearchObject::Content => "file content",
},
);
let example = match mode {
SearchMode::NameExact => format!("`{prefix}feat` matches *help_features.rs*"),
SearchMode::NameFuzzy => format!("`{prefix}conh` matches *DefaultConf.hjson*"),
SearchMode::NameRegex => format!("`{prefix}rs$` matches *build.rs*"),
SearchMode::NameTokens => format!("`{prefix}fea,he` matches *HelpFeature.java*"),
SearchMode::PathExact => format!("`{prefix}te\\/do` matches *website/docs*"),
SearchMode::PathFuzzy => format!("`{prefix}flam` matches *src/flag/mod.rs*"),
SearchMode::PathRegex => format!(r#"`{prefix}\d{{3}}.*txt` matches *dir/a123/b.txt*"#),
SearchMode::PathTokens => format!("`{prefix}help,doc` matches *website/docs/help.md*"),
SearchMode::ContentExact => format!("`{prefix}find(` matches a file containing *a.find(b);*"),
SearchMode::ContentRegex => format!("`{prefix}find/i` matches a file containing *A::Find(b)*"),
};
SearchModeHelp {
prefix,
description,
example,
}
}
Trait Implementations§
source§impl Clone for SearchMode
impl Clone for SearchMode
source§fn clone(&self) -> SearchMode
fn clone(&self) -> SearchMode
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for SearchMode
impl Debug for SearchMode
source§impl Hash for SearchMode
impl Hash for SearchMode
source§impl PartialEq<SearchMode> for SearchMode
impl PartialEq<SearchMode> for SearchMode
source§fn eq(&self, other: &SearchMode) -> bool
fn eq(&self, other: &SearchMode) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.impl Copy for SearchMode
impl Eq for SearchMode
impl StructuralEq for SearchMode
impl StructuralPartialEq for SearchMode
Auto Trait Implementations§
impl RefUnwindSafe for SearchMode
impl Send for SearchMode
impl Sync for SearchMode
impl Unpin for SearchMode
impl UnwindSafe for SearchMode
Blanket Implementations§
source§impl<T> CallHasher for Twhere
T: Hash + ?Sized,
impl<T> CallHasher for Twhere
T: Hash + ?Sized,
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.