Enum broot::app::SelInfo

source ·
pub enum SelInfo<'s> {
    None,
    One(Selection<'s>),
    More(&'s Stage),
}

Variants§

§

None

§

One(Selection<'s>)

§

More(&'s Stage)

Implementations§

Examples found in repository?
src/verb/internal_select.rs (line 99)
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
fn path_from_input(
    verb: &Verb,
    internal_exec: &InternalExecution,
    base_path: &Path, // either the selected path or the root path
    input_arg: Option<&String>,
    app_state: &AppState,
) -> PathBuf {
    match (input_arg, internal_exec.arg.as_ref()) {
        (Some(input_arg), Some(verb_arg)) => {
            // The verb probably defines some patttern which uses the input.
            // For example:
            // {
            //     invocation: "gotar {path}"
            //     execution: ":select {path}/target"
            // }
            // (or that input is useless)
            let path_builder = ExecutionStringBuilder::with_invocation(
                &verb.invocation_parser,
                SelInfo::from_path(base_path),
                app_state,
                Some(input_arg),
            );
            path_builder.path(verb_arg)
        }
        (Some(input_arg), None) => {
            // the verb defines nothing
            // The :select internal execution was triggered from the
            // input (which must be a kind of alias for :select)
            // so we do exactly what the input asks for
            path::path_from(base_path, PathAnchor::Unspecified, input_arg)
        }
        (None, Some(verb_arg)) => {
            // the verb defines the path where to go..
            // the internal_execution specifies the path to use
            // (it may come from a configured verb whose execution is
            //  `:select some/path`).
            // The given path may be relative hence the need for the
            // state's selection
            // (we assume a check before ensured it doesn't need an input)
            path::path_from(base_path, PathAnchor::Unspecified, verb_arg)
        }
        (None, None) => {
            // This doesn't really make sense: we're selecting the currently
            // selected path
            base_path.to_path_buf()
        }
    }

}
More examples
Hide additional examples
src/verb/internal_focus.rs (line 104)
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
fn path_from_input(
    verb: &Verb,
    internal_exec: &InternalExecution,
    base_path: &Path, // either the selected path or the root path
    input_arg: Option<&String>,
    app_state: &AppState,
) -> PathBuf {
    match (input_arg, internal_exec.arg.as_ref()) {
        (Some(input_arg), Some(verb_arg)) => {
            // The verb probably defines some patttern which uses the input.
            // For example:
            // {
            //     invocation: "gotar {path}"
            //     execution: ":focus {path}/target"
            // }
            // (or that input is useless)
            let path_builder = ExecutionStringBuilder::with_invocation(
                &verb.invocation_parser,
                SelInfo::from_path(base_path),
                app_state,
                Some(input_arg),
            );
            path_builder.path(verb_arg)
        }
        (Some(input_arg), None) => {
            // the verb defines nothing
            // The :focus internal execution was triggered from the
            // input (which must be a kind of alias for :focus)
            // so we do exactly what the input asks for
            path::path_from(base_path, PathAnchor::Unspecified, input_arg)
        }
        (None, Some(verb_arg)) => {
            // the verb defines the path where to go..
            // the internal_execution specifies the path to use
            // (it may come from a configured verb whose execution is
            //  `:focus some/path`).
            // The given path may be relative hence the need for the
            // state's selection
            // (we assume a check before ensured it doesn't need an input)
            path::path_from(base_path, PathAnchor::Unspecified, verb_arg)
        }
        (None, None) => {
            // user only wants to open the selected path, either in the same panel or
            // in a new one
            base_path.to_path_buf()
        }
    }

}
Examples found in repository?
src/verb/verb_store.rs (line 50)
44
45
46
47
48
49
50
51
52
    pub fn search_sel_info<'v>(
        &'v self,
        prefix: &str,
        sel_info: SelInfo<'_>,
    ) -> PrefixSearchResult<'v, &Verb> {
        let stype = sel_info.common_stype();
        let count = sel_info.count_paths();
        self.search(prefix, stype, Some(count), sel_info.extension())
    }
More examples
Hide additional examples
src/verb/external_execution.rs (line 108)
103
104
105
106
107
108
109
110
111
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
    fn cmd_result_exec_from_parent_shell(
        &self,
        builder: ExecutionStringBuilder<'_>,
        con: &AppContext,
    ) -> Result<CmdResult, ProgramError> {
        if builder.sel_info.count_paths() > 1 {
            return Ok(CmdResult::error(
                "only verbs returning to broot on end can be executed on a multi-selection"
            ));
        }
        if let Some(ref export_path) = con.launch_args.outcmd {
            // Broot was probably launched as br.
            // the whole command is exported in the passed file
            let f = OpenOptions::new().append(true).open(export_path)?;
            writeln!(&f, "{}", builder.shell_exec_string(&self.exec_pattern))?;
            Ok(CmdResult::Quit)
        } else {
            Ok(CmdResult::error(
                "this verb needs broot to be launched as `br`. Try `broot --install` if necessary."
            ))
        }
    }

    /// build the cmd result as an executable which will be called in a process
    /// launched by broot at end of broot
    fn cmd_result_exec_leave_broot(
        &self,
        builder: ExecutionStringBuilder<'_>,
        con: &AppContext,
    ) -> Result<CmdResult, ProgramError> {
        if builder.sel_info.count_paths() > 1 {
            return Ok(CmdResult::error(
                "only verbs returning to broot on end can be executed on a multi-selection"
            ));
        }
        let launchable = Launchable::program(
            builder.exec_token(&self.exec_pattern),
            self.working_dir_path(&builder),
            con,
        )?;
        Ok(CmdResult::from(launchable))
    }
src/app/panel_state.rs (line 981)
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
    fn get_verb_status(
        &self,
        verb: &Verb,
        invocation: &VerbInvocation,
        sel_info: SelInfo<'_>,
        _cc: &CmdContext,
        app_state: &AppState,
    ) -> Status {
        if sel_info.count_paths() > 1 {
            if let VerbExecution::External(external) = &verb.execution {
                if external.exec_mode != ExternalExecutionMode::StayInBroot {
                    return Status::new(
                        "only verbs returning to broot on end can be executed on a multi-selection".to_owned(),
                        true,
                    );
                }
            }
            // right now there's no check for sequences but they're inherently dangereous
        }
        if let Some(err) = verb.check_args(sel_info, invocation, &app_state.other_panel_path) {
            Status::new(err, true)
        } else {
            Status::new(
                verb.get_status_markdown(
                    sel_info,
                    app_state,
                    invocation,
                ),
                false,
            )
        }
    }
Examples found in repository?
src/verb/verb_store.rs (line 49)
44
45
46
47
48
49
50
51
52
    pub fn search_sel_info<'v>(
        &'v self,
        prefix: &str,
        sel_info: SelInfo<'_>,
    ) -> PrefixSearchResult<'v, &Verb> {
        let stype = sel_info.common_stype();
        let count = sel_info.count_paths();
        self.search(prefix, stype, Some(count), sel_info.extension())
    }
More examples
Hide additional examples
src/command/panel_input.rs (line 329)
185
186
187
188
189
190
191
192
193
194
195
196
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
    fn get_command(
        &mut self,
        timed_event: TimedEvent,
        con: &AppContext,
        sel_info: SelInfo<'_>,
        app_state: &AppState,
        mode: Mode,
        panel_state_type: PanelStateType,
    ) -> Command {
        match timed_event.event {
            Event::Mouse(MouseEvent { kind, column, row, modifiers: KeyModifiers::NONE }) => {
                if self.input_field.apply_timed_event(timed_event) {
                    Command::empty()
                } else {
                    match kind {
                        MouseEventKind::Up(MouseButton::Left) => {
                            if timed_event.double_click {
                                Command::DoubleClick(column, row)
                            } else {
                                Command::Click(column, row)
                            }
                        }
                        MouseEventKind::ScrollDown => {
                            Command::Internal {
                                internal: Internal::line_down,
                                input_invocation: None,
                            }
                        }
                        MouseEventKind::ScrollUp => {
                            Command::Internal {
                                internal: Internal::line_up,
                                input_invocation: None,
                            }
                        }
                        _ => Command::None,
                    }
                }
            }
            Event::Key(key) => {
                // value of raw and parts before any key related change
                let raw = self.input_field.get_content();
                let mut parts = CommandParts::from(raw.clone());

                // we first handle the cases that MUST absolutely
                // not be overridden by configuration

                if key == key!(esc) {
                    // tab cycling
                    self.tab_cycle_count = 0;
                    if let Some(raw) = self.input_before_cycle.take() {
                        // we cancel the tab cycling
                        self.input_field.set_str(&raw);
                        self.input_before_cycle = None;
                        return Command::from_raw(raw, false);
                    } else if con.modal && mode == Mode::Input {
                        // leave insertion mode
                        return Command::Internal {
                            internal: Internal::mode_command,
                            input_invocation: None,
                        };
                    } else {
                        // general back command
                        self.input_field.clear();
                        let internal = Internal::back;
                        return Command::Internal {
                            internal,
                            input_invocation: parts.verb_invocation,
                        };
                    }
                }

                // tab completion
                if key == key!(tab) {
                    if parts.verb_invocation.is_some() {
                        let parts_before_cycle;
                        let completable_parts = if let Some(s) = &self.input_before_cycle {
                            parts_before_cycle = CommandParts::from(s.clone());
                            &parts_before_cycle
                        } else {
                            &parts
                        };
                        let completions = Completions::for_input(completable_parts, con, sel_info);
                        info!(" -> completions: {:?}", &completions);
                        let added = match completions {
                            Completions::None => {
                                debug!("nothing to complete!");
                                self.tab_cycle_count = 0;
                                self.input_before_cycle = None;
                                None
                            }
                            Completions::Common(completion) => {
                                self.tab_cycle_count = 0;
                                Some(completion)
                            }
                            Completions::List(mut completions) => {
                                let idx = self.tab_cycle_count % completions.len();
                                if self.tab_cycle_count == 0 {
                                    self.input_before_cycle = Some(raw.to_string());
                                }
                                self.tab_cycle_count += 1;
                                Some(completions.swap_remove(idx))
                            }
                        };
                        if let Some(added) = added {
                            let mut raw = self
                                .input_before_cycle
                                .as_ref()
                                .map_or(raw, |s| s.to_string());
                            raw.push_str(&added);
                            self.input_field.set_str(&raw);
                            return Command::from_raw(raw, false);
                        } else {
                            return Command::None;
                        }
                    }
                } else {
                    self.tab_cycle_count = 0;
                    self.input_before_cycle = None;
                }

                if key == key!(enter) && parts.has_not_empty_verb_invocation() {
                    return Command::from_parts(parts, true);
                }

                if (key == key!('?') || key == key!(shift-'?'))
                    && (raw.is_empty() || parts.verb_invocation.is_some()) {
                    // a '?' opens the help when it's the first char
                    // or when it's part of the verb invocation
                    return Command::Internal {
                        internal: Internal::help,
                        input_invocation: parts.verb_invocation,
                    };
                }

                // we now check if the key is the trigger key of one of the verbs
                if keys::is_key_allowed_for_verb(key, mode, raw.is_empty()) {
                    for (index, verb) in con.verb_store.verbs.iter().enumerate() {
                        for verb_key in &verb.keys {
                            if *verb_key != key {
                                continue;
                            }
                            if self.handle_input_related_verb(verb, con) {
                                return Command::from_raw(self.input_field.get_content(), false);
                            }
                            if !verb.selection_condition.is_respected_by(sel_info.common_stype()) {
                                continue;
                            }
                            if !verb.can_be_called_in_panel(panel_state_type) {
                                continue;
                            }
                            if mode != Mode::Input && verb.is_internal(Internal::mode_input) {
                                self.enter_input_mode_with_key(key, &parts);
                            }
                            if !verb.file_extensions.is_empty() {
                                let extension = sel_info.extension();
                                if !extension.map_or(false, |ext| verb.file_extensions.iter().any(|ve| ve == ext)) {
                                    continue;
                                }
                            }
                            if verb.auto_exec {
                                return Command::VerbTrigger {
                                    index,
                                    input_invocation: parts.verb_invocation,
                                };
                            }
                            if let Some(invocation_parser) = &verb.invocation_parser {
                                let exec_builder = ExecutionStringBuilder::without_invocation(
                                    sel_info,
                                    app_state,
                                );
                                let verb_invocation = exec_builder.invocation_with_default(
                                    &invocation_parser.invocation_pattern
                                );
                                parts.verb_invocation = Some(verb_invocation);
                                self.set_content(&parts.to_string());
                                return Command::VerbEdit(parts.verb_invocation.unwrap());
                            }
                        }
                    }
                }

                // input field management
                if mode == Mode::Input {
                    if self.input_field.apply_timed_event(timed_event) {
                        return Command::from_raw(self.input_field.get_content(), false);
                    }
                }
                Command::None
            }
            _ => Command::None,
        }
    }
Examples found in repository?
src/app/selection.rs (line 138)
137
138
139
    pub fn one_path(self) -> Option<&'a Path> {
        self.one_sel().map(|sel| sel.path)
    }
More examples
Hide additional examples
src/verb/execution_builder.rs (line 228)
226
227
228
229
230
    fn base_dir(&self) -> &Path {
        self.sel_info
            .one_sel()
            .map_or(self.root, |sel| sel.path)
    }
Examples found in repository?
src/verb/internal_focus.rs (line 144)
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
pub fn get_status_markdown(
    verb: &Verb,
    internal_exec: &InternalExecution,
    sel_info: SelInfo<'_>,
    invocation: &VerbInvocation,
    app_state: &AppState,
) -> String {
    let base_path = sel_info
        .one_path()
        .unwrap_or(&app_state.root);
    let path = path_from_input(
        verb,
        internal_exec,
        base_path,
        invocation.args.as_ref(),
        app_state,
    );
    format!("Hit *enter* to focus `{}`", path.to_string_lossy())
}
Examples found in repository?
src/verb/verb_store.rs (line 51)
44
45
46
47
48
49
50
51
52
    pub fn search_sel_info<'v>(
        &'v self,
        prefix: &str,
        sel_info: SelInfo<'_>,
    ) -> PrefixSearchResult<'v, &Verb> {
        let stype = sel_info.common_stype();
        let count = sel_info.count_paths();
        self.search(prefix, stype, Some(count), sel_info.extension())
    }
More examples
Hide additional examples
src/command/panel_input.rs (line 339)
185
186
187
188
189
190
191
192
193
194
195
196
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
    fn get_command(
        &mut self,
        timed_event: TimedEvent,
        con: &AppContext,
        sel_info: SelInfo<'_>,
        app_state: &AppState,
        mode: Mode,
        panel_state_type: PanelStateType,
    ) -> Command {
        match timed_event.event {
            Event::Mouse(MouseEvent { kind, column, row, modifiers: KeyModifiers::NONE }) => {
                if self.input_field.apply_timed_event(timed_event) {
                    Command::empty()
                } else {
                    match kind {
                        MouseEventKind::Up(MouseButton::Left) => {
                            if timed_event.double_click {
                                Command::DoubleClick(column, row)
                            } else {
                                Command::Click(column, row)
                            }
                        }
                        MouseEventKind::ScrollDown => {
                            Command::Internal {
                                internal: Internal::line_down,
                                input_invocation: None,
                            }
                        }
                        MouseEventKind::ScrollUp => {
                            Command::Internal {
                                internal: Internal::line_up,
                                input_invocation: None,
                            }
                        }
                        _ => Command::None,
                    }
                }
            }
            Event::Key(key) => {
                // value of raw and parts before any key related change
                let raw = self.input_field.get_content();
                let mut parts = CommandParts::from(raw.clone());

                // we first handle the cases that MUST absolutely
                // not be overridden by configuration

                if key == key!(esc) {
                    // tab cycling
                    self.tab_cycle_count = 0;
                    if let Some(raw) = self.input_before_cycle.take() {
                        // we cancel the tab cycling
                        self.input_field.set_str(&raw);
                        self.input_before_cycle = None;
                        return Command::from_raw(raw, false);
                    } else if con.modal && mode == Mode::Input {
                        // leave insertion mode
                        return Command::Internal {
                            internal: Internal::mode_command,
                            input_invocation: None,
                        };
                    } else {
                        // general back command
                        self.input_field.clear();
                        let internal = Internal::back;
                        return Command::Internal {
                            internal,
                            input_invocation: parts.verb_invocation,
                        };
                    }
                }

                // tab completion
                if key == key!(tab) {
                    if parts.verb_invocation.is_some() {
                        let parts_before_cycle;
                        let completable_parts = if let Some(s) = &self.input_before_cycle {
                            parts_before_cycle = CommandParts::from(s.clone());
                            &parts_before_cycle
                        } else {
                            &parts
                        };
                        let completions = Completions::for_input(completable_parts, con, sel_info);
                        info!(" -> completions: {:?}", &completions);
                        let added = match completions {
                            Completions::None => {
                                debug!("nothing to complete!");
                                self.tab_cycle_count = 0;
                                self.input_before_cycle = None;
                                None
                            }
                            Completions::Common(completion) => {
                                self.tab_cycle_count = 0;
                                Some(completion)
                            }
                            Completions::List(mut completions) => {
                                let idx = self.tab_cycle_count % completions.len();
                                if self.tab_cycle_count == 0 {
                                    self.input_before_cycle = Some(raw.to_string());
                                }
                                self.tab_cycle_count += 1;
                                Some(completions.swap_remove(idx))
                            }
                        };
                        if let Some(added) = added {
                            let mut raw = self
                                .input_before_cycle
                                .as_ref()
                                .map_or(raw, |s| s.to_string());
                            raw.push_str(&added);
                            self.input_field.set_str(&raw);
                            return Command::from_raw(raw, false);
                        } else {
                            return Command::None;
                        }
                    }
                } else {
                    self.tab_cycle_count = 0;
                    self.input_before_cycle = None;
                }

                if key == key!(enter) && parts.has_not_empty_verb_invocation() {
                    return Command::from_parts(parts, true);
                }

                if (key == key!('?') || key == key!(shift-'?'))
                    && (raw.is_empty() || parts.verb_invocation.is_some()) {
                    // a '?' opens the help when it's the first char
                    // or when it's part of the verb invocation
                    return Command::Internal {
                        internal: Internal::help,
                        input_invocation: parts.verb_invocation,
                    };
                }

                // we now check if the key is the trigger key of one of the verbs
                if keys::is_key_allowed_for_verb(key, mode, raw.is_empty()) {
                    for (index, verb) in con.verb_store.verbs.iter().enumerate() {
                        for verb_key in &verb.keys {
                            if *verb_key != key {
                                continue;
                            }
                            if self.handle_input_related_verb(verb, con) {
                                return Command::from_raw(self.input_field.get_content(), false);
                            }
                            if !verb.selection_condition.is_respected_by(sel_info.common_stype()) {
                                continue;
                            }
                            if !verb.can_be_called_in_panel(panel_state_type) {
                                continue;
                            }
                            if mode != Mode::Input && verb.is_internal(Internal::mode_input) {
                                self.enter_input_mode_with_key(key, &parts);
                            }
                            if !verb.file_extensions.is_empty() {
                                let extension = sel_info.extension();
                                if !extension.map_or(false, |ext| verb.file_extensions.iter().any(|ve| ve == ext)) {
                                    continue;
                                }
                            }
                            if verb.auto_exec {
                                return Command::VerbTrigger {
                                    index,
                                    input_invocation: parts.verb_invocation,
                                };
                            }
                            if let Some(invocation_parser) = &verb.invocation_parser {
                                let exec_builder = ExecutionStringBuilder::without_invocation(
                                    sel_info,
                                    app_state,
                                );
                                let verb_invocation = exec_builder.invocation_with_default(
                                    &invocation_parser.invocation_pattern
                                );
                                parts.verb_invocation = Some(verb_invocation);
                                self.set_content(&parts.to_string());
                                return Command::VerbEdit(parts.verb_invocation.unwrap());
                            }
                        }
                    }
                }

                // input field management
                if mode == Mode::Input {
                    if self.input_field.apply_timed_event(timed_event) {
                        return Command::from_raw(self.input_field.get_content(), false);
                    }
                }
                Command::None
            }
            _ => Command::None,
        }
    }

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

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
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.