pub struct SearchModeMap {
    pub entries: Vec<SearchModeMapEntry>,
}
Expand description

manage how to find the search mode to apply to a pattern taking the config in account.

Fields§

§entries: Vec<SearchModeMapEntry>

Implementations§

Examples found in repository?
src/pattern/search_mode.rs (line 202)
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
    fn default() -> Self {
        let mut smm = SearchModeMap {
            entries: Vec::new(),
        };
        // the last keys are preferred
        smm.setm(&["ne", "en", "e"], SearchMode::NameExact);
        smm.setm(&["nf", "fn", "n", "f"], SearchMode::NameFuzzy);
        smm.setm(&["r", "nr", "rn", ""], SearchMode::NameRegex);
        smm.setm(&["pe", "ep"], SearchMode::PathExact);
        smm.setm(&["pf", "fp", "p"], SearchMode::PathFuzzy);
        smm.setm(&["pr", "rp"], SearchMode::PathRegex);
        smm.setm(&["ce", "ec", "c"], SearchMode::ContentExact);
        smm.setm(&["rx", "cr"], SearchMode::ContentRegex);
        smm.setm(&["pt", "tp", "t"], SearchMode::PathTokens);
        smm.setm(&["tn", "nt"], SearchMode::NameTokens);
        smm.set(SearchModeMapEntry { key: None, mode: SearchMode::PathFuzzy });
        smm
    }

we don’t remove existing entries to ensure there’s always a matching entry in mode->key (but search iterations will be done in reverse)

Examples found in repository?
src/pattern/search_mode.rs (line 212)
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
    fn default() -> Self {
        let mut smm = SearchModeMap {
            entries: Vec::new(),
        };
        // the last keys are preferred
        smm.setm(&["ne", "en", "e"], SearchMode::NameExact);
        smm.setm(&["nf", "fn", "n", "f"], SearchMode::NameFuzzy);
        smm.setm(&["r", "nr", "rn", ""], SearchMode::NameRegex);
        smm.setm(&["pe", "ep"], SearchMode::PathExact);
        smm.setm(&["pf", "fp", "p"], SearchMode::PathFuzzy);
        smm.setm(&["pr", "rp"], SearchMode::PathRegex);
        smm.setm(&["ce", "ec", "c"], SearchMode::ContentExact);
        smm.setm(&["rx", "cr"], SearchMode::ContentRegex);
        smm.setm(&["pt", "tp", "t"], SearchMode::PathTokens);
        smm.setm(&["tn", "nt"], SearchMode::NameTokens);
        smm.set(SearchModeMapEntry { key: None, mode: SearchMode::PathFuzzy });
        smm
    }
}

impl TryFrom<&FnvHashMap<String, String>> for SearchModeMap {
    type Error = ConfError;
    fn try_from(map: &FnvHashMap<String, String>) -> Result<Self, Self::Error> {
        let mut smm = Self::default();
        for (k, v) in map {
            smm.entries.push(SearchModeMapEntry::parse(k, v)?);
        }
        Ok(smm)
    }
}

impl SearchModeMap {
    pub fn setm(&mut self, keys: &[&str], mode: SearchMode) {
        for key in keys {
            self.set(SearchModeMapEntry {
                key: Some(key.to_string()),
                mode,
            });
        }
    }
Examples found in repository?
src/pattern/pattern.rs (line 45)
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
    pub fn new(
        raw_expr: &BeTree<PatternOperator, PatternParts>,
        search_modes: &SearchModeMap,
        content_search_max_file_size: usize,
    ) -> Result<Self, PatternError> {
        let expr: BeTree<PatternOperator, Pattern> = raw_expr
            .try_map_atoms::<_, PatternError, _>(|pattern_parts| {
                let core = pattern_parts.core();
                Ok(
                    if core.is_empty() {
                        Pattern::None
                    } else {
                        let parts_mode = pattern_parts.mode();
                        let mode = search_modes.search_mode(parts_mode)?;
                        let flags = pattern_parts.flags();
                        match mode {
                            SearchMode::NameExact => Self::NameExact(
                                ExactPattern::from(core)
                            ),
                            SearchMode::NameFuzzy => Self::NameFuzzy(
                                FuzzyPattern::from(core)
                            ),
                            SearchMode::NameRegex => Self::NameRegex(
                                RegexPattern::from(core, flags.unwrap_or(""))?
                            ),
                            SearchMode::NameTokens => Self::NameTokens(
                                TokPattern::new(core)
                            ),
                            SearchMode::PathExact => Self::PathExact(
                                ExactPattern::from(core)
                            ),
                            SearchMode::PathFuzzy => Self::PathFuzzy(
                                FuzzyPattern::from(core)
                            ),
                            SearchMode::PathRegex => Self::PathRegex(
                                RegexPattern::from(core, flags.unwrap_or(""))?
                            ),
                            SearchMode::PathTokens => Self::PathTokens(
                                TokPattern::new(core)
                            ),
                            SearchMode::ContentExact => Self::ContentExact(
                                ContentExactPattern::new(core, content_search_max_file_size)
                            ),
                            SearchMode::ContentRegex => Self::ContentRegex(
                                ContentRegexPattern::new(
                                    core,
                                    flags.unwrap_or(""),
                                    content_search_max_file_size,
                                )?
                            ),
                        }
                    }
                )
            })?;
        Ok(if expr.is_empty() {
            Pattern::None
        } else if expr.is_atomic() {
            expr.atoms().pop().unwrap()
        } else {
            Self::Composite(CompositePattern::new(expr))
        })
    }
More examples
Hide additional examples
src/help/help_state.rs (line 154)
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)?)
    }
Examples found in repository?
src/pattern/search_mode.rs (line 85)
82
83
84
85
86
87
    pub fn prefix(self, con: &AppContext) -> String {
        con
            .search_modes
            .key(self)
            .map_or_else(|| "".to_string(), |k| format!("{}/", k))
    }

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
The type returned in the event of a conversion error.
Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.