Trait broot::app::PanelState

source ·
pub trait PanelState {
Show 35 methods fn get_type(&self) -> PanelStateType; fn set_mode(&mut self, mode: Mode); fn get_mode(&self) -> Mode; fn on_internal(
        &mut self,
        w: &mut W,
        internal_exec: &InternalExecution,
        input_invocation: Option<&VerbInvocation>,
        trigger_type: TriggerType<'_>,
        app_state: &mut AppState,
        cc: &CmdContext<'_>
    ) -> Result<CmdResult, ProgramError>; fn selected_path(&self) -> Option<&Path>; fn selection(&self) -> Option<Selection<'_>>; fn refresh(&mut self, screen: Screen, con: &AppContext) -> Command; fn tree_options(&self) -> TreeOptions; fn with_new_options(
        &mut self,
        screen: Screen,
        change_options: &dyn Fn(&mut TreeOptions) -> &'static str,
        in_new_panel: bool,
        con: &AppContext
    ) -> CmdResult; fn display(
        &mut self,
        w: &mut W,
        disc: &DisplayContext<'_>
    ) -> Result<(), ProgramError>; fn clear_pending(&mut self) { ... } fn on_click(
        &mut self,
        _x: u16,
        _y: u16,
        _screen: Screen,
        _con: &AppContext
    ) -> Result<CmdResult, ProgramError> { ... } fn on_double_click(
        &mut self,
        _x: u16,
        _y: u16,
        _screen: Screen,
        _con: &AppContext
    ) -> Result<CmdResult, ProgramError> { ... } fn on_pattern(
        &mut self,
        _pat: InputPattern,
        _app_state: &AppState,
        _con: &AppContext
    ) -> Result<CmdResult, ProgramError> { ... } fn on_mode_verb(&mut self, mode: Mode, con: &AppContext) -> CmdResult { ... } fn on_internal_generic(
        &mut self,
        _w: &mut W,
        internal_exec: &InternalExecution,
        input_invocation: Option<&VerbInvocation>,
        _trigger_type: TriggerType<'_>,
        app_state: &mut AppState,
        cc: &CmdContext<'_>
    ) -> Result<CmdResult, ProgramError> { ... } fn stage(
        &self,
        app_state: &mut AppState,
        cc: &CmdContext<'_>,
        con: &AppContext
    ) -> CmdResult { ... } fn unstage(
        &self,
        app_state: &mut AppState,
        cc: &CmdContext<'_>,
        _con: &AppContext
    ) -> CmdResult { ... } fn toggle_stage(
        &self,
        app_state: &mut AppState,
        cc: &CmdContext<'_>,
        con: &AppContext
    ) -> CmdResult { ... } fn execute_verb(
        &mut self,
        w: &mut W,
        verb: &Verb,
        invocation: Option<&VerbInvocation>,
        trigger_type: TriggerType<'_>,
        app_state: &mut AppState,
        cc: &CmdContext<'_>
    ) -> Result<CmdResult, ProgramError> { ... } fn execute_external(
        &mut self,
        w: &mut W,
        verb: &Verb,
        external_execution: &ExternalExecution,
        invocation: Option<&VerbInvocation>,
        app_state: &mut AppState,
        cc: &CmdContext<'_>
    ) -> Result<CmdResult, ProgramError> { ... } fn execute_sequence(
        &mut self,
        _w: &mut W,
        verb: &Verb,
        seq_ex: &SequenceExecution,
        invocation: Option<&VerbInvocation>,
        app_state: &mut AppState,
        _cc: &CmdContext<'_>
    ) -> Result<CmdResult, ProgramError> { ... } fn on_command(
        &mut self,
        w: &mut W,
        app_state: &mut AppState,
        cc: &CmdContext<'_>
    ) -> Result<CmdResult, ProgramError> { ... } fn open_preview(
        &mut self,
        prefered_mode: Option<PreviewMode>,
        close_if_open: bool,
        cc: &CmdContext<'_>
    ) -> CmdResult { ... } fn tree_root(&self) -> Option<&Path> { ... } fn sel_info<'c>(&'c self, _app_state: &'c AppState) -> SelInfo<'c> { ... } fn has_at_least_one_selection(&self, _app_state: &AppState) -> bool { ... } fn do_pending_task(
        &mut self,
        _app_state: &mut AppState,
        _screen: Screen,
        _con: &AppContext,
        _dam: &mut Dam
    ) -> Result<(), ProgramError> { ... } fn get_pending_task(&self) -> Option<&'static str> { ... } fn get_flags(&self) -> Vec<Flag> { ... } fn get_starting_input(&self) -> String { ... } fn set_selected_path(&mut self, _path: PathBuf, _con: &AppContext) { ... } fn no_verb_status(
        &self,
        _has_previous_state: bool,
        _con: &AppContext
    ) -> Status { ... } fn get_status(
        &self,
        app_state: &AppState,
        cc: &CmdContext<'_>,
        has_previous_state: bool
    ) -> Status { ... } fn get_verb_status(
        &self,
        verb: &Verb,
        invocation: &VerbInvocation,
        sel_info: SelInfo<'_>,
        _cc: &CmdContext<'_>,
        app_state: &AppState
    ) -> Status { ... }
}
Expand description

a panel state, stackable to allow reverting to a previous one

Required Methods§

execute the internal with the optional given invocation.

The invocation comes from the input and may be related to a different verb (the verb may have been triggered by a key shortcut)

Build a cmdResult in response to a command being a change of tree options. This may or not be a new state.

The provided change_options function returns a status message explaining the change

Provided Methods§

called on start of on_command

Examples found in repository?
src/app/panel_state.rs (line 739)
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
    fn on_command(
        &mut self,
        w: &mut W,
        app_state: &mut AppState,
        cc: &CmdContext,
    ) -> Result<CmdResult, ProgramError> {
        self.clear_pending();
        let con = &cc.app.con;
        let screen = cc.app.screen;
        match &cc.cmd {
            Command::Click(x, y) => self.on_click(*x, *y, screen, con),
            Command::DoubleClick(x, y) => self.on_double_click(*x, *y, screen, con),
            Command::PatternEdit { raw, expr } => {
                match InputPattern::new(raw.clone(), expr, con) {
                    Ok(pattern) => self.on_pattern(pattern, app_state, con),
                    Err(e) => Ok(CmdResult::DisplayError(format!("{}", e))),
                }
            }
            Command::VerbTrigger {
                index,
                input_invocation,
            } => self.execute_verb(
                w,
                &con.verb_store.verbs[*index],
                input_invocation.as_ref(),
                TriggerType::Other,
                app_state,
                cc,
            ),
            Command::Internal {
                internal,
                input_invocation,
            } => self.on_internal(
                w,
                &InternalExecution::from_internal(*internal),
                input_invocation.as_ref(),
                TriggerType::Other,
                app_state,
                cc,
            ),
            Command::VerbInvocate(invocation) => {
                let sel_info = self.sel_info(app_state);
                match con.verb_store.search_sel_info(
                    &invocation.name,
                    sel_info,
                ) {
                    PrefixSearchResult::Match(_, verb) => {
                        self.execute_verb(
                            w,
                            verb,
                            Some(invocation),
                            TriggerType::Input(verb),
                            app_state,
                            cc,
                        )
                    }
                    _ => Ok(CmdResult::verb_not_found(&invocation.name)),
                }
            }
            Command::None | Command::VerbEdit(_) => {
                // we do nothing here, the real job is done in get_status
                Ok(CmdResult::Keep)
            }
        }
    }
Examples found in repository?
src/app/panel_state.rs (line 743)
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
    fn on_command(
        &mut self,
        w: &mut W,
        app_state: &mut AppState,
        cc: &CmdContext,
    ) -> Result<CmdResult, ProgramError> {
        self.clear_pending();
        let con = &cc.app.con;
        let screen = cc.app.screen;
        match &cc.cmd {
            Command::Click(x, y) => self.on_click(*x, *y, screen, con),
            Command::DoubleClick(x, y) => self.on_double_click(*x, *y, screen, con),
            Command::PatternEdit { raw, expr } => {
                match InputPattern::new(raw.clone(), expr, con) {
                    Ok(pattern) => self.on_pattern(pattern, app_state, con),
                    Err(e) => Ok(CmdResult::DisplayError(format!("{}", e))),
                }
            }
            Command::VerbTrigger {
                index,
                input_invocation,
            } => self.execute_verb(
                w,
                &con.verb_store.verbs[*index],
                input_invocation.as_ref(),
                TriggerType::Other,
                app_state,
                cc,
            ),
            Command::Internal {
                internal,
                input_invocation,
            } => self.on_internal(
                w,
                &InternalExecution::from_internal(*internal),
                input_invocation.as_ref(),
                TriggerType::Other,
                app_state,
                cc,
            ),
            Command::VerbInvocate(invocation) => {
                let sel_info = self.sel_info(app_state);
                match con.verb_store.search_sel_info(
                    &invocation.name,
                    sel_info,
                ) {
                    PrefixSearchResult::Match(_, verb) => {
                        self.execute_verb(
                            w,
                            verb,
                            Some(invocation),
                            TriggerType::Input(verb),
                            app_state,
                            cc,
                        )
                    }
                    _ => Ok(CmdResult::verb_not_found(&invocation.name)),
                }
            }
            Command::None | Command::VerbEdit(_) => {
                // we do nothing here, the real job is done in get_status
                Ok(CmdResult::Keep)
            }
        }
    }
Examples found in repository?
src/app/panel_state.rs (line 744)
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
    fn on_command(
        &mut self,
        w: &mut W,
        app_state: &mut AppState,
        cc: &CmdContext,
    ) -> Result<CmdResult, ProgramError> {
        self.clear_pending();
        let con = &cc.app.con;
        let screen = cc.app.screen;
        match &cc.cmd {
            Command::Click(x, y) => self.on_click(*x, *y, screen, con),
            Command::DoubleClick(x, y) => self.on_double_click(*x, *y, screen, con),
            Command::PatternEdit { raw, expr } => {
                match InputPattern::new(raw.clone(), expr, con) {
                    Ok(pattern) => self.on_pattern(pattern, app_state, con),
                    Err(e) => Ok(CmdResult::DisplayError(format!("{}", e))),
                }
            }
            Command::VerbTrigger {
                index,
                input_invocation,
            } => self.execute_verb(
                w,
                &con.verb_store.verbs[*index],
                input_invocation.as_ref(),
                TriggerType::Other,
                app_state,
                cc,
            ),
            Command::Internal {
                internal,
                input_invocation,
            } => self.on_internal(
                w,
                &InternalExecution::from_internal(*internal),
                input_invocation.as_ref(),
                TriggerType::Other,
                app_state,
                cc,
            ),
            Command::VerbInvocate(invocation) => {
                let sel_info = self.sel_info(app_state);
                match con.verb_store.search_sel_info(
                    &invocation.name,
                    sel_info,
                ) {
                    PrefixSearchResult::Match(_, verb) => {
                        self.execute_verb(
                            w,
                            verb,
                            Some(invocation),
                            TriggerType::Input(verb),
                            app_state,
                            cc,
                        )
                    }
                    _ => Ok(CmdResult::verb_not_found(&invocation.name)),
                }
            }
            Command::None | Command::VerbEdit(_) => {
                // we do nothing here, the real job is done in get_status
                Ok(CmdResult::Keep)
            }
        }
    }
Examples found in repository?
src/app/panel_state.rs (line 747)
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
    fn on_command(
        &mut self,
        w: &mut W,
        app_state: &mut AppState,
        cc: &CmdContext,
    ) -> Result<CmdResult, ProgramError> {
        self.clear_pending();
        let con = &cc.app.con;
        let screen = cc.app.screen;
        match &cc.cmd {
            Command::Click(x, y) => self.on_click(*x, *y, screen, con),
            Command::DoubleClick(x, y) => self.on_double_click(*x, *y, screen, con),
            Command::PatternEdit { raw, expr } => {
                match InputPattern::new(raw.clone(), expr, con) {
                    Ok(pattern) => self.on_pattern(pattern, app_state, con),
                    Err(e) => Ok(CmdResult::DisplayError(format!("{}", e))),
                }
            }
            Command::VerbTrigger {
                index,
                input_invocation,
            } => self.execute_verb(
                w,
                &con.verb_store.verbs[*index],
                input_invocation.as_ref(),
                TriggerType::Other,
                app_state,
                cc,
            ),
            Command::Internal {
                internal,
                input_invocation,
            } => self.on_internal(
                w,
                &InternalExecution::from_internal(*internal),
                input_invocation.as_ref(),
                TriggerType::Other,
                app_state,
                cc,
            ),
            Command::VerbInvocate(invocation) => {
                let sel_info = self.sel_info(app_state);
                match con.verb_store.search_sel_info(
                    &invocation.name,
                    sel_info,
                ) {
                    PrefixSearchResult::Match(_, verb) => {
                        self.execute_verb(
                            w,
                            verb,
                            Some(invocation),
                            TriggerType::Input(verb),
                            app_state,
                            cc,
                        )
                    }
                    _ => Ok(CmdResult::verb_not_found(&invocation.name)),
                }
            }
            Command::None | Command::VerbEdit(_) => {
                // we do nothing here, the real job is done in get_status
                Ok(CmdResult::Keep)
            }
        }
    }
More examples
Hide additional examples
src/preview/preview_state.rs (line 317)
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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
    fn on_internal(
        &mut self,
        w: &mut W,
        internal_exec: &InternalExecution,
        input_invocation: Option<&VerbInvocation>,
        trigger_type: TriggerType,
        app_state: &mut AppState,
        cc: &CmdContext,
    ) -> Result<CmdResult, ProgramError> {
        let con = &cc.app.con;
        match internal_exec.internal {
            Internal::back => {
                if self.filtered_preview.is_some() {
                    self.on_pattern(InputPattern::none(), app_state, con)
                } else {
                    Ok(CmdResult::PopState)
                }
            }
            Internal::copy_line => {
                #[cfg(not(feature = "clipboard"))]
                {
                    Ok(CmdResult::error("Clipboard feature not enabled at compilation"))
                }
                #[cfg(feature = "clipboard")]
                {
                    Ok(match self.mut_preview().get_selected_line() {
                        Some(line) => {
                            match terminal_clipboard::set_string(line) {
                                Ok(()) => CmdResult::Keep,
                                Err(_) => CmdResult::error("Clipboard error while copying path"),
                            }
                        }
                        None => CmdResult::error("No selected line in preview"),
                    })
                }
            }
            Internal::line_down => {
                let count = get_arg(input_invocation, internal_exec, 1);
                self.mut_preview().move_selection(count, true);
                Ok(CmdResult::Keep)
            }
            Internal::line_up => {
                let count = get_arg(input_invocation, internal_exec, 1);
                self.mut_preview().move_selection(-count, true);
                Ok(CmdResult::Keep)
            }
            Internal::line_down_no_cycle => {
                let count = get_arg(input_invocation, internal_exec, 1);
                self.mut_preview().move_selection(count, false);
                Ok(CmdResult::Keep)
            }
            Internal::line_up_no_cycle => {
                let count = get_arg(input_invocation, internal_exec, 1);
                self.mut_preview().move_selection(-count, false);
                Ok(CmdResult::Keep)
            }
            Internal::page_down => {
                self.mut_preview().try_scroll(ScrollCommand::Pages(1));
                Ok(CmdResult::Keep)
            }
            Internal::page_up => {
                self.mut_preview().try_scroll(ScrollCommand::Pages(-1));
                Ok(CmdResult::Keep)
            }
            //Internal::restore_pattern => {
            //    debug!("restore_pattern");
            //    self.pending_pattern = self.removed_pattern.take();
            //    Ok(CmdResult::Keep)
            //}
            Internal::panel_left if self.removed_pattern.is_some() => {
                self.pending_pattern = self.removed_pattern.take();
                Ok(CmdResult::Keep)
            }
            Internal::panel_left_no_open if self.removed_pattern.is_some() => {
                self.pending_pattern = self.removed_pattern.take();
                Ok(CmdResult::Keep)
            }
            Internal::panel_right if self.filtered_preview.is_some() => {
                self.on_pattern(InputPattern::none(), app_state, con)
            }
            Internal::panel_right_no_open if self.filtered_preview.is_some() => {
                self.on_pattern(InputPattern::none(), app_state, con)
            }
            Internal::select_first => {
                self.mut_preview().select_first();
                Ok(CmdResult::Keep)
            }
            Internal::select_last => {
                self.mut_preview().select_last();
                Ok(CmdResult::Keep)
            }
            Internal::preview_image => self.set_mode(PreviewMode::Image, con),
            Internal::preview_text => self.set_mode(PreviewMode::Text, con),
            Internal::preview_binary => self.set_mode(PreviewMode::Hex, con),
            _ => self.on_internal_generic(
                w,
                internal_exec,
                input_invocation,
                trigger_type,
                app_state,
                cc,
            ),
        }
    }
Examples found in repository?
src/app/panel_state.rs (line 178)
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
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
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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
    fn on_internal_generic(
        &mut self,
        _w: &mut W,
        internal_exec: &InternalExecution,
        input_invocation: Option<&VerbInvocation>,
        _trigger_type: TriggerType,
        app_state: &mut AppState,
        cc: &CmdContext,
    ) -> Result<CmdResult, ProgramError> {
        let con = &cc.app.con;
        let screen = cc.app.screen;
        let bang = input_invocation
            .map(|inv| inv.bang)
            .unwrap_or(internal_exec.bang);
        Ok(match internal_exec.internal {
            Internal::back => CmdResult::PopState,
            Internal::copy_line | Internal::copy_path => {
                #[cfg(not(feature = "clipboard"))]
                {
                    CmdResult::error("Clipboard feature not enabled at compilation")
                }
                #[cfg(feature = "clipboard")]
                {
                    if let Some(path) = self.selected_path() {
                        let path = path.to_string_lossy().to_string();
                        match terminal_clipboard::set_string(path) {
                            Ok(()) => CmdResult::Keep,
                            Err(_) => CmdResult::error("Clipboard error while copying path"),
                        }
                    } else {
                        CmdResult::error("Nothing to copy")
                    }
                }
            }
            Internal::close_panel_ok => CmdResult::ClosePanel {
                validate_purpose: true,
                panel_ref: PanelReference::Active,
            },
            Internal::close_panel_cancel => CmdResult::ClosePanel {
                validate_purpose: false,
                panel_ref: PanelReference::Active,
            },
            #[cfg(unix)]
            Internal::filesystems => {
                let fs_state = crate::filesystems::FilesystemState::new(
                    self.selected_path(),
                    self.tree_options(),
                    con,
                );
                match fs_state {
                    Ok(state) => {
                        let bang = input_invocation
                            .map(|inv| inv.bang)
                            .unwrap_or(internal_exec.bang);
                        if bang && cc.app.preview_panel.is_none() {
                            CmdResult::NewPanel {
                                state: Box::new(state),
                                purpose: PanelPurpose::None,
                                direction: HDir::Right,
                            }
                        } else {
                            CmdResult::new_state(Box::new(state))
                        }
                    }
                    Err(e) => CmdResult::DisplayError(format!("{}", e)),
                }
            }
            Internal::help => {
                let bang = input_invocation
                    .map(|inv| inv.bang)
                    .unwrap_or(internal_exec.bang);
                if bang && cc.app.preview_panel.is_none() {
                    CmdResult::NewPanel {
                        state: Box::new(HelpState::new(self.tree_options(), screen, con)),
                        purpose: PanelPurpose::None,
                        direction: HDir::Right,
                    }
                } else {
                    CmdResult::new_state(Box::new(
                            HelpState::new(self.tree_options(), screen, con)
                    ))
                }
            }
            Internal::mode_input => self.on_mode_verb(Mode::Input, con),
            Internal::mode_command => self.on_mode_verb(Mode::Command, con),
            Internal::open_leave => {
                if let Some(selection) = self.selection() {
                    selection.to_opener(con)?
                } else {
                    CmdResult::error("no selection to open")
                }
            }
            Internal::open_preview => self.open_preview(None, false, cc),
            Internal::preview_image => self.open_preview(Some(PreviewMode::Image), false, cc),
            Internal::preview_text => self.open_preview(Some(PreviewMode::Text), false, cc),
            Internal::preview_binary => self.open_preview(Some(PreviewMode::Hex), false, cc),
            Internal::toggle_preview => self.open_preview(None, true, cc),
            Internal::sort_by_count => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::Count {
                        o.sort = Sort::None;
                        o.show_counts = false;
                        "*not sorting anymore*"
                    } else {
                        o.sort = Sort::Count;
                        o.show_counts = true;
                        "*now sorting by file count*"
                    }
                },
                bang,
                con,
            ),
            Internal::sort_by_date => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::Date {
                        o.sort = Sort::None;
                        o.show_dates = false;
                        "*not sorting anymore*"
                    } else {
                        o.sort = Sort::Date;
                        o.show_dates = true;
                        "*now sorting by last modified date*"
                    }
                },
                bang,
                con,
            ),
            Internal::sort_by_size => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::Size {
                        o.sort = Sort::None;
                        o.show_sizes = false;
                        "*not sorting anymore*"
                    } else {
                        o.sort = Sort::Size;
                        o.show_sizes = true;
                        o.show_root_fs = true;
                        "*now sorting files and directories by total size*"
                    }
                },
                bang,
                con,
            ),
            Internal::sort_by_type => self.with_new_options(
                screen,
                &|o| {
                    match o.sort {
                        Sort::TypeDirsFirst => {
                           o.sort = Sort::TypeDirsLast;
                           "*sorting by type, directories last*"
                        }
                        Sort::TypeDirsLast => {
                            o.sort = Sort::None;
                            "*not sorting anymore*"
                        }
                        _ => {
                            o.sort = Sort::TypeDirsFirst;
                           "*sorting by type, directories first*"
                        }
                    }
                },
                bang,
                con,
            ),
            Internal::sort_by_type_dirs_first => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::TypeDirsFirst {
                        o.sort = Sort::None;
                        "*not sorting anymore*"
                    } else {
                        o.sort = Sort::TypeDirsFirst;
                        "*now sorting by type, directories first*"
                    }
                },
                bang,
                con,
            ),
            Internal::sort_by_type_dirs_last => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::TypeDirsLast {
                        o.sort = Sort::None;
                        "*not sorting anymore*"
                    } else {
                        o.sort = Sort::TypeDirsLast;
                        "*now sorting by type, directories last*"
                    }
                },
                bang,
                con,
            ),
            Internal::no_sort => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::None {
                        "*still not searching*"
                    } else {
                        o.sort = Sort::None;
                        "*not sorting anymore*"
                    }
                },
                bang,
                con,
            ),
            Internal::toggle_counts => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_counts ^= true;
                        if o.show_counts {
                            "*displaying file counts*"
                        } else {
                            "*hiding file counts*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_dates => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_dates ^= true;
                        if o.show_dates {
                            "*displaying last modified dates*"
                        } else {
                            "*hiding last modified dates*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_device_id => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_device_id ^= true;
                        if o.show_device_id {
                            "*displaying device id*"
                        } else {
                            "*hiding device id*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_files => {
                self.with_new_options(
					screen,
					&|o| {
                        o.only_folders ^= true;
                        if o.only_folders {
                            "*displaying only directories*"
                        } else {
                            "*displaying both files and directories*"
                        }
                    },
					bang,
					con,
				)
            }
            Internal::toggle_hidden => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_hidden ^= true;
                        if o.show_hidden {
                            "h:**y** - *Hidden files displayed*"
                        } else {
                            "h:**n** - *Hidden files not displayed*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_root_fs => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_root_fs ^= true;
                        if o.show_root_fs {
                            "*displaying filesystem info for the tree's root directory*"
                        } else {
                            "*removing filesystem info*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_git_ignore => {
                self.with_new_options(
					screen,
					&|o| {
						o.respect_git_ignore ^= true;
                        if o.respect_git_ignore {
                            "gi:**y** - *applying gitignore rules*"
                        } else {
                            "gi:**n** - *not applying gitignore rules*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_git_file_info => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_git_file_info ^= true;
                        if o.show_git_file_info {
                            "*displaying git info next to files*"
                        } else {
                            "*removing git file info*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_git_status => {
                self.with_new_options(
                    screen, &|o| {
                        if o.filter_by_git_status {
                            o.filter_by_git_status = false;
                            "*not filtering according to git status anymore*"
                        } else {
                            o.filter_by_git_status = true;
                            o.show_hidden = true;
                            "*only displaying new or modified files*"
                        }
                    }, bang, con
                )
            }
            Internal::toggle_perm => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_permissions ^= true;
                        if o.show_permissions {
                            "*displaying file permissions*"
                        } else {
                            "*removing file permissions*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_sizes => self.with_new_options(
                screen,
                &|o| {
                    if o.show_sizes {
                        o.show_sizes = false;
                        o.show_root_fs = false;
                        "*removing sizes of files and directories*"
                    } else {
                        o.show_sizes = true;
                        o.show_root_fs = true;
                        "*now diplaying sizes of files and directories*"
                    }
                },
                bang,
                con,
            ),
            Internal::toggle_trim_root => {
                self.with_new_options(
					screen,
					&|o| {
						o.trim_root ^= true;
                        if o.trim_root {
                            "*now trimming root from excess files*"
                        } else {
                            "*not trimming root files anymore*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::close_preview => {
                if let Some(id) = cc.app.preview_panel {
                    CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(id),
                    }
                } else {
                    CmdResult::Keep
                }
            }
            Internal::panel_left | Internal::panel_left_no_open => {
                CmdResult::HandleInApp(Internal::panel_left_no_open)
            }
            Internal::panel_right | Internal::panel_right_no_open => {
                CmdResult::HandleInApp(Internal::panel_right_no_open)
            }
            Internal::toggle_second_tree => {
                CmdResult::HandleInApp(Internal::toggle_second_tree)
            }
            Internal::clear_stage => {
                app_state.stage.clear();
                if let Some(panel_id) = cc.app.stage_panel {
                    CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(panel_id),
                    }
                } else {
                    CmdResult::Keep
                }
            }
            Internal::stage => self.stage(app_state, cc, con),
            Internal::unstage => self.unstage(app_state, cc, con),
            Internal::toggle_stage => self.toggle_stage(app_state, cc, con),
            Internal::close_staging_area => {
                if let Some(id) = cc.app.stage_panel {
                    CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(id),
                    }
                } else {
                    CmdResult::Keep
                }
            }
            Internal::open_staging_area => {
                if cc.app.stage_panel.is_none() {
                    CmdResult::NewPanel {
                        state: Box::new(StageState::new(app_state, self.tree_options(), con)),
                        purpose: PanelPurpose::None,
                        direction: HDir::Right,
                    }
                } else {
                    CmdResult::Keep
                }
            }
            Internal::toggle_staging_area => {
                if let Some(id) = cc.app.stage_panel {
                    CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(id),
                    }
                } else {
                    CmdResult::NewPanel {
                        state: Box::new(StageState::new(app_state, self.tree_options(), con)),
                        purpose: PanelPurpose::None,
                        direction: HDir::Right,
                    }
                }
            }
            Internal::set_syntax_theme => CmdResult::HandleInApp(Internal::set_syntax_theme),
            Internal::print_path => print::print_paths(self.sel_info(app_state), con)?,
            Internal::print_relative_path => print::print_relative_paths(self.sel_info(app_state), con)?,
            Internal::refresh => CmdResult::RefreshState { clear_cache: true },
            Internal::quit => CmdResult::Quit,
            _ => CmdResult::Keep,
        })
    }

a generic implementation of on_internal which may be called by states when they don’t have a specific behavior to execute

Examples found in repository?
src/help/help_state.rs (lines 261-268)
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
    fn on_internal(
        &mut self,
        w: &mut W,
        internal_exec: &InternalExecution,
        input_invocation: Option<&VerbInvocation>,
        trigger_type: TriggerType,
        app_state: &mut AppState,
        cc: &CmdContext,
    ) -> Result<CmdResult, ProgramError> {
        use Internal::*;
        Ok(match internal_exec.internal {
            Internal::back => {
                if self.pattern.is_some() {
                    self.pattern = Pattern::None;
                    CmdResult::Keep
                } else {
                    CmdResult::PopState
                }
            }
            help => CmdResult::Keep,
            line_down | line_down_no_cycle => {
                self.scroll += get_arg(input_invocation, internal_exec, 1);
                CmdResult::Keep
            }
            line_up | line_up_no_cycle => {
                let dy = get_arg(input_invocation, internal_exec, 1);
                self.scroll = if self.scroll > dy {
                    self.scroll - dy
                } else {
                    0
                };
                CmdResult::Keep
            }
            open_stay => match opener::open(&Conf::default_location()) {
                Ok(exit_status) => {
                    info!("open returned with exit_status {:?}", exit_status);
                    CmdResult::Keep
                }
                Err(e) => CmdResult::DisplayError(format!("{:?}", e)),
            },
            // FIXME check we can't use the generic one
            open_leave => {
                CmdResult::from(Launchable::opener(
                    Conf::default_location()
                ))
            }
            page_down => {
                self.scroll += self.text_area.height as usize;
                CmdResult::Keep
            }
            page_up => {
                let height = self.text_area.height as usize;
                self.scroll = if self.scroll > height {
                    self.scroll - self.text_area.height as usize
                } else {
                    0
                };
                CmdResult::Keep
            }
            _ => self.on_internal_generic(
                w,
                internal_exec,
                input_invocation,
                trigger_type,
                app_state,
                cc,
            )?,
        })
    }
More examples
Hide additional examples
src/stage/stage_state.rs (lines 496-503)
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
    fn on_internal(
        &mut self,
        w: &mut W,
        internal_exec: &InternalExecution,
        input_invocation: Option<&VerbInvocation>,
        trigger_type: TriggerType,
        app_state: &mut AppState,
        cc: &CmdContext,
    ) -> Result<CmdResult, ProgramError> {
        Ok(match internal_exec.internal {
            Internal::back if self.filtered_stage.pattern().is_some() => {
                self.filtered_stage = FilteredStage::unfiltered(&app_state.stage);
                CmdResult::Keep
            }
            Internal::back if self.filtered_stage.has_selection() => {
                self.filtered_stage.unselect();
                CmdResult::Keep
            }
            Internal::line_down => {
                let count = get_arg(input_invocation, internal_exec, 1);
                self.move_selection(count, true)
            }
            Internal::line_up => {
                let count = get_arg(input_invocation, internal_exec, 1);
                self.move_selection(-count, true)
            }
            Internal::line_down_no_cycle => {
                let count = get_arg(input_invocation, internal_exec, 1);
                self.move_selection(count, false)
            }
            Internal::line_up_no_cycle => {
                let count = get_arg(input_invocation, internal_exec, 1);
                self.move_selection(-count, false)
            }
            Internal::page_down => {
                self.try_scroll(ScrollCommand::Pages(1));
                CmdResult::Keep
            }
            Internal::page_up => {
                self.try_scroll(ScrollCommand::Pages(-1));
                CmdResult::Keep
            }
            Internal::stage => {
                // shall we restage what we just unstaged ?
                CmdResult::error("nothing to stage here")
            }
            Internal::unstage | Internal::toggle_stage => {
                if self.filtered_stage.unstage_selection(&mut app_state.stage) {
                    CmdResult::Keep
                } else {
                    CmdResult::error("you must select a path to unstage")
                }
            }
            _ => self.on_internal_generic(
                w,
                internal_exec,
                input_invocation,
                trigger_type,
                app_state,
                cc,
            )?,
        })
    }
src/preview/preview_state.rs (lines 398-405)
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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
    fn on_internal(
        &mut self,
        w: &mut W,
        internal_exec: &InternalExecution,
        input_invocation: Option<&VerbInvocation>,
        trigger_type: TriggerType,
        app_state: &mut AppState,
        cc: &CmdContext,
    ) -> Result<CmdResult, ProgramError> {
        let con = &cc.app.con;
        match internal_exec.internal {
            Internal::back => {
                if self.filtered_preview.is_some() {
                    self.on_pattern(InputPattern::none(), app_state, con)
                } else {
                    Ok(CmdResult::PopState)
                }
            }
            Internal::copy_line => {
                #[cfg(not(feature = "clipboard"))]
                {
                    Ok(CmdResult::error("Clipboard feature not enabled at compilation"))
                }
                #[cfg(feature = "clipboard")]
                {
                    Ok(match self.mut_preview().get_selected_line() {
                        Some(line) => {
                            match terminal_clipboard::set_string(line) {
                                Ok(()) => CmdResult::Keep,
                                Err(_) => CmdResult::error("Clipboard error while copying path"),
                            }
                        }
                        None => CmdResult::error("No selected line in preview"),
                    })
                }
            }
            Internal::line_down => {
                let count = get_arg(input_invocation, internal_exec, 1);
                self.mut_preview().move_selection(count, true);
                Ok(CmdResult::Keep)
            }
            Internal::line_up => {
                let count = get_arg(input_invocation, internal_exec, 1);
                self.mut_preview().move_selection(-count, true);
                Ok(CmdResult::Keep)
            }
            Internal::line_down_no_cycle => {
                let count = get_arg(input_invocation, internal_exec, 1);
                self.mut_preview().move_selection(count, false);
                Ok(CmdResult::Keep)
            }
            Internal::line_up_no_cycle => {
                let count = get_arg(input_invocation, internal_exec, 1);
                self.mut_preview().move_selection(-count, false);
                Ok(CmdResult::Keep)
            }
            Internal::page_down => {
                self.mut_preview().try_scroll(ScrollCommand::Pages(1));
                Ok(CmdResult::Keep)
            }
            Internal::page_up => {
                self.mut_preview().try_scroll(ScrollCommand::Pages(-1));
                Ok(CmdResult::Keep)
            }
            //Internal::restore_pattern => {
            //    debug!("restore_pattern");
            //    self.pending_pattern = self.removed_pattern.take();
            //    Ok(CmdResult::Keep)
            //}
            Internal::panel_left if self.removed_pattern.is_some() => {
                self.pending_pattern = self.removed_pattern.take();
                Ok(CmdResult::Keep)
            }
            Internal::panel_left_no_open if self.removed_pattern.is_some() => {
                self.pending_pattern = self.removed_pattern.take();
                Ok(CmdResult::Keep)
            }
            Internal::panel_right if self.filtered_preview.is_some() => {
                self.on_pattern(InputPattern::none(), app_state, con)
            }
            Internal::panel_right_no_open if self.filtered_preview.is_some() => {
                self.on_pattern(InputPattern::none(), app_state, con)
            }
            Internal::select_first => {
                self.mut_preview().select_first();
                Ok(CmdResult::Keep)
            }
            Internal::select_last => {
                self.mut_preview().select_last();
                Ok(CmdResult::Keep)
            }
            Internal::preview_image => self.set_mode(PreviewMode::Image, con),
            Internal::preview_text => self.set_mode(PreviewMode::Text, con),
            Internal::preview_binary => self.set_mode(PreviewMode::Hex, con),
            _ => self.on_internal_generic(
                w,
                internal_exec,
                input_invocation,
                trigger_type,
                app_state,
                cc,
            ),
        }
    }
src/filesystems/filesystems_state.rs (lines 579-586)
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
    fn on_internal(
        &mut self,
        w: &mut W,
        internal_exec: &InternalExecution,
        input_invocation: Option<&VerbInvocation>,
        trigger_type: TriggerType,
        app_state: &mut AppState,
        cc: &CmdContext,
    ) -> Result<CmdResult, ProgramError> {
        let screen = cc.app.screen;
        let con = &cc.app.con;
        use Internal::*;
        Ok(match internal_exec.internal {
            Internal::back => {
                if let Some(f) = self.filtered.take() {
                    if !f.mounts.is_empty() {
                        self.selection_idx = self.mounts.iter()
                            .position(|m| m.info.id == f.mounts[f.selection_idx].info.id)
                            .unwrap(); // all filtered mounts come from self.mounts
                    }
                    CmdResult::Keep
                } else {
                    CmdResult::PopState
                }
            }
            Internal::line_down => {
                self.move_line(internal_exec, input_invocation, 1, true)
            }
            Internal::line_up => {
                self.move_line(internal_exec, input_invocation, -1, true)
            }
            Internal::line_down_no_cycle => {
                self.move_line(internal_exec, input_invocation, 1, false)
            }
            Internal::line_up_no_cycle => {
                self.move_line(internal_exec, input_invocation, -1, false)
            }
            Internal::open_stay => {
                let in_new_panel = input_invocation
                    .map(|inv| inv.bang)
                    .unwrap_or(internal_exec.bang);
                let dam = Dam::unlimited();
                let mut tree_options = self.tree_options();
                tree_options.show_root_fs = true;
                CmdResult::from_optional_state(
                    BrowserState::new(
                        self.no_opt_selected_path().to_path_buf(),
                        tree_options,
                        screen,
                        con,
                        &dam,
                    ),
                    None,
                    in_new_panel,
                )
            }
            Internal::panel_left => {
                let areas = &cc.panel.areas;
                if areas.is_first() && areas.nb_pos < con.max_panels_count {
                    // we ask for the creation of a panel to the left
                    internal_focus::new_panel_on_path(
                        self.no_opt_selected_path().to_path_buf(),
                        screen,
                        self.tree_options(),
                        PanelPurpose::None,
                        con,
                        HDir::Left,
                    )
                } else {
                    // we ask the app to focus the panel to the left
                    CmdResult::HandleInApp(Internal::panel_left_no_open)
                }
            }
            Internal::panel_left_no_open => CmdResult::HandleInApp(Internal::panel_left_no_open),
            Internal::panel_right => {
                let areas = &cc.panel.areas;
                if areas.is_last() && areas.nb_pos < con.max_panels_count {
                    // we ask for the creation of a panel to the right
                    internal_focus::new_panel_on_path(
                        self.no_opt_selected_path().to_path_buf(),
                        screen,
                        self.tree_options(),
                        PanelPurpose::None,
                        con,
                        HDir::Right,
                    )
                } else {
                    // we ask the app to focus the panel to the right
                    CmdResult::HandleInApp(Internal::panel_right_no_open)
                }
            }
            Internal::panel_right_no_open => CmdResult::HandleInApp(Internal::panel_right_no_open),
            Internal::page_down => {
                if !self.try_scroll(ScrollCommand::Pages(1)) {
                    self.selection_idx = self.count() - 1;
                }
                CmdResult::Keep
            }
            Internal::page_up => {
                if !self.try_scroll(ScrollCommand::Pages(-1)) {
                    self.selection_idx = 0;
                }
                CmdResult::Keep
            }
            open_leave => CmdResult::PopStateAndReapply,
            _ => self.on_internal_generic(
                w,
                internal_exec,
                input_invocation,
                trigger_type,
                app_state,
                cc,
            )?,
        })
    }
src/browser/browser_state.rs (lines 601-608)
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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
    fn on_internal(
        &mut self,
        w: &mut W,
        internal_exec: &InternalExecution,
        input_invocation: Option<&VerbInvocation>,
        trigger_type: TriggerType,
        app_state: &mut AppState,
        cc: &CmdContext,
    ) -> Result<CmdResult, ProgramError> {
        let con = &cc.app.con;
        let screen = cc.app.screen;
        let page_height = BrowserState::page_height(cc.app.screen);
        let bang = input_invocation
            .map(|inv| inv.bang)
            .unwrap_or(internal_exec.bang);
        Ok(match internal_exec.internal {
            Internal::back => {
                if let Some(filtered_tree) = &self.filtered_tree {
                    let filtered_selection = &filtered_tree.selected_line().path;
                    if self.tree.try_select_path(filtered_selection) {
                        self.tree.make_selection_visible(page_height);
                    }
                    self.filtered_tree = None;
                    CmdResult::Keep
                } else if self.tree.selection > 0 {
                    self.tree.selection = 0;
                    CmdResult::Keep
                } else {
                    CmdResult::PopState
                }
            }
            Internal::focus => internal_focus::on_internal(
                internal_exec,
                input_invocation,
                trigger_type,
                &self.displayed_tree().selected_line().path,
                self.displayed_tree().options.clone(),
                app_state,
                cc,
            ),
            Internal::select => internal_select::on_internal(
                internal_exec,
                input_invocation,
                trigger_type,
                self.displayed_tree_mut(),
                app_state,
                cc,
            ),
            Internal::up_tree => match self.displayed_tree().root().parent() {
                Some(path) => internal_focus::on_path(
                    path.to_path_buf(),
                    screen,
                    self.displayed_tree().options.clone(),
                    bang,
                    con,
                ),
                None => CmdResult::error("no parent found"),
            },
            Internal::open_stay => self.open_selection_stay_in_broot(screen, con, bang, false)?,
            Internal::open_stay_filter => self.open_selection_stay_in_broot(screen, con, bang, true)?,
            Internal::line_down => {
                let count = get_arg(input_invocation, internal_exec, 1);
                self.displayed_tree_mut().move_selection(count, page_height, true);
                CmdResult::Keep
            }
            Internal::line_up => {
                let count = get_arg(input_invocation, internal_exec, 1);
                self.displayed_tree_mut().move_selection(-count, page_height, true);
                CmdResult::Keep
            }
            Internal::line_down_no_cycle => {
                let count = get_arg(input_invocation, internal_exec, 1);
                self.displayed_tree_mut().move_selection(count, page_height, false);
                CmdResult::Keep
            }
            Internal::line_up_no_cycle => {
                let count = get_arg(input_invocation, internal_exec, 1);
                self.displayed_tree_mut().move_selection(-count, page_height, false);
                CmdResult::Keep
            }
            Internal::previous_dir => {
                self.displayed_tree_mut().try_select_previous_filtered(
                    |line| line.is_dir(),
                    page_height,
                );
                CmdResult::Keep
            }
            Internal::next_dir => {
                self.displayed_tree_mut().try_select_next_filtered(
                    |line| line.is_dir(),
                    page_height,
                );
                CmdResult::Keep
            }
            Internal::previous_match => {
                self.displayed_tree_mut().try_select_previous_filtered(
                    |line| line.direct_match,
                    page_height,
                );
                CmdResult::Keep
            }
            Internal::next_match => {
                self.displayed_tree_mut().try_select_next_filtered(
                    |line| line.direct_match,
                    page_height,
                );
                CmdResult::Keep
            }
            Internal::previous_same_depth => {
                self.displayed_tree_mut().try_select_previous_same_depth(page_height);
                CmdResult::Keep
            }
            Internal::next_same_depth => {
                self.displayed_tree_mut().try_select_next_same_depth(page_height);
                CmdResult::Keep
            }
            Internal::page_down => {
                let tree = self.displayed_tree_mut();
                if !tree.try_scroll(page_height as i32, page_height) {
                    tree.try_select_last(page_height);
                }
                CmdResult::Keep
            }
            Internal::page_up => {
                let tree = self.displayed_tree_mut();
                if !tree.try_scroll(page_height as i32 * -1, page_height) {
                    tree.try_select_first();
                }
                CmdResult::Keep
            }
            Internal::panel_left => {
                let areas = &cc.panel.areas;
                if areas.is_first() && areas.nb_pos < con.max_panels_count  {
                    // we ask for the creation of a panel to the left
                    internal_focus::new_panel_on_path(
                        self.displayed_tree().selected_line().path.to_path_buf(),
                        screen,
                        self.displayed_tree().options.clone(),
                        PanelPurpose::None,
                        con,
                        HDir::Left,
                    )
                } else {
                    // we let the app handle other cases
                    CmdResult::HandleInApp(Internal::panel_left_no_open)
                }
            }
            Internal::panel_left_no_open => CmdResult::HandleInApp(Internal::panel_left_no_open),
            Internal::panel_right => {
                let areas = &cc.panel.areas;
                let selected_path = &self.displayed_tree().selected_line().path;
                if areas.is_last() && areas.nb_pos < con.max_panels_count {
                    let purpose = if selected_path.is_file() && cc.app.preview_panel.is_none() {
                        PanelPurpose::Preview
                    } else {
                        PanelPurpose::None
                    };
                    // we ask for the creation of a panel to the right
                    internal_focus::new_panel_on_path(
                        selected_path.to_path_buf(),
                        screen,
                        self.displayed_tree().options.clone(),
                        purpose,
                        con,
                        HDir::Right,
                    )
                } else {
                    // we ask the app to handle other cases :
                    // focus the panel to the right or close the leftest one
                    CmdResult::HandleInApp(Internal::panel_right_no_open)
                }
            }
            Internal::panel_right_no_open => CmdResult::HandleInApp(Internal::panel_right_no_open),
            Internal::parent => self.go_to_parent(screen, con, bang),
            Internal::print_tree => {
                print::print_tree(self.displayed_tree(), cc.app.screen, cc.app.panel_skin, con)?
            }
            Internal::root_up => {
                let tree = self.displayed_tree();
                let root = tree.root();
                if let Some(new_root) = root.parent() {
                    self.modified(
                        screen,
                        new_root.to_path_buf(),
                        tree.options.clone(),
                        None,
                        bang,
                        con,
                    )
                } else {
                    CmdResult::error(format!("{:?} has no parent", root))
                }
            }
            Internal::root_down => {
                let tree = self.displayed_tree();
                if tree.selection > 0 {
                    let root_len = tree.root().components().count();
                    let new_root = tree.selected_line().path
                        .components()
                        .take(root_len + 1)
                        .collect();
                    self.modified(
                        screen,
                        new_root,
                        tree.options.clone(),
                        None,
                        bang,
                        con,
                    )
                } else {
                    CmdResult::error("No selected line")
                }
            }
            Internal::stage_all_files => {
                let pattern = self.displayed_tree().options.pattern.clone();
                self.pending_task = Some(BrowserTask::StageAll(pattern));
                if cc.app.stage_panel.is_none() {
                    let stage_options = self.tree.options.without_pattern();
                    CmdResult::NewPanel {
                        state: Box::new(StageState::new(app_state, stage_options, con)),
                        purpose: PanelPurpose::None,
                        direction: HDir::Right,
                    }
                } else {
                    CmdResult::Keep
                }
            }
            Internal::select_first => {
                self.displayed_tree_mut().try_select_first();
                CmdResult::Keep
            }
            Internal::select_last => {
                let page_height = BrowserState::page_height(screen);
                self.displayed_tree_mut().try_select_last(page_height);
                CmdResult::Keep
            }
            Internal::start_end_panel => {
                if cc.panel.purpose.is_arg_edition() {
                    debug!("start_end understood as end");
                    CmdResult::ClosePanel {
                        validate_purpose: true,
                        panel_ref: PanelReference::Active,
                    }
                } else {
                    debug!("start_end understood as start");
                    let tree_options = self.displayed_tree().options.clone();
                    if let Some(input_invocation) = input_invocation {
                        // we'll go for input arg editing
                        let path = if let Some(input_arg) = &input_invocation.args {
                            path::path_from(self.root(), PathAnchor::Unspecified, input_arg)
                        } else {
                            self.root().to_path_buf()
                        };
                        let arg_type = SelectionType::Any; // We might do better later
                        let purpose = PanelPurpose::ArgEdition { arg_type };
                        internal_focus::new_panel_on_path(
                            path, screen, tree_options, purpose, con, HDir::Right,
                        )
                    } else {
                        // we just open a new panel on the selected path,
                        // without purpose
                        internal_focus::new_panel_on_path(
                            self.displayed_tree().selected_line().path.to_path_buf(),
                            screen,
                            tree_options,
                            PanelPurpose::None,
                            con,
                            HDir::Right,
                        )
                    }
                }
            }
            Internal::total_search => {
                match self.filtered_tree.as_ref().map(|t| t.total_search) {
                    None => {
                        CmdResult::error("this verb can be used only after a search")
                    }
                    Some(true) => {
                        CmdResult::error("search was already total: all possible matches have been ranked")
                    }
                    Some(false) => {
                        self.search(self.displayed_tree().options.pattern.clone(), true);
                        CmdResult::Keep
                    }
                }
            }
            Internal::quit => CmdResult::Quit,
            _ => self.on_internal_generic(
                w,
                internal_exec,
                input_invocation,
                trigger_type,
                app_state,
                cc,
            )?,
        })
    }
Examples found in repository?
src/app/panel_state.rs (line 513)
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
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
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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
    fn on_internal_generic(
        &mut self,
        _w: &mut W,
        internal_exec: &InternalExecution,
        input_invocation: Option<&VerbInvocation>,
        _trigger_type: TriggerType,
        app_state: &mut AppState,
        cc: &CmdContext,
    ) -> Result<CmdResult, ProgramError> {
        let con = &cc.app.con;
        let screen = cc.app.screen;
        let bang = input_invocation
            .map(|inv| inv.bang)
            .unwrap_or(internal_exec.bang);
        Ok(match internal_exec.internal {
            Internal::back => CmdResult::PopState,
            Internal::copy_line | Internal::copy_path => {
                #[cfg(not(feature = "clipboard"))]
                {
                    CmdResult::error("Clipboard feature not enabled at compilation")
                }
                #[cfg(feature = "clipboard")]
                {
                    if let Some(path) = self.selected_path() {
                        let path = path.to_string_lossy().to_string();
                        match terminal_clipboard::set_string(path) {
                            Ok(()) => CmdResult::Keep,
                            Err(_) => CmdResult::error("Clipboard error while copying path"),
                        }
                    } else {
                        CmdResult::error("Nothing to copy")
                    }
                }
            }
            Internal::close_panel_ok => CmdResult::ClosePanel {
                validate_purpose: true,
                panel_ref: PanelReference::Active,
            },
            Internal::close_panel_cancel => CmdResult::ClosePanel {
                validate_purpose: false,
                panel_ref: PanelReference::Active,
            },
            #[cfg(unix)]
            Internal::filesystems => {
                let fs_state = crate::filesystems::FilesystemState::new(
                    self.selected_path(),
                    self.tree_options(),
                    con,
                );
                match fs_state {
                    Ok(state) => {
                        let bang = input_invocation
                            .map(|inv| inv.bang)
                            .unwrap_or(internal_exec.bang);
                        if bang && cc.app.preview_panel.is_none() {
                            CmdResult::NewPanel {
                                state: Box::new(state),
                                purpose: PanelPurpose::None,
                                direction: HDir::Right,
                            }
                        } else {
                            CmdResult::new_state(Box::new(state))
                        }
                    }
                    Err(e) => CmdResult::DisplayError(format!("{}", e)),
                }
            }
            Internal::help => {
                let bang = input_invocation
                    .map(|inv| inv.bang)
                    .unwrap_or(internal_exec.bang);
                if bang && cc.app.preview_panel.is_none() {
                    CmdResult::NewPanel {
                        state: Box::new(HelpState::new(self.tree_options(), screen, con)),
                        purpose: PanelPurpose::None,
                        direction: HDir::Right,
                    }
                } else {
                    CmdResult::new_state(Box::new(
                            HelpState::new(self.tree_options(), screen, con)
                    ))
                }
            }
            Internal::mode_input => self.on_mode_verb(Mode::Input, con),
            Internal::mode_command => self.on_mode_verb(Mode::Command, con),
            Internal::open_leave => {
                if let Some(selection) = self.selection() {
                    selection.to_opener(con)?
                } else {
                    CmdResult::error("no selection to open")
                }
            }
            Internal::open_preview => self.open_preview(None, false, cc),
            Internal::preview_image => self.open_preview(Some(PreviewMode::Image), false, cc),
            Internal::preview_text => self.open_preview(Some(PreviewMode::Text), false, cc),
            Internal::preview_binary => self.open_preview(Some(PreviewMode::Hex), false, cc),
            Internal::toggle_preview => self.open_preview(None, true, cc),
            Internal::sort_by_count => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::Count {
                        o.sort = Sort::None;
                        o.show_counts = false;
                        "*not sorting anymore*"
                    } else {
                        o.sort = Sort::Count;
                        o.show_counts = true;
                        "*now sorting by file count*"
                    }
                },
                bang,
                con,
            ),
            Internal::sort_by_date => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::Date {
                        o.sort = Sort::None;
                        o.show_dates = false;
                        "*not sorting anymore*"
                    } else {
                        o.sort = Sort::Date;
                        o.show_dates = true;
                        "*now sorting by last modified date*"
                    }
                },
                bang,
                con,
            ),
            Internal::sort_by_size => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::Size {
                        o.sort = Sort::None;
                        o.show_sizes = false;
                        "*not sorting anymore*"
                    } else {
                        o.sort = Sort::Size;
                        o.show_sizes = true;
                        o.show_root_fs = true;
                        "*now sorting files and directories by total size*"
                    }
                },
                bang,
                con,
            ),
            Internal::sort_by_type => self.with_new_options(
                screen,
                &|o| {
                    match o.sort {
                        Sort::TypeDirsFirst => {
                           o.sort = Sort::TypeDirsLast;
                           "*sorting by type, directories last*"
                        }
                        Sort::TypeDirsLast => {
                            o.sort = Sort::None;
                            "*not sorting anymore*"
                        }
                        _ => {
                            o.sort = Sort::TypeDirsFirst;
                           "*sorting by type, directories first*"
                        }
                    }
                },
                bang,
                con,
            ),
            Internal::sort_by_type_dirs_first => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::TypeDirsFirst {
                        o.sort = Sort::None;
                        "*not sorting anymore*"
                    } else {
                        o.sort = Sort::TypeDirsFirst;
                        "*now sorting by type, directories first*"
                    }
                },
                bang,
                con,
            ),
            Internal::sort_by_type_dirs_last => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::TypeDirsLast {
                        o.sort = Sort::None;
                        "*not sorting anymore*"
                    } else {
                        o.sort = Sort::TypeDirsLast;
                        "*now sorting by type, directories last*"
                    }
                },
                bang,
                con,
            ),
            Internal::no_sort => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::None {
                        "*still not searching*"
                    } else {
                        o.sort = Sort::None;
                        "*not sorting anymore*"
                    }
                },
                bang,
                con,
            ),
            Internal::toggle_counts => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_counts ^= true;
                        if o.show_counts {
                            "*displaying file counts*"
                        } else {
                            "*hiding file counts*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_dates => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_dates ^= true;
                        if o.show_dates {
                            "*displaying last modified dates*"
                        } else {
                            "*hiding last modified dates*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_device_id => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_device_id ^= true;
                        if o.show_device_id {
                            "*displaying device id*"
                        } else {
                            "*hiding device id*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_files => {
                self.with_new_options(
					screen,
					&|o| {
                        o.only_folders ^= true;
                        if o.only_folders {
                            "*displaying only directories*"
                        } else {
                            "*displaying both files and directories*"
                        }
                    },
					bang,
					con,
				)
            }
            Internal::toggle_hidden => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_hidden ^= true;
                        if o.show_hidden {
                            "h:**y** - *Hidden files displayed*"
                        } else {
                            "h:**n** - *Hidden files not displayed*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_root_fs => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_root_fs ^= true;
                        if o.show_root_fs {
                            "*displaying filesystem info for the tree's root directory*"
                        } else {
                            "*removing filesystem info*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_git_ignore => {
                self.with_new_options(
					screen,
					&|o| {
						o.respect_git_ignore ^= true;
                        if o.respect_git_ignore {
                            "gi:**y** - *applying gitignore rules*"
                        } else {
                            "gi:**n** - *not applying gitignore rules*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_git_file_info => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_git_file_info ^= true;
                        if o.show_git_file_info {
                            "*displaying git info next to files*"
                        } else {
                            "*removing git file info*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_git_status => {
                self.with_new_options(
                    screen, &|o| {
                        if o.filter_by_git_status {
                            o.filter_by_git_status = false;
                            "*not filtering according to git status anymore*"
                        } else {
                            o.filter_by_git_status = true;
                            o.show_hidden = true;
                            "*only displaying new or modified files*"
                        }
                    }, bang, con
                )
            }
            Internal::toggle_perm => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_permissions ^= true;
                        if o.show_permissions {
                            "*displaying file permissions*"
                        } else {
                            "*removing file permissions*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_sizes => self.with_new_options(
                screen,
                &|o| {
                    if o.show_sizes {
                        o.show_sizes = false;
                        o.show_root_fs = false;
                        "*removing sizes of files and directories*"
                    } else {
                        o.show_sizes = true;
                        o.show_root_fs = true;
                        "*now diplaying sizes of files and directories*"
                    }
                },
                bang,
                con,
            ),
            Internal::toggle_trim_root => {
                self.with_new_options(
					screen,
					&|o| {
						o.trim_root ^= true;
                        if o.trim_root {
                            "*now trimming root from excess files*"
                        } else {
                            "*not trimming root files anymore*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::close_preview => {
                if let Some(id) = cc.app.preview_panel {
                    CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(id),
                    }
                } else {
                    CmdResult::Keep
                }
            }
            Internal::panel_left | Internal::panel_left_no_open => {
                CmdResult::HandleInApp(Internal::panel_left_no_open)
            }
            Internal::panel_right | Internal::panel_right_no_open => {
                CmdResult::HandleInApp(Internal::panel_right_no_open)
            }
            Internal::toggle_second_tree => {
                CmdResult::HandleInApp(Internal::toggle_second_tree)
            }
            Internal::clear_stage => {
                app_state.stage.clear();
                if let Some(panel_id) = cc.app.stage_panel {
                    CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(panel_id),
                    }
                } else {
                    CmdResult::Keep
                }
            }
            Internal::stage => self.stage(app_state, cc, con),
            Internal::unstage => self.unstage(app_state, cc, con),
            Internal::toggle_stage => self.toggle_stage(app_state, cc, con),
            Internal::close_staging_area => {
                if let Some(id) = cc.app.stage_panel {
                    CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(id),
                    }
                } else {
                    CmdResult::Keep
                }
            }
            Internal::open_staging_area => {
                if cc.app.stage_panel.is_none() {
                    CmdResult::NewPanel {
                        state: Box::new(StageState::new(app_state, self.tree_options(), con)),
                        purpose: PanelPurpose::None,
                        direction: HDir::Right,
                    }
                } else {
                    CmdResult::Keep
                }
            }
            Internal::toggle_staging_area => {
                if let Some(id) = cc.app.stage_panel {
                    CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(id),
                    }
                } else {
                    CmdResult::NewPanel {
                        state: Box::new(StageState::new(app_state, self.tree_options(), con)),
                        purpose: PanelPurpose::None,
                        direction: HDir::Right,
                    }
                }
            }
            Internal::set_syntax_theme => CmdResult::HandleInApp(Internal::set_syntax_theme),
            Internal::print_path => print::print_paths(self.sel_info(app_state), con)?,
            Internal::print_relative_path => print::print_relative_paths(self.sel_info(app_state), con)?,
            Internal::refresh => CmdResult::RefreshState { clear_cache: true },
            Internal::quit => CmdResult::Quit,
            _ => CmdResult::Keep,
        })
    }

    fn stage(
        &self,
        app_state: &mut AppState,
        cc: &CmdContext,
        con: &AppContext,
    ) -> CmdResult {
        if let Some(path) = self.selected_path() {
            let path = path.to_path_buf();
            app_state.stage.add(path);
            if cc.app.stage_panel.is_none() {
                return CmdResult::NewPanel {
                    state: Box::new(StageState::new(app_state, self.tree_options(), con)),
                    purpose: PanelPurpose::None,
                    direction: HDir::Right,
                };
            }
        } else {
            // TODO display error ?
            warn!("no path in state");
        }
        CmdResult::Keep
    }

    fn unstage(
        &self,
        app_state: &mut AppState,
        cc: &CmdContext,
        _con: &AppContext,
    ) -> CmdResult {
        if let Some(path) = self.selected_path() {
            if app_state.stage.remove(path) && app_state.stage.is_empty() {
                if let Some(panel_id) = cc.app.stage_panel {
                    return CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(panel_id),
                    };
                }
            }
        }
        CmdResult::Keep
    }

    fn toggle_stage(
        &self,
        app_state: &mut AppState,
        cc: &CmdContext,
        con: &AppContext,
    ) -> CmdResult {
        if let Some(path) = self.selected_path() {
            if app_state.stage.contains(path) {
                self.unstage(app_state, cc, con)
            } else {
                self.stage(app_state, cc, con)
            }
        } else {
            CmdResult::error("no selection")
        }
    }
Examples found in repository?
src/app/panel_state.rs (line 514)
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
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
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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
    fn on_internal_generic(
        &mut self,
        _w: &mut W,
        internal_exec: &InternalExecution,
        input_invocation: Option<&VerbInvocation>,
        _trigger_type: TriggerType,
        app_state: &mut AppState,
        cc: &CmdContext,
    ) -> Result<CmdResult, ProgramError> {
        let con = &cc.app.con;
        let screen = cc.app.screen;
        let bang = input_invocation
            .map(|inv| inv.bang)
            .unwrap_or(internal_exec.bang);
        Ok(match internal_exec.internal {
            Internal::back => CmdResult::PopState,
            Internal::copy_line | Internal::copy_path => {
                #[cfg(not(feature = "clipboard"))]
                {
                    CmdResult::error("Clipboard feature not enabled at compilation")
                }
                #[cfg(feature = "clipboard")]
                {
                    if let Some(path) = self.selected_path() {
                        let path = path.to_string_lossy().to_string();
                        match terminal_clipboard::set_string(path) {
                            Ok(()) => CmdResult::Keep,
                            Err(_) => CmdResult::error("Clipboard error while copying path"),
                        }
                    } else {
                        CmdResult::error("Nothing to copy")
                    }
                }
            }
            Internal::close_panel_ok => CmdResult::ClosePanel {
                validate_purpose: true,
                panel_ref: PanelReference::Active,
            },
            Internal::close_panel_cancel => CmdResult::ClosePanel {
                validate_purpose: false,
                panel_ref: PanelReference::Active,
            },
            #[cfg(unix)]
            Internal::filesystems => {
                let fs_state = crate::filesystems::FilesystemState::new(
                    self.selected_path(),
                    self.tree_options(),
                    con,
                );
                match fs_state {
                    Ok(state) => {
                        let bang = input_invocation
                            .map(|inv| inv.bang)
                            .unwrap_or(internal_exec.bang);
                        if bang && cc.app.preview_panel.is_none() {
                            CmdResult::NewPanel {
                                state: Box::new(state),
                                purpose: PanelPurpose::None,
                                direction: HDir::Right,
                            }
                        } else {
                            CmdResult::new_state(Box::new(state))
                        }
                    }
                    Err(e) => CmdResult::DisplayError(format!("{}", e)),
                }
            }
            Internal::help => {
                let bang = input_invocation
                    .map(|inv| inv.bang)
                    .unwrap_or(internal_exec.bang);
                if bang && cc.app.preview_panel.is_none() {
                    CmdResult::NewPanel {
                        state: Box::new(HelpState::new(self.tree_options(), screen, con)),
                        purpose: PanelPurpose::None,
                        direction: HDir::Right,
                    }
                } else {
                    CmdResult::new_state(Box::new(
                            HelpState::new(self.tree_options(), screen, con)
                    ))
                }
            }
            Internal::mode_input => self.on_mode_verb(Mode::Input, con),
            Internal::mode_command => self.on_mode_verb(Mode::Command, con),
            Internal::open_leave => {
                if let Some(selection) = self.selection() {
                    selection.to_opener(con)?
                } else {
                    CmdResult::error("no selection to open")
                }
            }
            Internal::open_preview => self.open_preview(None, false, cc),
            Internal::preview_image => self.open_preview(Some(PreviewMode::Image), false, cc),
            Internal::preview_text => self.open_preview(Some(PreviewMode::Text), false, cc),
            Internal::preview_binary => self.open_preview(Some(PreviewMode::Hex), false, cc),
            Internal::toggle_preview => self.open_preview(None, true, cc),
            Internal::sort_by_count => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::Count {
                        o.sort = Sort::None;
                        o.show_counts = false;
                        "*not sorting anymore*"
                    } else {
                        o.sort = Sort::Count;
                        o.show_counts = true;
                        "*now sorting by file count*"
                    }
                },
                bang,
                con,
            ),
            Internal::sort_by_date => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::Date {
                        o.sort = Sort::None;
                        o.show_dates = false;
                        "*not sorting anymore*"
                    } else {
                        o.sort = Sort::Date;
                        o.show_dates = true;
                        "*now sorting by last modified date*"
                    }
                },
                bang,
                con,
            ),
            Internal::sort_by_size => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::Size {
                        o.sort = Sort::None;
                        o.show_sizes = false;
                        "*not sorting anymore*"
                    } else {
                        o.sort = Sort::Size;
                        o.show_sizes = true;
                        o.show_root_fs = true;
                        "*now sorting files and directories by total size*"
                    }
                },
                bang,
                con,
            ),
            Internal::sort_by_type => self.with_new_options(
                screen,
                &|o| {
                    match o.sort {
                        Sort::TypeDirsFirst => {
                           o.sort = Sort::TypeDirsLast;
                           "*sorting by type, directories last*"
                        }
                        Sort::TypeDirsLast => {
                            o.sort = Sort::None;
                            "*not sorting anymore*"
                        }
                        _ => {
                            o.sort = Sort::TypeDirsFirst;
                           "*sorting by type, directories first*"
                        }
                    }
                },
                bang,
                con,
            ),
            Internal::sort_by_type_dirs_first => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::TypeDirsFirst {
                        o.sort = Sort::None;
                        "*not sorting anymore*"
                    } else {
                        o.sort = Sort::TypeDirsFirst;
                        "*now sorting by type, directories first*"
                    }
                },
                bang,
                con,
            ),
            Internal::sort_by_type_dirs_last => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::TypeDirsLast {
                        o.sort = Sort::None;
                        "*not sorting anymore*"
                    } else {
                        o.sort = Sort::TypeDirsLast;
                        "*now sorting by type, directories last*"
                    }
                },
                bang,
                con,
            ),
            Internal::no_sort => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::None {
                        "*still not searching*"
                    } else {
                        o.sort = Sort::None;
                        "*not sorting anymore*"
                    }
                },
                bang,
                con,
            ),
            Internal::toggle_counts => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_counts ^= true;
                        if o.show_counts {
                            "*displaying file counts*"
                        } else {
                            "*hiding file counts*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_dates => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_dates ^= true;
                        if o.show_dates {
                            "*displaying last modified dates*"
                        } else {
                            "*hiding last modified dates*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_device_id => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_device_id ^= true;
                        if o.show_device_id {
                            "*displaying device id*"
                        } else {
                            "*hiding device id*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_files => {
                self.with_new_options(
					screen,
					&|o| {
                        o.only_folders ^= true;
                        if o.only_folders {
                            "*displaying only directories*"
                        } else {
                            "*displaying both files and directories*"
                        }
                    },
					bang,
					con,
				)
            }
            Internal::toggle_hidden => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_hidden ^= true;
                        if o.show_hidden {
                            "h:**y** - *Hidden files displayed*"
                        } else {
                            "h:**n** - *Hidden files not displayed*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_root_fs => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_root_fs ^= true;
                        if o.show_root_fs {
                            "*displaying filesystem info for the tree's root directory*"
                        } else {
                            "*removing filesystem info*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_git_ignore => {
                self.with_new_options(
					screen,
					&|o| {
						o.respect_git_ignore ^= true;
                        if o.respect_git_ignore {
                            "gi:**y** - *applying gitignore rules*"
                        } else {
                            "gi:**n** - *not applying gitignore rules*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_git_file_info => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_git_file_info ^= true;
                        if o.show_git_file_info {
                            "*displaying git info next to files*"
                        } else {
                            "*removing git file info*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_git_status => {
                self.with_new_options(
                    screen, &|o| {
                        if o.filter_by_git_status {
                            o.filter_by_git_status = false;
                            "*not filtering according to git status anymore*"
                        } else {
                            o.filter_by_git_status = true;
                            o.show_hidden = true;
                            "*only displaying new or modified files*"
                        }
                    }, bang, con
                )
            }
            Internal::toggle_perm => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_permissions ^= true;
                        if o.show_permissions {
                            "*displaying file permissions*"
                        } else {
                            "*removing file permissions*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_sizes => self.with_new_options(
                screen,
                &|o| {
                    if o.show_sizes {
                        o.show_sizes = false;
                        o.show_root_fs = false;
                        "*removing sizes of files and directories*"
                    } else {
                        o.show_sizes = true;
                        o.show_root_fs = true;
                        "*now diplaying sizes of files and directories*"
                    }
                },
                bang,
                con,
            ),
            Internal::toggle_trim_root => {
                self.with_new_options(
					screen,
					&|o| {
						o.trim_root ^= true;
                        if o.trim_root {
                            "*now trimming root from excess files*"
                        } else {
                            "*not trimming root files anymore*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::close_preview => {
                if let Some(id) = cc.app.preview_panel {
                    CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(id),
                    }
                } else {
                    CmdResult::Keep
                }
            }
            Internal::panel_left | Internal::panel_left_no_open => {
                CmdResult::HandleInApp(Internal::panel_left_no_open)
            }
            Internal::panel_right | Internal::panel_right_no_open => {
                CmdResult::HandleInApp(Internal::panel_right_no_open)
            }
            Internal::toggle_second_tree => {
                CmdResult::HandleInApp(Internal::toggle_second_tree)
            }
            Internal::clear_stage => {
                app_state.stage.clear();
                if let Some(panel_id) = cc.app.stage_panel {
                    CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(panel_id),
                    }
                } else {
                    CmdResult::Keep
                }
            }
            Internal::stage => self.stage(app_state, cc, con),
            Internal::unstage => self.unstage(app_state, cc, con),
            Internal::toggle_stage => self.toggle_stage(app_state, cc, con),
            Internal::close_staging_area => {
                if let Some(id) = cc.app.stage_panel {
                    CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(id),
                    }
                } else {
                    CmdResult::Keep
                }
            }
            Internal::open_staging_area => {
                if cc.app.stage_panel.is_none() {
                    CmdResult::NewPanel {
                        state: Box::new(StageState::new(app_state, self.tree_options(), con)),
                        purpose: PanelPurpose::None,
                        direction: HDir::Right,
                    }
                } else {
                    CmdResult::Keep
                }
            }
            Internal::toggle_staging_area => {
                if let Some(id) = cc.app.stage_panel {
                    CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(id),
                    }
                } else {
                    CmdResult::NewPanel {
                        state: Box::new(StageState::new(app_state, self.tree_options(), con)),
                        purpose: PanelPurpose::None,
                        direction: HDir::Right,
                    }
                }
            }
            Internal::set_syntax_theme => CmdResult::HandleInApp(Internal::set_syntax_theme),
            Internal::print_path => print::print_paths(self.sel_info(app_state), con)?,
            Internal::print_relative_path => print::print_relative_paths(self.sel_info(app_state), con)?,
            Internal::refresh => CmdResult::RefreshState { clear_cache: true },
            Internal::quit => CmdResult::Quit,
            _ => CmdResult::Keep,
        })
    }

    fn stage(
        &self,
        app_state: &mut AppState,
        cc: &CmdContext,
        con: &AppContext,
    ) -> CmdResult {
        if let Some(path) = self.selected_path() {
            let path = path.to_path_buf();
            app_state.stage.add(path);
            if cc.app.stage_panel.is_none() {
                return CmdResult::NewPanel {
                    state: Box::new(StageState::new(app_state, self.tree_options(), con)),
                    purpose: PanelPurpose::None,
                    direction: HDir::Right,
                };
            }
        } else {
            // TODO display error ?
            warn!("no path in state");
        }
        CmdResult::Keep
    }

    fn unstage(
        &self,
        app_state: &mut AppState,
        cc: &CmdContext,
        _con: &AppContext,
    ) -> CmdResult {
        if let Some(path) = self.selected_path() {
            if app_state.stage.remove(path) && app_state.stage.is_empty() {
                if let Some(panel_id) = cc.app.stage_panel {
                    return CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(panel_id),
                    };
                }
            }
        }
        CmdResult::Keep
    }

    fn toggle_stage(
        &self,
        app_state: &mut AppState,
        cc: &CmdContext,
        con: &AppContext,
    ) -> CmdResult {
        if let Some(path) = self.selected_path() {
            if app_state.stage.contains(path) {
                self.unstage(app_state, cc, con)
            } else {
                self.stage(app_state, cc, con)
            }
        } else {
            CmdResult::error("no selection")
        }
    }
Examples found in repository?
src/app/panel_state.rs (line 515)
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
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
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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
    fn on_internal_generic(
        &mut self,
        _w: &mut W,
        internal_exec: &InternalExecution,
        input_invocation: Option<&VerbInvocation>,
        _trigger_type: TriggerType,
        app_state: &mut AppState,
        cc: &CmdContext,
    ) -> Result<CmdResult, ProgramError> {
        let con = &cc.app.con;
        let screen = cc.app.screen;
        let bang = input_invocation
            .map(|inv| inv.bang)
            .unwrap_or(internal_exec.bang);
        Ok(match internal_exec.internal {
            Internal::back => CmdResult::PopState,
            Internal::copy_line | Internal::copy_path => {
                #[cfg(not(feature = "clipboard"))]
                {
                    CmdResult::error("Clipboard feature not enabled at compilation")
                }
                #[cfg(feature = "clipboard")]
                {
                    if let Some(path) = self.selected_path() {
                        let path = path.to_string_lossy().to_string();
                        match terminal_clipboard::set_string(path) {
                            Ok(()) => CmdResult::Keep,
                            Err(_) => CmdResult::error("Clipboard error while copying path"),
                        }
                    } else {
                        CmdResult::error("Nothing to copy")
                    }
                }
            }
            Internal::close_panel_ok => CmdResult::ClosePanel {
                validate_purpose: true,
                panel_ref: PanelReference::Active,
            },
            Internal::close_panel_cancel => CmdResult::ClosePanel {
                validate_purpose: false,
                panel_ref: PanelReference::Active,
            },
            #[cfg(unix)]
            Internal::filesystems => {
                let fs_state = crate::filesystems::FilesystemState::new(
                    self.selected_path(),
                    self.tree_options(),
                    con,
                );
                match fs_state {
                    Ok(state) => {
                        let bang = input_invocation
                            .map(|inv| inv.bang)
                            .unwrap_or(internal_exec.bang);
                        if bang && cc.app.preview_panel.is_none() {
                            CmdResult::NewPanel {
                                state: Box::new(state),
                                purpose: PanelPurpose::None,
                                direction: HDir::Right,
                            }
                        } else {
                            CmdResult::new_state(Box::new(state))
                        }
                    }
                    Err(e) => CmdResult::DisplayError(format!("{}", e)),
                }
            }
            Internal::help => {
                let bang = input_invocation
                    .map(|inv| inv.bang)
                    .unwrap_or(internal_exec.bang);
                if bang && cc.app.preview_panel.is_none() {
                    CmdResult::NewPanel {
                        state: Box::new(HelpState::new(self.tree_options(), screen, con)),
                        purpose: PanelPurpose::None,
                        direction: HDir::Right,
                    }
                } else {
                    CmdResult::new_state(Box::new(
                            HelpState::new(self.tree_options(), screen, con)
                    ))
                }
            }
            Internal::mode_input => self.on_mode_verb(Mode::Input, con),
            Internal::mode_command => self.on_mode_verb(Mode::Command, con),
            Internal::open_leave => {
                if let Some(selection) = self.selection() {
                    selection.to_opener(con)?
                } else {
                    CmdResult::error("no selection to open")
                }
            }
            Internal::open_preview => self.open_preview(None, false, cc),
            Internal::preview_image => self.open_preview(Some(PreviewMode::Image), false, cc),
            Internal::preview_text => self.open_preview(Some(PreviewMode::Text), false, cc),
            Internal::preview_binary => self.open_preview(Some(PreviewMode::Hex), false, cc),
            Internal::toggle_preview => self.open_preview(None, true, cc),
            Internal::sort_by_count => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::Count {
                        o.sort = Sort::None;
                        o.show_counts = false;
                        "*not sorting anymore*"
                    } else {
                        o.sort = Sort::Count;
                        o.show_counts = true;
                        "*now sorting by file count*"
                    }
                },
                bang,
                con,
            ),
            Internal::sort_by_date => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::Date {
                        o.sort = Sort::None;
                        o.show_dates = false;
                        "*not sorting anymore*"
                    } else {
                        o.sort = Sort::Date;
                        o.show_dates = true;
                        "*now sorting by last modified date*"
                    }
                },
                bang,
                con,
            ),
            Internal::sort_by_size => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::Size {
                        o.sort = Sort::None;
                        o.show_sizes = false;
                        "*not sorting anymore*"
                    } else {
                        o.sort = Sort::Size;
                        o.show_sizes = true;
                        o.show_root_fs = true;
                        "*now sorting files and directories by total size*"
                    }
                },
                bang,
                con,
            ),
            Internal::sort_by_type => self.with_new_options(
                screen,
                &|o| {
                    match o.sort {
                        Sort::TypeDirsFirst => {
                           o.sort = Sort::TypeDirsLast;
                           "*sorting by type, directories last*"
                        }
                        Sort::TypeDirsLast => {
                            o.sort = Sort::None;
                            "*not sorting anymore*"
                        }
                        _ => {
                            o.sort = Sort::TypeDirsFirst;
                           "*sorting by type, directories first*"
                        }
                    }
                },
                bang,
                con,
            ),
            Internal::sort_by_type_dirs_first => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::TypeDirsFirst {
                        o.sort = Sort::None;
                        "*not sorting anymore*"
                    } else {
                        o.sort = Sort::TypeDirsFirst;
                        "*now sorting by type, directories first*"
                    }
                },
                bang,
                con,
            ),
            Internal::sort_by_type_dirs_last => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::TypeDirsLast {
                        o.sort = Sort::None;
                        "*not sorting anymore*"
                    } else {
                        o.sort = Sort::TypeDirsLast;
                        "*now sorting by type, directories last*"
                    }
                },
                bang,
                con,
            ),
            Internal::no_sort => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::None {
                        "*still not searching*"
                    } else {
                        o.sort = Sort::None;
                        "*not sorting anymore*"
                    }
                },
                bang,
                con,
            ),
            Internal::toggle_counts => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_counts ^= true;
                        if o.show_counts {
                            "*displaying file counts*"
                        } else {
                            "*hiding file counts*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_dates => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_dates ^= true;
                        if o.show_dates {
                            "*displaying last modified dates*"
                        } else {
                            "*hiding last modified dates*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_device_id => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_device_id ^= true;
                        if o.show_device_id {
                            "*displaying device id*"
                        } else {
                            "*hiding device id*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_files => {
                self.with_new_options(
					screen,
					&|o| {
                        o.only_folders ^= true;
                        if o.only_folders {
                            "*displaying only directories*"
                        } else {
                            "*displaying both files and directories*"
                        }
                    },
					bang,
					con,
				)
            }
            Internal::toggle_hidden => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_hidden ^= true;
                        if o.show_hidden {
                            "h:**y** - *Hidden files displayed*"
                        } else {
                            "h:**n** - *Hidden files not displayed*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_root_fs => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_root_fs ^= true;
                        if o.show_root_fs {
                            "*displaying filesystem info for the tree's root directory*"
                        } else {
                            "*removing filesystem info*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_git_ignore => {
                self.with_new_options(
					screen,
					&|o| {
						o.respect_git_ignore ^= true;
                        if o.respect_git_ignore {
                            "gi:**y** - *applying gitignore rules*"
                        } else {
                            "gi:**n** - *not applying gitignore rules*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_git_file_info => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_git_file_info ^= true;
                        if o.show_git_file_info {
                            "*displaying git info next to files*"
                        } else {
                            "*removing git file info*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_git_status => {
                self.with_new_options(
                    screen, &|o| {
                        if o.filter_by_git_status {
                            o.filter_by_git_status = false;
                            "*not filtering according to git status anymore*"
                        } else {
                            o.filter_by_git_status = true;
                            o.show_hidden = true;
                            "*only displaying new or modified files*"
                        }
                    }, bang, con
                )
            }
            Internal::toggle_perm => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_permissions ^= true;
                        if o.show_permissions {
                            "*displaying file permissions*"
                        } else {
                            "*removing file permissions*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_sizes => self.with_new_options(
                screen,
                &|o| {
                    if o.show_sizes {
                        o.show_sizes = false;
                        o.show_root_fs = false;
                        "*removing sizes of files and directories*"
                    } else {
                        o.show_sizes = true;
                        o.show_root_fs = true;
                        "*now diplaying sizes of files and directories*"
                    }
                },
                bang,
                con,
            ),
            Internal::toggle_trim_root => {
                self.with_new_options(
					screen,
					&|o| {
						o.trim_root ^= true;
                        if o.trim_root {
                            "*now trimming root from excess files*"
                        } else {
                            "*not trimming root files anymore*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::close_preview => {
                if let Some(id) = cc.app.preview_panel {
                    CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(id),
                    }
                } else {
                    CmdResult::Keep
                }
            }
            Internal::panel_left | Internal::panel_left_no_open => {
                CmdResult::HandleInApp(Internal::panel_left_no_open)
            }
            Internal::panel_right | Internal::panel_right_no_open => {
                CmdResult::HandleInApp(Internal::panel_right_no_open)
            }
            Internal::toggle_second_tree => {
                CmdResult::HandleInApp(Internal::toggle_second_tree)
            }
            Internal::clear_stage => {
                app_state.stage.clear();
                if let Some(panel_id) = cc.app.stage_panel {
                    CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(panel_id),
                    }
                } else {
                    CmdResult::Keep
                }
            }
            Internal::stage => self.stage(app_state, cc, con),
            Internal::unstage => self.unstage(app_state, cc, con),
            Internal::toggle_stage => self.toggle_stage(app_state, cc, con),
            Internal::close_staging_area => {
                if let Some(id) = cc.app.stage_panel {
                    CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(id),
                    }
                } else {
                    CmdResult::Keep
                }
            }
            Internal::open_staging_area => {
                if cc.app.stage_panel.is_none() {
                    CmdResult::NewPanel {
                        state: Box::new(StageState::new(app_state, self.tree_options(), con)),
                        purpose: PanelPurpose::None,
                        direction: HDir::Right,
                    }
                } else {
                    CmdResult::Keep
                }
            }
            Internal::toggle_staging_area => {
                if let Some(id) = cc.app.stage_panel {
                    CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(id),
                    }
                } else {
                    CmdResult::NewPanel {
                        state: Box::new(StageState::new(app_state, self.tree_options(), con)),
                        purpose: PanelPurpose::None,
                        direction: HDir::Right,
                    }
                }
            }
            Internal::set_syntax_theme => CmdResult::HandleInApp(Internal::set_syntax_theme),
            Internal::print_path => print::print_paths(self.sel_info(app_state), con)?,
            Internal::print_relative_path => print::print_relative_paths(self.sel_info(app_state), con)?,
            Internal::refresh => CmdResult::RefreshState { clear_cache: true },
            Internal::quit => CmdResult::Quit,
            _ => CmdResult::Keep,
        })
    }
Examples found in repository?
src/app/panel_state.rs (lines 754-761)
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
    fn on_command(
        &mut self,
        w: &mut W,
        app_state: &mut AppState,
        cc: &CmdContext,
    ) -> Result<CmdResult, ProgramError> {
        self.clear_pending();
        let con = &cc.app.con;
        let screen = cc.app.screen;
        match &cc.cmd {
            Command::Click(x, y) => self.on_click(*x, *y, screen, con),
            Command::DoubleClick(x, y) => self.on_double_click(*x, *y, screen, con),
            Command::PatternEdit { raw, expr } => {
                match InputPattern::new(raw.clone(), expr, con) {
                    Ok(pattern) => self.on_pattern(pattern, app_state, con),
                    Err(e) => Ok(CmdResult::DisplayError(format!("{}", e))),
                }
            }
            Command::VerbTrigger {
                index,
                input_invocation,
            } => self.execute_verb(
                w,
                &con.verb_store.verbs[*index],
                input_invocation.as_ref(),
                TriggerType::Other,
                app_state,
                cc,
            ),
            Command::Internal {
                internal,
                input_invocation,
            } => self.on_internal(
                w,
                &InternalExecution::from_internal(*internal),
                input_invocation.as_ref(),
                TriggerType::Other,
                app_state,
                cc,
            ),
            Command::VerbInvocate(invocation) => {
                let sel_info = self.sel_info(app_state);
                match con.verb_store.search_sel_info(
                    &invocation.name,
                    sel_info,
                ) {
                    PrefixSearchResult::Match(_, verb) => {
                        self.execute_verb(
                            w,
                            verb,
                            Some(invocation),
                            TriggerType::Input(verb),
                            app_state,
                            cc,
                        )
                    }
                    _ => Ok(CmdResult::verb_not_found(&invocation.name)),
                }
            }
            Command::None | Command::VerbEdit(_) => {
                // we do nothing here, the real job is done in get_status
                Ok(CmdResult::Keep)
            }
        }
    }
Examples found in repository?
src/app/panel_state.rs (line 646)
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
    fn execute_verb(
        &mut self,
        w: &mut W, // needed because we may want to switch from alternate in some externals
        verb: &Verb,
        invocation: Option<&VerbInvocation>,
        trigger_type: TriggerType,
        app_state: &mut AppState,
        cc: &CmdContext,
    ) -> Result<CmdResult, ProgramError> {
        if verb.needs_selection && !self.has_at_least_one_selection(app_state) {
            return Ok(CmdResult::error("This verb needs a selection"));
        }
        if verb.needs_another_panel && app_state.other_panel_path.is_none() {
            return Ok(CmdResult::error("This verb needs another panel"));
        }
        let res = match &verb.execution {
            VerbExecution::Internal(internal_exec) => {
                self.on_internal(
                    w,
                    internal_exec,
                    invocation,
                    trigger_type,
                    app_state,
                    cc,
                )
            }
            VerbExecution::External(external) => {
                self.execute_external(w, verb, external, invocation, app_state, cc)
            }
            VerbExecution::Sequence(seq_ex) => {
                self.execute_sequence(w, verb, seq_ex, invocation, app_state, cc)
            }
        };
        if res.is_ok() {
            // if the stage has been emptied by the operation (eg a "rm"), we
            // close it
            app_state.stage.refresh();
            if app_state.stage.is_empty() {
                if let Some(id) = cc.app.stage_panel {
                    return Ok(CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(id),
                    });
                }
            }
        }
        res
    }
Examples found in repository?
src/app/panel_state.rs (line 649)
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
    fn execute_verb(
        &mut self,
        w: &mut W, // needed because we may want to switch from alternate in some externals
        verb: &Verb,
        invocation: Option<&VerbInvocation>,
        trigger_type: TriggerType,
        app_state: &mut AppState,
        cc: &CmdContext,
    ) -> Result<CmdResult, ProgramError> {
        if verb.needs_selection && !self.has_at_least_one_selection(app_state) {
            return Ok(CmdResult::error("This verb needs a selection"));
        }
        if verb.needs_another_panel && app_state.other_panel_path.is_none() {
            return Ok(CmdResult::error("This verb needs another panel"));
        }
        let res = match &verb.execution {
            VerbExecution::Internal(internal_exec) => {
                self.on_internal(
                    w,
                    internal_exec,
                    invocation,
                    trigger_type,
                    app_state,
                    cc,
                )
            }
            VerbExecution::External(external) => {
                self.execute_external(w, verb, external, invocation, app_state, cc)
            }
            VerbExecution::Sequence(seq_ex) => {
                self.execute_sequence(w, verb, seq_ex, invocation, app_state, cc)
            }
        };
        if res.is_ok() {
            // if the stage has been emptied by the operation (eg a "rm"), we
            // close it
            app_state.stage.refresh();
            if app_state.stage.is_empty() {
                if let Some(id) = cc.app.stage_panel {
                    return Ok(CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(id),
                    });
                }
            }
        }
        res
    }

change the state, does no rendering

Examples found in repository?
src/app/panel.rs (line 83)
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
    pub fn apply_command<'c>(
        &mut self,
        w: &'c mut W,
        cmd: &'c Command,
        app_state: &mut AppState,
        app_cmd_context: &'c AppCmdContext<'c>,
    ) -> Result<CmdResult, ProgramError> {
        let state_idx = self.states.len() - 1;
        let cc = CmdContext {
            cmd,
            app: app_cmd_context,
            panel: PanelCmdContext {
                areas: &self.areas,
                purpose: self.purpose,
            },
        };
        let result = self.states[state_idx].on_command(w, app_state, &cc);
        let has_previous_state = self.states.len() > 1;
        self.status = self.state().get_status(app_state, &cc, has_previous_state);
        result
    }

return a cmdresult asking for the opening of a preview

Examples found in repository?
src/app/panel_state.rs (line 187)
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
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
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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
    fn on_internal_generic(
        &mut self,
        _w: &mut W,
        internal_exec: &InternalExecution,
        input_invocation: Option<&VerbInvocation>,
        _trigger_type: TriggerType,
        app_state: &mut AppState,
        cc: &CmdContext,
    ) -> Result<CmdResult, ProgramError> {
        let con = &cc.app.con;
        let screen = cc.app.screen;
        let bang = input_invocation
            .map(|inv| inv.bang)
            .unwrap_or(internal_exec.bang);
        Ok(match internal_exec.internal {
            Internal::back => CmdResult::PopState,
            Internal::copy_line | Internal::copy_path => {
                #[cfg(not(feature = "clipboard"))]
                {
                    CmdResult::error("Clipboard feature not enabled at compilation")
                }
                #[cfg(feature = "clipboard")]
                {
                    if let Some(path) = self.selected_path() {
                        let path = path.to_string_lossy().to_string();
                        match terminal_clipboard::set_string(path) {
                            Ok(()) => CmdResult::Keep,
                            Err(_) => CmdResult::error("Clipboard error while copying path"),
                        }
                    } else {
                        CmdResult::error("Nothing to copy")
                    }
                }
            }
            Internal::close_panel_ok => CmdResult::ClosePanel {
                validate_purpose: true,
                panel_ref: PanelReference::Active,
            },
            Internal::close_panel_cancel => CmdResult::ClosePanel {
                validate_purpose: false,
                panel_ref: PanelReference::Active,
            },
            #[cfg(unix)]
            Internal::filesystems => {
                let fs_state = crate::filesystems::FilesystemState::new(
                    self.selected_path(),
                    self.tree_options(),
                    con,
                );
                match fs_state {
                    Ok(state) => {
                        let bang = input_invocation
                            .map(|inv| inv.bang)
                            .unwrap_or(internal_exec.bang);
                        if bang && cc.app.preview_panel.is_none() {
                            CmdResult::NewPanel {
                                state: Box::new(state),
                                purpose: PanelPurpose::None,
                                direction: HDir::Right,
                            }
                        } else {
                            CmdResult::new_state(Box::new(state))
                        }
                    }
                    Err(e) => CmdResult::DisplayError(format!("{}", e)),
                }
            }
            Internal::help => {
                let bang = input_invocation
                    .map(|inv| inv.bang)
                    .unwrap_or(internal_exec.bang);
                if bang && cc.app.preview_panel.is_none() {
                    CmdResult::NewPanel {
                        state: Box::new(HelpState::new(self.tree_options(), screen, con)),
                        purpose: PanelPurpose::None,
                        direction: HDir::Right,
                    }
                } else {
                    CmdResult::new_state(Box::new(
                            HelpState::new(self.tree_options(), screen, con)
                    ))
                }
            }
            Internal::mode_input => self.on_mode_verb(Mode::Input, con),
            Internal::mode_command => self.on_mode_verb(Mode::Command, con),
            Internal::open_leave => {
                if let Some(selection) = self.selection() {
                    selection.to_opener(con)?
                } else {
                    CmdResult::error("no selection to open")
                }
            }
            Internal::open_preview => self.open_preview(None, false, cc),
            Internal::preview_image => self.open_preview(Some(PreviewMode::Image), false, cc),
            Internal::preview_text => self.open_preview(Some(PreviewMode::Text), false, cc),
            Internal::preview_binary => self.open_preview(Some(PreviewMode::Hex), false, cc),
            Internal::toggle_preview => self.open_preview(None, true, cc),
            Internal::sort_by_count => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::Count {
                        o.sort = Sort::None;
                        o.show_counts = false;
                        "*not sorting anymore*"
                    } else {
                        o.sort = Sort::Count;
                        o.show_counts = true;
                        "*now sorting by file count*"
                    }
                },
                bang,
                con,
            ),
            Internal::sort_by_date => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::Date {
                        o.sort = Sort::None;
                        o.show_dates = false;
                        "*not sorting anymore*"
                    } else {
                        o.sort = Sort::Date;
                        o.show_dates = true;
                        "*now sorting by last modified date*"
                    }
                },
                bang,
                con,
            ),
            Internal::sort_by_size => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::Size {
                        o.sort = Sort::None;
                        o.show_sizes = false;
                        "*not sorting anymore*"
                    } else {
                        o.sort = Sort::Size;
                        o.show_sizes = true;
                        o.show_root_fs = true;
                        "*now sorting files and directories by total size*"
                    }
                },
                bang,
                con,
            ),
            Internal::sort_by_type => self.with_new_options(
                screen,
                &|o| {
                    match o.sort {
                        Sort::TypeDirsFirst => {
                           o.sort = Sort::TypeDirsLast;
                           "*sorting by type, directories last*"
                        }
                        Sort::TypeDirsLast => {
                            o.sort = Sort::None;
                            "*not sorting anymore*"
                        }
                        _ => {
                            o.sort = Sort::TypeDirsFirst;
                           "*sorting by type, directories first*"
                        }
                    }
                },
                bang,
                con,
            ),
            Internal::sort_by_type_dirs_first => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::TypeDirsFirst {
                        o.sort = Sort::None;
                        "*not sorting anymore*"
                    } else {
                        o.sort = Sort::TypeDirsFirst;
                        "*now sorting by type, directories first*"
                    }
                },
                bang,
                con,
            ),
            Internal::sort_by_type_dirs_last => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::TypeDirsLast {
                        o.sort = Sort::None;
                        "*not sorting anymore*"
                    } else {
                        o.sort = Sort::TypeDirsLast;
                        "*now sorting by type, directories last*"
                    }
                },
                bang,
                con,
            ),
            Internal::no_sort => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::None {
                        "*still not searching*"
                    } else {
                        o.sort = Sort::None;
                        "*not sorting anymore*"
                    }
                },
                bang,
                con,
            ),
            Internal::toggle_counts => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_counts ^= true;
                        if o.show_counts {
                            "*displaying file counts*"
                        } else {
                            "*hiding file counts*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_dates => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_dates ^= true;
                        if o.show_dates {
                            "*displaying last modified dates*"
                        } else {
                            "*hiding last modified dates*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_device_id => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_device_id ^= true;
                        if o.show_device_id {
                            "*displaying device id*"
                        } else {
                            "*hiding device id*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_files => {
                self.with_new_options(
					screen,
					&|o| {
                        o.only_folders ^= true;
                        if o.only_folders {
                            "*displaying only directories*"
                        } else {
                            "*displaying both files and directories*"
                        }
                    },
					bang,
					con,
				)
            }
            Internal::toggle_hidden => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_hidden ^= true;
                        if o.show_hidden {
                            "h:**y** - *Hidden files displayed*"
                        } else {
                            "h:**n** - *Hidden files not displayed*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_root_fs => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_root_fs ^= true;
                        if o.show_root_fs {
                            "*displaying filesystem info for the tree's root directory*"
                        } else {
                            "*removing filesystem info*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_git_ignore => {
                self.with_new_options(
					screen,
					&|o| {
						o.respect_git_ignore ^= true;
                        if o.respect_git_ignore {
                            "gi:**y** - *applying gitignore rules*"
                        } else {
                            "gi:**n** - *not applying gitignore rules*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_git_file_info => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_git_file_info ^= true;
                        if o.show_git_file_info {
                            "*displaying git info next to files*"
                        } else {
                            "*removing git file info*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_git_status => {
                self.with_new_options(
                    screen, &|o| {
                        if o.filter_by_git_status {
                            o.filter_by_git_status = false;
                            "*not filtering according to git status anymore*"
                        } else {
                            o.filter_by_git_status = true;
                            o.show_hidden = true;
                            "*only displaying new or modified files*"
                        }
                    }, bang, con
                )
            }
            Internal::toggle_perm => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_permissions ^= true;
                        if o.show_permissions {
                            "*displaying file permissions*"
                        } else {
                            "*removing file permissions*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_sizes => self.with_new_options(
                screen,
                &|o| {
                    if o.show_sizes {
                        o.show_sizes = false;
                        o.show_root_fs = false;
                        "*removing sizes of files and directories*"
                    } else {
                        o.show_sizes = true;
                        o.show_root_fs = true;
                        "*now diplaying sizes of files and directories*"
                    }
                },
                bang,
                con,
            ),
            Internal::toggle_trim_root => {
                self.with_new_options(
					screen,
					&|o| {
						o.trim_root ^= true;
                        if o.trim_root {
                            "*now trimming root from excess files*"
                        } else {
                            "*not trimming root files anymore*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::close_preview => {
                if let Some(id) = cc.app.preview_panel {
                    CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(id),
                    }
                } else {
                    CmdResult::Keep
                }
            }
            Internal::panel_left | Internal::panel_left_no_open => {
                CmdResult::HandleInApp(Internal::panel_left_no_open)
            }
            Internal::panel_right | Internal::panel_right_no_open => {
                CmdResult::HandleInApp(Internal::panel_right_no_open)
            }
            Internal::toggle_second_tree => {
                CmdResult::HandleInApp(Internal::toggle_second_tree)
            }
            Internal::clear_stage => {
                app_state.stage.clear();
                if let Some(panel_id) = cc.app.stage_panel {
                    CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(panel_id),
                    }
                } else {
                    CmdResult::Keep
                }
            }
            Internal::stage => self.stage(app_state, cc, con),
            Internal::unstage => self.unstage(app_state, cc, con),
            Internal::toggle_stage => self.toggle_stage(app_state, cc, con),
            Internal::close_staging_area => {
                if let Some(id) = cc.app.stage_panel {
                    CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(id),
                    }
                } else {
                    CmdResult::Keep
                }
            }
            Internal::open_staging_area => {
                if cc.app.stage_panel.is_none() {
                    CmdResult::NewPanel {
                        state: Box::new(StageState::new(app_state, self.tree_options(), con)),
                        purpose: PanelPurpose::None,
                        direction: HDir::Right,
                    }
                } else {
                    CmdResult::Keep
                }
            }
            Internal::toggle_staging_area => {
                if let Some(id) = cc.app.stage_panel {
                    CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(id),
                    }
                } else {
                    CmdResult::NewPanel {
                        state: Box::new(StageState::new(app_state, self.tree_options(), con)),
                        purpose: PanelPurpose::None,
                        direction: HDir::Right,
                    }
                }
            }
            Internal::set_syntax_theme => CmdResult::HandleInApp(Internal::set_syntax_theme),
            Internal::print_path => print::print_paths(self.sel_info(app_state), con)?,
            Internal::print_relative_path => print::print_relative_paths(self.sel_info(app_state), con)?,
            Internal::refresh => CmdResult::RefreshState { clear_cache: true },
            Internal::quit => CmdResult::Quit,
            _ => CmdResult::Keep,
        })
    }

must return None if the state doesn’t display a file tree

Examples found in repository?
src/app/app.rs (line 523)
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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
    fn apply_command(
        &mut self,
        w: &mut W,
        cmd: Command,
        panel_skin: &PanelSkin,
        app_state: &mut AppState,
        con: &mut AppContext,
    ) -> Result<(), ProgramError> {
        use CmdResult::*;
        let mut error: Option<String> = None;
        let is_input_invocation = cmd.is_verb_invocated_from_input();
        let app_cmd_context = AppCmdContext {
            panel_skin,
            preview_panel: self.preview_panel,
            stage_panel: self.stage_panel,
            screen: self.screen, // it can't change in this function
            con,
        };
        let cmd_result = self.mut_panel().apply_command(w, &cmd, app_state, &app_cmd_context)?;
        debug!("cmd_result: {:?}", &cmd_result);
        match cmd_result {
            ApplyOnPanel { id } => {
                if let Some(idx) = self.panel_id_to_idx(id) {
                    if let DisplayError(txt) = self.panels[idx].apply_command(
                        w, &cmd, app_state, &app_cmd_context
                    )? {
                        // we should probably handle other results
                        // which implies the possibility of a recursion
                        error = Some(txt);
                    } else if is_input_invocation {
                        self.mut_panel().clear_input();
                    }
                } else {
                    warn!("no panel found for ApplyOnPanel");
                }
            }
            ClosePanel { validate_purpose, panel_ref } => {
                if is_input_invocation {
                    self.mut_panel().clear_input_invocation(con);
                }
                let close_idx = self.panel_ref_to_idx(panel_ref)
                    .unwrap_or_else(||
                        // when there's a preview panel, we close it rather than the app
                        if self.panels.len().get()==2 && self.preview_panel.is_some() {
                            1
                        } else {
                            self.active_panel_idx
                        }
                    );
                let mut new_arg = None;
                if validate_purpose {
                    let purpose = &self.panels[close_idx].purpose;
                    if let PanelPurpose::ArgEdition { .. } = purpose {
                        new_arg = self.panels[close_idx]
                            .state()
                            .selected_path()
                            .map(|p| p.to_string_lossy().to_string());
                    }
                }
                if self.close_panel(close_idx) {
                    let screen = self.screen;
                    self.mut_state().refresh(screen, con);
                    if let Some(new_arg) = new_arg {
                        self.mut_panel().set_input_arg(new_arg);
                        let new_input = self.panel().get_input_content();
                        let cmd = Command::from_raw(new_input, false);
                        let app_cmd_context = AppCmdContext {
                            panel_skin,
                            preview_panel: self.preview_panel,
                            stage_panel: self.stage_panel,
                            screen,
                            con,
                        };
                        self.mut_panel().apply_command(w, &cmd, app_state, &app_cmd_context)?;
                    }
                } else {
                    self.quitting = true;
                }
            }
            DisplayError(txt) => {
                error = Some(txt);
            }
            ExecuteSequence { sequence } => {
                self.tx_seqs.send(sequence).unwrap();
            }
            HandleInApp(internal) => {
                debug!("handling internal {internal:?} at app level");
                match internal {
                    Internal::panel_left_no_open | Internal::panel_right_no_open => {
                        let new_active_panel_idx = if internal == Internal::panel_left_no_open {
                            // we're here because the state wants us to either move to the panel
                            // to the left, or close the rightest one
                            if self.active_panel_idx == 0 {
                                self.close_panel(self.panels.len().get()-1);
                                None
                            } else {
                                Some(self.active_panel_idx - 1)
                            }
                        } else { // panel_right
                            // we either move to the right or close the leftest panel
                            if self.active_panel_idx + 1 == self.panels.len().get() {
                                self.close_panel(0);
                                None
                            } else {
                                Some(self.active_panel_idx + 1)
                            }
                        };
                        if let Some(idx) = new_active_panel_idx {
                            if is_input_invocation {
                                self.mut_panel().clear_input();
                            }
                            self.active_panel_idx = idx;
                            let app_cmd_context = AppCmdContext {
                                panel_skin,
                                preview_panel: self.preview_panel,
                                stage_panel: self.stage_panel,
                                screen: self.screen,
                                con,
                            };
                            self.mut_panel().refresh_input_status(app_state, &app_cmd_context);
                        }
                    }
                    Internal::toggle_second_tree => {
                        let panels_count = self.panels.len().get();
                        let trees_count = self.panels.iter()
                            .filter(|p| p.state().get_type() == PanelStateType::Tree)
                            .count();
                        if trees_count < 2 {
                            // we open a tree, closing a (non tree) panel if necessary
                            if panels_count >= con.max_panels_count {
                                for i in (0..panels_count).rev() {
                                    if self.panels[i].state().get_type() != PanelStateType::Tree {
                                        self.close_panel(i);
                                        break;
                                    }
                                }
                            }
                            if let Some(selected_path) = self.state().selected_path() {
                                let dir = closest_dir(selected_path);
                                if let Ok(new_state) = BrowserState::new(
                                    dir,
                                    self.state().tree_options().without_pattern(),
                                    self.screen,
                                    con,
                                    &Dam::unlimited(),
                                ) {
                                    if let Err(s) = self.new_panel(
                                        Box::new(new_state),
                                        PanelPurpose::None,
                                        HDir::Right,
                                        is_input_invocation,
                                        con,
                                    ) {
                                        error = Some(s);
                                    }
                                }
                            }
                        } else {
                            // we close the rightest inactive tree
                            for i in (0..panels_count).rev() {
                                if self.panels[i].state().get_type() == PanelStateType::Tree {
                                    if i == self.active_panel_idx {
                                        continue;
                                    }
                                    self.close_panel(i);
                                    break;
                                }
                            }
                        }
                    }
                    Internal::set_syntax_theme => {
                        let arg = cmd
                            .as_verb_invocation()
                            .and_then(|vi| vi.args.as_ref());
                        match arg {
                            Some(arg) => {
                                match SyntaxTheme::from_str(arg) {
                                    Ok(theme) => {
                                        con.syntax_theme = Some(theme);
                                        self.update_preview(con, true);
                                    }
                                    Err(e) => {
                                        error = Some(e.to_string());
                                    }
                                }
                            }
                            None => {
                                error = Some("no theme provided".to_string());
                            }
                        }
                    }
                    _ => {
                        info!("unhandled propagated internal. cmd={:?}", &cmd);
                    }
                }
            }
            Keep => {
                if is_input_invocation {
                    self.mut_panel().clear_input_invocation(con);
                }
            }
            Launch(launchable) => {
                self.launch_at_end = Some(*launchable);
                self.quitting = true;
            }
            NewPanel {
                state,
                purpose,
                direction,
            } => {
                if let Err(s) = self.new_panel(state, purpose, direction, is_input_invocation, con) {
                    error = Some(s);
                }
            }
            NewState { state, message } => {
                self.mut_panel().clear_input();
                self.mut_panel().push_state(state);
                if let Some(md) = message {
                    self.mut_panel().set_message(md);
                } else {
                    self.mut_panel().refresh_input_status(app_state, &app_cmd_context);
                }
            }
            PopState => {
                if is_input_invocation {
                    self.mut_panel().clear_input();
                }
                if self.remove_state() {
                    self.mut_state().refresh(app_cmd_context.screen, con);
                    self.mut_panel().refresh_input_status(app_state, &app_cmd_context);
                } else if con.quit_on_last_cancel {
                    self.quitting = true;
                }
            }
            PopStateAndReapply => {
                if is_input_invocation {
                    self.mut_panel().clear_input();
                }
                if self.remove_state() {
                    let app_cmd_context = AppCmdContext {
                        panel_skin,
                        preview_panel: self.preview_panel,
                        stage_panel: self.stage_panel,
                        screen: self.screen,
                        con,
                    };
                    self.mut_panel().apply_command(w, &cmd, app_state, &app_cmd_context)?;
                } else if con.quit_on_last_cancel {
                    self.quitting = true;
                }
            }
            Quit => {
                self.quitting = true;
            }
            RefreshState { clear_cache } => {
                if is_input_invocation {
                    self.mut_panel().clear_input_invocation(con);
                }
                if clear_cache {
                    clear_caches();
                }
                app_state.stage.refresh();
                for i in 0..self.panels.len().get() {
                    self.panels[i].mut_state().refresh(self.screen, con);
                }
            }
        }
        if let Some(text) = error {
            self.mut_panel().set_error(text);
        }

        app_state.other_panel_path = self.get_other_panel_path();
        if let Some(path) = self.state().tree_root() {
            app_state.root = path.to_path_buf();
        }


        if let Some(shared_root) = &mut self.shared_root {
            if let Ok(mut root) = shared_root.lock() {
                *root = app_state.root.clone();
            }
        }

        self.update_preview(con, false);

        Ok(())
    }
Examples found in repository?
src/app/panel.rs (line 135)
128
129
130
131
132
133
134
135
136
137
138
139
    pub fn add_event(
        &mut self,
        w: &mut W,
        event: TimedEvent,
        app_state: &AppState,
        con: &AppContext,
    ) -> Result<Command, ProgramError> {
        let sel_info = self.states[self.states.len() - 1].sel_info(app_state);
        let mode = self.state().get_mode();
        let panel_state_type = self.state().get_type();
        self.input.on_event(w, event, con, sel_info, app_state, mode, panel_state_type)
    }
More examples
Hide additional examples
src/app/panel_state.rs (line 552)
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
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
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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
    fn on_internal_generic(
        &mut self,
        _w: &mut W,
        internal_exec: &InternalExecution,
        input_invocation: Option<&VerbInvocation>,
        _trigger_type: TriggerType,
        app_state: &mut AppState,
        cc: &CmdContext,
    ) -> Result<CmdResult, ProgramError> {
        let con = &cc.app.con;
        let screen = cc.app.screen;
        let bang = input_invocation
            .map(|inv| inv.bang)
            .unwrap_or(internal_exec.bang);
        Ok(match internal_exec.internal {
            Internal::back => CmdResult::PopState,
            Internal::copy_line | Internal::copy_path => {
                #[cfg(not(feature = "clipboard"))]
                {
                    CmdResult::error("Clipboard feature not enabled at compilation")
                }
                #[cfg(feature = "clipboard")]
                {
                    if let Some(path) = self.selected_path() {
                        let path = path.to_string_lossy().to_string();
                        match terminal_clipboard::set_string(path) {
                            Ok(()) => CmdResult::Keep,
                            Err(_) => CmdResult::error("Clipboard error while copying path"),
                        }
                    } else {
                        CmdResult::error("Nothing to copy")
                    }
                }
            }
            Internal::close_panel_ok => CmdResult::ClosePanel {
                validate_purpose: true,
                panel_ref: PanelReference::Active,
            },
            Internal::close_panel_cancel => CmdResult::ClosePanel {
                validate_purpose: false,
                panel_ref: PanelReference::Active,
            },
            #[cfg(unix)]
            Internal::filesystems => {
                let fs_state = crate::filesystems::FilesystemState::new(
                    self.selected_path(),
                    self.tree_options(),
                    con,
                );
                match fs_state {
                    Ok(state) => {
                        let bang = input_invocation
                            .map(|inv| inv.bang)
                            .unwrap_or(internal_exec.bang);
                        if bang && cc.app.preview_panel.is_none() {
                            CmdResult::NewPanel {
                                state: Box::new(state),
                                purpose: PanelPurpose::None,
                                direction: HDir::Right,
                            }
                        } else {
                            CmdResult::new_state(Box::new(state))
                        }
                    }
                    Err(e) => CmdResult::DisplayError(format!("{}", e)),
                }
            }
            Internal::help => {
                let bang = input_invocation
                    .map(|inv| inv.bang)
                    .unwrap_or(internal_exec.bang);
                if bang && cc.app.preview_panel.is_none() {
                    CmdResult::NewPanel {
                        state: Box::new(HelpState::new(self.tree_options(), screen, con)),
                        purpose: PanelPurpose::None,
                        direction: HDir::Right,
                    }
                } else {
                    CmdResult::new_state(Box::new(
                            HelpState::new(self.tree_options(), screen, con)
                    ))
                }
            }
            Internal::mode_input => self.on_mode_verb(Mode::Input, con),
            Internal::mode_command => self.on_mode_verb(Mode::Command, con),
            Internal::open_leave => {
                if let Some(selection) = self.selection() {
                    selection.to_opener(con)?
                } else {
                    CmdResult::error("no selection to open")
                }
            }
            Internal::open_preview => self.open_preview(None, false, cc),
            Internal::preview_image => self.open_preview(Some(PreviewMode::Image), false, cc),
            Internal::preview_text => self.open_preview(Some(PreviewMode::Text), false, cc),
            Internal::preview_binary => self.open_preview(Some(PreviewMode::Hex), false, cc),
            Internal::toggle_preview => self.open_preview(None, true, cc),
            Internal::sort_by_count => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::Count {
                        o.sort = Sort::None;
                        o.show_counts = false;
                        "*not sorting anymore*"
                    } else {
                        o.sort = Sort::Count;
                        o.show_counts = true;
                        "*now sorting by file count*"
                    }
                },
                bang,
                con,
            ),
            Internal::sort_by_date => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::Date {
                        o.sort = Sort::None;
                        o.show_dates = false;
                        "*not sorting anymore*"
                    } else {
                        o.sort = Sort::Date;
                        o.show_dates = true;
                        "*now sorting by last modified date*"
                    }
                },
                bang,
                con,
            ),
            Internal::sort_by_size => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::Size {
                        o.sort = Sort::None;
                        o.show_sizes = false;
                        "*not sorting anymore*"
                    } else {
                        o.sort = Sort::Size;
                        o.show_sizes = true;
                        o.show_root_fs = true;
                        "*now sorting files and directories by total size*"
                    }
                },
                bang,
                con,
            ),
            Internal::sort_by_type => self.with_new_options(
                screen,
                &|o| {
                    match o.sort {
                        Sort::TypeDirsFirst => {
                           o.sort = Sort::TypeDirsLast;
                           "*sorting by type, directories last*"
                        }
                        Sort::TypeDirsLast => {
                            o.sort = Sort::None;
                            "*not sorting anymore*"
                        }
                        _ => {
                            o.sort = Sort::TypeDirsFirst;
                           "*sorting by type, directories first*"
                        }
                    }
                },
                bang,
                con,
            ),
            Internal::sort_by_type_dirs_first => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::TypeDirsFirst {
                        o.sort = Sort::None;
                        "*not sorting anymore*"
                    } else {
                        o.sort = Sort::TypeDirsFirst;
                        "*now sorting by type, directories first*"
                    }
                },
                bang,
                con,
            ),
            Internal::sort_by_type_dirs_last => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::TypeDirsLast {
                        o.sort = Sort::None;
                        "*not sorting anymore*"
                    } else {
                        o.sort = Sort::TypeDirsLast;
                        "*now sorting by type, directories last*"
                    }
                },
                bang,
                con,
            ),
            Internal::no_sort => self.with_new_options(
                screen,
                &|o| {
                    if o.sort == Sort::None {
                        "*still not searching*"
                    } else {
                        o.sort = Sort::None;
                        "*not sorting anymore*"
                    }
                },
                bang,
                con,
            ),
            Internal::toggle_counts => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_counts ^= true;
                        if o.show_counts {
                            "*displaying file counts*"
                        } else {
                            "*hiding file counts*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_dates => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_dates ^= true;
                        if o.show_dates {
                            "*displaying last modified dates*"
                        } else {
                            "*hiding last modified dates*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_device_id => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_device_id ^= true;
                        if o.show_device_id {
                            "*displaying device id*"
                        } else {
                            "*hiding device id*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_files => {
                self.with_new_options(
					screen,
					&|o| {
                        o.only_folders ^= true;
                        if o.only_folders {
                            "*displaying only directories*"
                        } else {
                            "*displaying both files and directories*"
                        }
                    },
					bang,
					con,
				)
            }
            Internal::toggle_hidden => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_hidden ^= true;
                        if o.show_hidden {
                            "h:**y** - *Hidden files displayed*"
                        } else {
                            "h:**n** - *Hidden files not displayed*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_root_fs => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_root_fs ^= true;
                        if o.show_root_fs {
                            "*displaying filesystem info for the tree's root directory*"
                        } else {
                            "*removing filesystem info*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_git_ignore => {
                self.with_new_options(
					screen,
					&|o| {
						o.respect_git_ignore ^= true;
                        if o.respect_git_ignore {
                            "gi:**y** - *applying gitignore rules*"
                        } else {
                            "gi:**n** - *not applying gitignore rules*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_git_file_info => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_git_file_info ^= true;
                        if o.show_git_file_info {
                            "*displaying git info next to files*"
                        } else {
                            "*removing git file info*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_git_status => {
                self.with_new_options(
                    screen, &|o| {
                        if o.filter_by_git_status {
                            o.filter_by_git_status = false;
                            "*not filtering according to git status anymore*"
                        } else {
                            o.filter_by_git_status = true;
                            o.show_hidden = true;
                            "*only displaying new or modified files*"
                        }
                    }, bang, con
                )
            }
            Internal::toggle_perm => {
                self.with_new_options(
					screen,
					&|o| {
						o.show_permissions ^= true;
                        if o.show_permissions {
                            "*displaying file permissions*"
                        } else {
                            "*removing file permissions*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::toggle_sizes => self.with_new_options(
                screen,
                &|o| {
                    if o.show_sizes {
                        o.show_sizes = false;
                        o.show_root_fs = false;
                        "*removing sizes of files and directories*"
                    } else {
                        o.show_sizes = true;
                        o.show_root_fs = true;
                        "*now diplaying sizes of files and directories*"
                    }
                },
                bang,
                con,
            ),
            Internal::toggle_trim_root => {
                self.with_new_options(
					screen,
					&|o| {
						o.trim_root ^= true;
                        if o.trim_root {
                            "*now trimming root from excess files*"
                        } else {
                            "*not trimming root files anymore*"
                        }
					},
					bang,
					con,
				)
            }
            Internal::close_preview => {
                if let Some(id) = cc.app.preview_panel {
                    CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(id),
                    }
                } else {
                    CmdResult::Keep
                }
            }
            Internal::panel_left | Internal::panel_left_no_open => {
                CmdResult::HandleInApp(Internal::panel_left_no_open)
            }
            Internal::panel_right | Internal::panel_right_no_open => {
                CmdResult::HandleInApp(Internal::panel_right_no_open)
            }
            Internal::toggle_second_tree => {
                CmdResult::HandleInApp(Internal::toggle_second_tree)
            }
            Internal::clear_stage => {
                app_state.stage.clear();
                if let Some(panel_id) = cc.app.stage_panel {
                    CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(panel_id),
                    }
                } else {
                    CmdResult::Keep
                }
            }
            Internal::stage => self.stage(app_state, cc, con),
            Internal::unstage => self.unstage(app_state, cc, con),
            Internal::toggle_stage => self.toggle_stage(app_state, cc, con),
            Internal::close_staging_area => {
                if let Some(id) = cc.app.stage_panel {
                    CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(id),
                    }
                } else {
                    CmdResult::Keep
                }
            }
            Internal::open_staging_area => {
                if cc.app.stage_panel.is_none() {
                    CmdResult::NewPanel {
                        state: Box::new(StageState::new(app_state, self.tree_options(), con)),
                        purpose: PanelPurpose::None,
                        direction: HDir::Right,
                    }
                } else {
                    CmdResult::Keep
                }
            }
            Internal::toggle_staging_area => {
                if let Some(id) = cc.app.stage_panel {
                    CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(id),
                    }
                } else {
                    CmdResult::NewPanel {
                        state: Box::new(StageState::new(app_state, self.tree_options(), con)),
                        purpose: PanelPurpose::None,
                        direction: HDir::Right,
                    }
                }
            }
            Internal::set_syntax_theme => CmdResult::HandleInApp(Internal::set_syntax_theme),
            Internal::print_path => print::print_paths(self.sel_info(app_state), con)?,
            Internal::print_relative_path => print::print_relative_paths(self.sel_info(app_state), con)?,
            Internal::refresh => CmdResult::RefreshState { clear_cache: true },
            Internal::quit => CmdResult::Quit,
            _ => CmdResult::Keep,
        })
    }

    fn stage(
        &self,
        app_state: &mut AppState,
        cc: &CmdContext,
        con: &AppContext,
    ) -> CmdResult {
        if let Some(path) = self.selected_path() {
            let path = path.to_path_buf();
            app_state.stage.add(path);
            if cc.app.stage_panel.is_none() {
                return CmdResult::NewPanel {
                    state: Box::new(StageState::new(app_state, self.tree_options(), con)),
                    purpose: PanelPurpose::None,
                    direction: HDir::Right,
                };
            }
        } else {
            // TODO display error ?
            warn!("no path in state");
        }
        CmdResult::Keep
    }

    fn unstage(
        &self,
        app_state: &mut AppState,
        cc: &CmdContext,
        _con: &AppContext,
    ) -> CmdResult {
        if let Some(path) = self.selected_path() {
            if app_state.stage.remove(path) && app_state.stage.is_empty() {
                if let Some(panel_id) = cc.app.stage_panel {
                    return CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(panel_id),
                    };
                }
            }
        }
        CmdResult::Keep
    }

    fn toggle_stage(
        &self,
        app_state: &mut AppState,
        cc: &CmdContext,
        con: &AppContext,
    ) -> CmdResult {
        if let Some(path) = self.selected_path() {
            if app_state.stage.contains(path) {
                self.unstage(app_state, cc, con)
            } else {
                self.stage(app_state, cc, con)
            }
        } else {
            CmdResult::error("no selection")
        }
    }

    fn execute_verb(
        &mut self,
        w: &mut W, // needed because we may want to switch from alternate in some externals
        verb: &Verb,
        invocation: Option<&VerbInvocation>,
        trigger_type: TriggerType,
        app_state: &mut AppState,
        cc: &CmdContext,
    ) -> Result<CmdResult, ProgramError> {
        if verb.needs_selection && !self.has_at_least_one_selection(app_state) {
            return Ok(CmdResult::error("This verb needs a selection"));
        }
        if verb.needs_another_panel && app_state.other_panel_path.is_none() {
            return Ok(CmdResult::error("This verb needs another panel"));
        }
        let res = match &verb.execution {
            VerbExecution::Internal(internal_exec) => {
                self.on_internal(
                    w,
                    internal_exec,
                    invocation,
                    trigger_type,
                    app_state,
                    cc,
                )
            }
            VerbExecution::External(external) => {
                self.execute_external(w, verb, external, invocation, app_state, cc)
            }
            VerbExecution::Sequence(seq_ex) => {
                self.execute_sequence(w, verb, seq_ex, invocation, app_state, cc)
            }
        };
        if res.is_ok() {
            // if the stage has been emptied by the operation (eg a "rm"), we
            // close it
            app_state.stage.refresh();
            if app_state.stage.is_empty() {
                if let Some(id) = cc.app.stage_panel {
                    return Ok(CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(id),
                    });
                }
            }
        }
        res
    }

    fn execute_external(
        &mut self,
        w: &mut W,
        verb: &Verb,
        external_execution: &ExternalExecution,
        invocation: Option<&VerbInvocation>,
        app_state: &mut AppState,
        cc: &CmdContext,
    ) -> Result<CmdResult, ProgramError> {
        let sel_info = self.sel_info(app_state);
        if let Some(invocation) = &invocation {
            if let Some(error) = verb.check_args(sel_info, invocation, &app_state.other_panel_path) {
                debug!("verb.check_args prevented execution: {:?}", &error);
                return Ok(CmdResult::error(error));
            }
        }
        let exec_builder = ExecutionStringBuilder::with_invocation(
            &verb.invocation_parser,
            sel_info,
            app_state,
            if let Some(inv) = invocation {
                inv.args.as_ref()
            } else {
                None
            },
        );
        external_execution.to_cmd_result(w, exec_builder, cc.app.con)
    }

    fn execute_sequence(
        &mut self,
        _w: &mut W,
        verb: &Verb,
        seq_ex: &SequenceExecution,
        invocation: Option<&VerbInvocation>,
        app_state: &mut AppState,
        _cc: &CmdContext,
    ) -> Result<CmdResult, ProgramError> {
        let sel_info = self.sel_info(app_state);
        if matches!(sel_info, SelInfo::More(_)) {
            // sequences would be hard to execute as the execution on a file can change the
            // state in too many ways (changing selection, focused panel, parent, unstage or
            // stage files, removing the staged paths, etc.)
            return Ok(CmdResult::error("sequences can't be executed on multiple selections"));
        }
        let exec_builder = ExecutionStringBuilder::with_invocation(
            &verb.invocation_parser,
            sel_info,
            app_state,
            if let Some(inv) = invocation {
                inv.args.as_ref()
            } else {
                None
            },
        );
        // TODO what follows is dangerous: if an inserted group value contains the separator,
        // the parsing will cut on this separator
        let sequence = Sequence {
            raw: exec_builder.shell_exec_string(&ExecPattern::from_string(&seq_ex.sequence.raw)),
            separator: seq_ex.sequence.separator.clone(),
        };
        Ok(CmdResult::ExecuteSequence { sequence })
    }

    /// change the state, does no rendering
    fn on_command(
        &mut self,
        w: &mut W,
        app_state: &mut AppState,
        cc: &CmdContext,
    ) -> Result<CmdResult, ProgramError> {
        self.clear_pending();
        let con = &cc.app.con;
        let screen = cc.app.screen;
        match &cc.cmd {
            Command::Click(x, y) => self.on_click(*x, *y, screen, con),
            Command::DoubleClick(x, y) => self.on_double_click(*x, *y, screen, con),
            Command::PatternEdit { raw, expr } => {
                match InputPattern::new(raw.clone(), expr, con) {
                    Ok(pattern) => self.on_pattern(pattern, app_state, con),
                    Err(e) => Ok(CmdResult::DisplayError(format!("{}", e))),
                }
            }
            Command::VerbTrigger {
                index,
                input_invocation,
            } => self.execute_verb(
                w,
                &con.verb_store.verbs[*index],
                input_invocation.as_ref(),
                TriggerType::Other,
                app_state,
                cc,
            ),
            Command::Internal {
                internal,
                input_invocation,
            } => self.on_internal(
                w,
                &InternalExecution::from_internal(*internal),
                input_invocation.as_ref(),
                TriggerType::Other,
                app_state,
                cc,
            ),
            Command::VerbInvocate(invocation) => {
                let sel_info = self.sel_info(app_state);
                match con.verb_store.search_sel_info(
                    &invocation.name,
                    sel_info,
                ) {
                    PrefixSearchResult::Match(_, verb) => {
                        self.execute_verb(
                            w,
                            verb,
                            Some(invocation),
                            TriggerType::Input(verb),
                            app_state,
                            cc,
                        )
                    }
                    _ => Ok(CmdResult::verb_not_found(&invocation.name)),
                }
            }
            Command::None | Command::VerbEdit(_) => {
                // we do nothing here, the real job is done in get_status
                Ok(CmdResult::Keep)
            }
        }
    }

    /// return a cmdresult asking for the opening of a preview
    fn open_preview(
        &mut self,
        prefered_mode: Option<PreviewMode>,
        close_if_open: bool,
        cc: &CmdContext,
    ) -> CmdResult {
        if let Some(id) = cc.app.preview_panel {
            if close_if_open {
                CmdResult::ClosePanel {
                    validate_purpose: false,
                    panel_ref: PanelReference::Id(id),
                }
            } else {
                if prefered_mode.is_some() {
                    // we'll make the preview mode change be
                    // applied on the preview panel
                    CmdResult::ApplyOnPanel { id }
                } else {
                    CmdResult::Keep
                }
            }
        } else {
            if let Some(path) = self.selected_path() {
                if path.is_file() {
                    CmdResult::NewPanel {
                        state: Box::new(PreviewState::new(
                            path.to_path_buf(),
                            InputPattern::none(),
                            prefered_mode,
                            self.tree_options(),
                            cc.app.con,
                        )),
                        purpose: PanelPurpose::Preview,
                        direction: HDir::Right,
                    }
                } else {
                    CmdResult::error("only regular files can be previewed")
                }
            } else {
                CmdResult::error("no selected file")
            }
        }
    }

    /// must return None if the state doesn't display a file tree
    fn tree_root(&self) -> Option<&Path> {
        None
    }

    fn selected_path(&self) -> Option<&Path>;

    fn selection(&self) -> Option<Selection<'_>>;

    fn sel_info<'c>(&'c self, _app_state: &'c AppState) -> SelInfo<'c> {
        // overloaded in stage_state
        match self.selection() {
            None => SelInfo::None,
            Some(selection) => SelInfo::One(selection),
        }
    }

    fn has_at_least_one_selection(&self, _app_state: &AppState) -> bool {
        true // overloaded in stage_state
    }

    fn refresh(&mut self, screen: Screen, con: &AppContext) -> Command;

    fn tree_options(&self) -> TreeOptions;

    /// Build a cmdResult in response to a command being a change of
    /// tree options. This may or not be a new state.
    ///
    /// The provided `change_options` function returns a status message
    /// explaining the change
    fn with_new_options(
        &mut self,
        screen: Screen,
        change_options: &dyn Fn(&mut TreeOptions) -> &'static str,
        in_new_panel: bool,
        con: &AppContext,
    ) -> CmdResult;

    fn do_pending_task(
        &mut self,
        _app_state: &mut AppState,
        _screen: Screen,
        _con: &AppContext,
        _dam: &mut Dam,
    ) -> Result<(), ProgramError> {
        // no pending task in default impl
        unreachable!();
    }

    fn get_pending_task(
        &self,
    ) -> Option<&'static str> {
        None
    }

    fn display(
        &mut self,
        w: &mut W,
        disc: &DisplayContext,
    ) -> Result<(), ProgramError>;

    /// return the flags to display
    fn get_flags(&self) -> Vec<Flag> {
        vec![]
    }

    fn get_starting_input(&self) -> String {
        String::new()
    }

    fn set_selected_path(&mut self, _path: PathBuf, _con: &AppContext) {
        // this function is useful for preview states
    }

    /// return the status which should be used when there's no verb edited
    fn no_verb_status(
        &self,
        _has_previous_state: bool,
        _con: &AppContext,
    ) -> Status {
        Status::from_message(
            "Hit *esc* to get back, or a space to start a verb"
        )
    }

    fn get_status(
        &self,
        app_state: &AppState,
        cc: &CmdContext,
        has_previous_state: bool,
    ) -> Status {
        match &cc.cmd {
            Command::PatternEdit { .. } => self.no_verb_status(has_previous_state, cc.app.con),
            Command::VerbEdit(invocation) => {
                if invocation.name.is_empty() {
                    Status::new(
                        "Type a verb then *enter* to execute it (*?* for the list of verbs)",
                        false,
                    )
                } else {
                    let sel_info = self.sel_info(app_state);
                    match cc.app.con.verb_store.search_sel_info(
                        &invocation.name,
                        sel_info,
                    ) {
                        PrefixSearchResult::NoMatch => {
                            Status::new("No matching verb (*?* for the list of verbs)", true)
                        }
                        PrefixSearchResult::Match(_, verb) => {
                            self.get_verb_status(verb, invocation, sel_info, cc, app_state)
                        }
                        PrefixSearchResult::Matches(completions) => Status::new(
                            format!(
                                "Possible verbs: {}",
                                completions
                                    .iter()
                                    .map(|c| format!("*{}*", c))
                                    .collect::<Vec<String>>()
                                    .join(", "),
                            ),
                            false,
                        ),
                    }
                }
            }
            _ => self.no_verb_status(has_previous_state, cc.app.con),
        }
    }
Examples found in repository?
src/app/panel_state.rs (line 628)
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
    fn execute_verb(
        &mut self,
        w: &mut W, // needed because we may want to switch from alternate in some externals
        verb: &Verb,
        invocation: Option<&VerbInvocation>,
        trigger_type: TriggerType,
        app_state: &mut AppState,
        cc: &CmdContext,
    ) -> Result<CmdResult, ProgramError> {
        if verb.needs_selection && !self.has_at_least_one_selection(app_state) {
            return Ok(CmdResult::error("This verb needs a selection"));
        }
        if verb.needs_another_panel && app_state.other_panel_path.is_none() {
            return Ok(CmdResult::error("This verb needs another panel"));
        }
        let res = match &verb.execution {
            VerbExecution::Internal(internal_exec) => {
                self.on_internal(
                    w,
                    internal_exec,
                    invocation,
                    trigger_type,
                    app_state,
                    cc,
                )
            }
            VerbExecution::External(external) => {
                self.execute_external(w, verb, external, invocation, app_state, cc)
            }
            VerbExecution::Sequence(seq_ex) => {
                self.execute_sequence(w, verb, seq_ex, invocation, app_state, cc)
            }
        };
        if res.is_ok() {
            // if the stage has been emptied by the operation (eg a "rm"), we
            // close it
            app_state.stage.refresh();
            if app_state.stage.is_empty() {
                if let Some(id) = cc.app.stage_panel {
                    return Ok(CmdResult::ClosePanel {
                        validate_purpose: false,
                        panel_ref: PanelReference::Id(id),
                    });
                }
            }
        }
        res
    }
Examples found in repository?
src/app/panel.rs (line 119)
112
113
114
115
116
117
118
119
120
    pub fn do_pending_task(
        &mut self,
        app_state: &mut AppState,
        screen: Screen,
        con: &AppContext,
        dam: &mut Dam,
    ) -> Result<(), ProgramError> {
        self.mut_state().do_pending_task(app_state, screen, con, dam)
    }
Examples found in repository?
src/app/panel.rs (line 123)
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
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
    pub fn has_pending_task(&self) -> bool {
        self.state().get_pending_task().is_some()
    }

    /// return a new command
    /// Update the input field
    pub fn add_event(
        &mut self,
        w: &mut W,
        event: TimedEvent,
        app_state: &AppState,
        con: &AppContext,
    ) -> Result<Command, ProgramError> {
        let sel_info = self.states[self.states.len() - 1].sel_info(app_state);
        let mode = self.state().get_mode();
        let panel_state_type = self.state().get_type();
        self.input.on_event(w, event, con, sel_info, app_state, mode, panel_state_type)
    }

    pub fn push_state(&mut self, new_state: Box<dyn PanelState>) {
        self.input.set_content(&new_state.get_starting_input());
        self.states.push(new_state);
    }
    pub fn mut_state(&mut self) -> &mut dyn PanelState {
        self.states.last_mut().unwrap().as_mut()
    }
    pub fn state(&self) -> &dyn PanelState {
        self.states.last().unwrap().as_ref()
    }

    pub fn clear_input(&mut self) {
        self.input.set_content("");
    }
    /// remove the verb invocation from the input but keep
    /// the filter if there's one
    pub fn clear_input_invocation(&mut self, con: &AppContext) {
        let mut command_parts = CommandParts::from(self.input.get_content());
        if command_parts.verb_invocation.is_some() {
            command_parts.verb_invocation = None;
            let new_input = format!("{}", command_parts);
            self.input.set_content(&new_input);
        }
        self.mut_state().set_mode(initial_mode(con));
    }

    pub fn set_input_content(&mut self, content: &str) {
        self.input.set_content(content);
    }

    pub fn get_input_content(&self) -> String {
        self.input.get_content()
    }

    /// change the argument of the verb in the input, if there's one
    pub fn set_input_arg(&mut self, arg: String) {
        let mut command_parts = CommandParts::from(self.input.get_content());
        if let Some(invocation) = &mut command_parts.verb_invocation {
            invocation.args = Some(arg);
            let new_input = format!("{}", command_parts);
            self.input.set_content(&new_input);
        }
    }

    /// return true when the element has been removed
    pub fn remove_state(&mut self) -> bool {
        if self.states.len() > 1 {
            self.states.pop();
            self.input.set_content(&self.state().get_starting_input());
            true
        } else {
            false
        }
    }

    /// render the whole panel (state, status, purpose, input, flags)
    pub fn display(
        &mut self,
        w: &mut W,
        disc: &DisplayContext,
    ) -> Result<(), ProgramError> {
        self.mut_state().display(w, disc)?;
        if disc.active || !WIDE_STATUS {
            self.write_status(w, disc.panel_skin, disc.screen)?;
        }
        let mut input_area = self.areas.input.clone();
        if disc.active {
            self.write_purpose(w, disc.panel_skin, disc.screen, disc.con)?;
            let flags = self.state().get_flags();
            let input_content_len = self.input.get_content().len() as u16;
            let flags_len = flags_display::visible_width(&flags);
            if input_area.width > input_content_len + 1 + flags_len {
                input_area.width -= flags_len + 1;
                disc.screen.goto(w, input_area.left + input_area.width, input_area.top)?;
                flags_display::write(w, &flags, disc.panel_skin)?;
            }
        }
        self.input.display(w, disc.active, self.state().get_mode(), input_area, disc.panel_skin)?;
        Ok(())
    }

    fn write_status(
        &self,
        w: &mut W,
        panel_skin: &PanelSkin,
        screen: Screen,
    ) -> Result<(), ProgramError> {
        let task = self.state().get_pending_task();
        status_line::write(
            w,
            task,
            &self.status,
            &self.areas.status,
            panel_skin,
            screen,
        )
    }

return the flags to display

Examples found in repository?
src/app/panel.rs (line 209)
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
    pub fn display(
        &mut self,
        w: &mut W,
        disc: &DisplayContext,
    ) -> Result<(), ProgramError> {
        self.mut_state().display(w, disc)?;
        if disc.active || !WIDE_STATUS {
            self.write_status(w, disc.panel_skin, disc.screen)?;
        }
        let mut input_area = self.areas.input.clone();
        if disc.active {
            self.write_purpose(w, disc.panel_skin, disc.screen, disc.con)?;
            let flags = self.state().get_flags();
            let input_content_len = self.input.get_content().len() as u16;
            let flags_len = flags_display::visible_width(&flags);
            if input_area.width > input_content_len + 1 + flags_len {
                input_area.width -= flags_len + 1;
                disc.screen.goto(w, input_area.left + input_area.width, input_area.top)?;
                flags_display::write(w, &flags, disc.panel_skin)?;
            }
        }
        self.input.display(w, disc.active, self.state().get_mode(), input_area, disc.panel_skin)?;
        Ok(())
    }
Examples found in repository?
src/app/panel.rs (line 45)
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
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
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
    pub fn new(
        id: PanelId,
        state: Box<dyn PanelState>,
        areas: Areas,
        con: &AppContext,
    ) -> Self {
        let mut input = PanelInput::new(areas.input.clone());
        input.set_content(&state.get_starting_input());
        let status = state.no_verb_status(false, con);
        Self {
            id,
            states: vec![state],
            areas,
            status,
            purpose: PanelPurpose::None,
            input,
        }
    }

    pub fn set_error(&mut self, text: String) {
        self.status = Status::from_error(text);
    }
    pub fn set_message<S: Into<String>>(&mut self, md: S) {
        self.status = Status::from_message(md.into());
    }

    /// apply a command on the current state, with no
    /// effect on screen
    #[allow(clippy::too_many_arguments)] // a refactory could still be useful
    pub fn apply_command<'c>(
        &mut self,
        w: &'c mut W,
        cmd: &'c Command,
        app_state: &mut AppState,
        app_cmd_context: &'c AppCmdContext<'c>,
    ) -> Result<CmdResult, ProgramError> {
        let state_idx = self.states.len() - 1;
        let cc = CmdContext {
            cmd,
            app: app_cmd_context,
            panel: PanelCmdContext {
                areas: &self.areas,
                purpose: self.purpose,
            },
        };
        let result = self.states[state_idx].on_command(w, app_state, &cc);
        let has_previous_state = self.states.len() > 1;
        self.status = self.state().get_status(app_state, &cc, has_previous_state);
        result
    }

    /// called on focusing the panel and before the display,
    /// this updates the status from the command read in the input
    pub fn refresh_input_status<'c>(
        &mut self,
        app_state: &AppState,
        app_cmd_context: &'c AppCmdContext<'c>,
    ) {
        let cmd = Command::from_raw(self.input.get_content(), false);
        let cc = CmdContext {
            cmd: &cmd,
            app: app_cmd_context,
            panel: PanelCmdContext {
                areas: &self.areas,
                purpose: self.purpose,
            },
        };
        let has_previous_state = self.states.len() > 1;
        self.status = self.state().get_status(app_state, &cc, has_previous_state);
    }


    /// do the next pending task stopping as soon as there's an event
    /// in the dam
    pub fn do_pending_task(
        &mut self,
        app_state: &mut AppState,
        screen: Screen,
        con: &AppContext,
        dam: &mut Dam,
    ) -> Result<(), ProgramError> {
        self.mut_state().do_pending_task(app_state, screen, con, dam)
    }

    pub fn has_pending_task(&self) -> bool {
        self.state().get_pending_task().is_some()
    }

    /// return a new command
    /// Update the input field
    pub fn add_event(
        &mut self,
        w: &mut W,
        event: TimedEvent,
        app_state: &AppState,
        con: &AppContext,
    ) -> Result<Command, ProgramError> {
        let sel_info = self.states[self.states.len() - 1].sel_info(app_state);
        let mode = self.state().get_mode();
        let panel_state_type = self.state().get_type();
        self.input.on_event(w, event, con, sel_info, app_state, mode, panel_state_type)
    }

    pub fn push_state(&mut self, new_state: Box<dyn PanelState>) {
        self.input.set_content(&new_state.get_starting_input());
        self.states.push(new_state);
    }
    pub fn mut_state(&mut self) -> &mut dyn PanelState {
        self.states.last_mut().unwrap().as_mut()
    }
    pub fn state(&self) -> &dyn PanelState {
        self.states.last().unwrap().as_ref()
    }

    pub fn clear_input(&mut self) {
        self.input.set_content("");
    }
    /// remove the verb invocation from the input but keep
    /// the filter if there's one
    pub fn clear_input_invocation(&mut self, con: &AppContext) {
        let mut command_parts = CommandParts::from(self.input.get_content());
        if command_parts.verb_invocation.is_some() {
            command_parts.verb_invocation = None;
            let new_input = format!("{}", command_parts);
            self.input.set_content(&new_input);
        }
        self.mut_state().set_mode(initial_mode(con));
    }

    pub fn set_input_content(&mut self, content: &str) {
        self.input.set_content(content);
    }

    pub fn get_input_content(&self) -> String {
        self.input.get_content()
    }

    /// change the argument of the verb in the input, if there's one
    pub fn set_input_arg(&mut self, arg: String) {
        let mut command_parts = CommandParts::from(self.input.get_content());
        if let Some(invocation) = &mut command_parts.verb_invocation {
            invocation.args = Some(arg);
            let new_input = format!("{}", command_parts);
            self.input.set_content(&new_input);
        }
    }

    /// return true when the element has been removed
    pub fn remove_state(&mut self) -> bool {
        if self.states.len() > 1 {
            self.states.pop();
            self.input.set_content(&self.state().get_starting_input());
            true
        } else {
            false
        }
    }
Examples found in repository?
src/preview/preview_state.rs (line 216)
214
215
216
217
218
    fn refresh(&mut self, _screen: Screen, con: &AppContext) -> Command {
        self.dirty = true;
        self.set_selected_path(self.path.clone(), con);
        Command::empty()
    }
More examples
Hide additional examples
src/app/app.rs (line 547)
540
541
542
543
544
545
546
547
548
549
550
551
    fn update_preview(&mut self, con: &AppContext, refresh: bool) {
        let preview_idx = self.preview_panel.and_then(|id| self.panel_id_to_idx(id));
        if let Some(preview_idx) = preview_idx {
            if let Some(path) = self.state().selected_path() {
                let old_path = self.panels[preview_idx].state().selected_path();
                if (refresh || Some(path) != old_path) && path.is_file() {
                    let path = path.to_path_buf();
                    self.panels[preview_idx].mut_state().set_selected_path(path, con);
                }
            }
        }
    }

return the status which should be used when there’s no verb edited

Examples found in repository?
src/app/panel.rs (line 46)
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
    pub fn new(
        id: PanelId,
        state: Box<dyn PanelState>,
        areas: Areas,
        con: &AppContext,
    ) -> Self {
        let mut input = PanelInput::new(areas.input.clone());
        input.set_content(&state.get_starting_input());
        let status = state.no_verb_status(false, con);
        Self {
            id,
            states: vec![state],
            areas,
            status,
            purpose: PanelPurpose::None,
            input,
        }
    }
More examples
Hide additional examples
src/app/panel_state.rs (line 936)
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
    fn get_status(
        &self,
        app_state: &AppState,
        cc: &CmdContext,
        has_previous_state: bool,
    ) -> Status {
        match &cc.cmd {
            Command::PatternEdit { .. } => self.no_verb_status(has_previous_state, cc.app.con),
            Command::VerbEdit(invocation) => {
                if invocation.name.is_empty() {
                    Status::new(
                        "Type a verb then *enter* to execute it (*?* for the list of verbs)",
                        false,
                    )
                } else {
                    let sel_info = self.sel_info(app_state);
                    match cc.app.con.verb_store.search_sel_info(
                        &invocation.name,
                        sel_info,
                    ) {
                        PrefixSearchResult::NoMatch => {
                            Status::new("No matching verb (*?* for the list of verbs)", true)
                        }
                        PrefixSearchResult::Match(_, verb) => {
                            self.get_verb_status(verb, invocation, sel_info, cc, app_state)
                        }
                        PrefixSearchResult::Matches(completions) => Status::new(
                            format!(
                                "Possible verbs: {}",
                                completions
                                    .iter()
                                    .map(|c| format!("*{}*", c))
                                    .collect::<Vec<String>>()
                                    .join(", "),
                            ),
                            false,
                        ),
                    }
                }
            }
            _ => self.no_verb_status(has_previous_state, cc.app.con),
        }
    }
Examples found in repository?
src/app/panel.rs (line 85)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
    pub fn apply_command<'c>(
        &mut self,
        w: &'c mut W,
        cmd: &'c Command,
        app_state: &mut AppState,
        app_cmd_context: &'c AppCmdContext<'c>,
    ) -> Result<CmdResult, ProgramError> {
        let state_idx = self.states.len() - 1;
        let cc = CmdContext {
            cmd,
            app: app_cmd_context,
            panel: PanelCmdContext {
                areas: &self.areas,
                purpose: self.purpose,
            },
        };
        let result = self.states[state_idx].on_command(w, app_state, &cc);
        let has_previous_state = self.states.len() > 1;
        self.status = self.state().get_status(app_state, &cc, has_previous_state);
        result
    }

    /// called on focusing the panel and before the display,
    /// this updates the status from the command read in the input
    pub fn refresh_input_status<'c>(
        &mut self,
        app_state: &AppState,
        app_cmd_context: &'c AppCmdContext<'c>,
    ) {
        let cmd = Command::from_raw(self.input.get_content(), false);
        let cc = CmdContext {
            cmd: &cmd,
            app: app_cmd_context,
            panel: PanelCmdContext {
                areas: &self.areas,
                purpose: self.purpose,
            },
        };
        let has_previous_state = self.states.len() > 1;
        self.status = self.state().get_status(app_state, &cc, has_previous_state);
    }
Examples found in repository?
src/app/panel_state.rs (line 953)
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
    fn get_status(
        &self,
        app_state: &AppState,
        cc: &CmdContext,
        has_previous_state: bool,
    ) -> Status {
        match &cc.cmd {
            Command::PatternEdit { .. } => self.no_verb_status(has_previous_state, cc.app.con),
            Command::VerbEdit(invocation) => {
                if invocation.name.is_empty() {
                    Status::new(
                        "Type a verb then *enter* to execute it (*?* for the list of verbs)",
                        false,
                    )
                } else {
                    let sel_info = self.sel_info(app_state);
                    match cc.app.con.verb_store.search_sel_info(
                        &invocation.name,
                        sel_info,
                    ) {
                        PrefixSearchResult::NoMatch => {
                            Status::new("No matching verb (*?* for the list of verbs)", true)
                        }
                        PrefixSearchResult::Match(_, verb) => {
                            self.get_verb_status(verb, invocation, sel_info, cc, app_state)
                        }
                        PrefixSearchResult::Matches(completions) => Status::new(
                            format!(
                                "Possible verbs: {}",
                                completions
                                    .iter()
                                    .map(|c| format!("*{}*", c))
                                    .collect::<Vec<String>>()
                                    .join(", "),
                            ),
                            false,
                        ),
                    }
                }
            }
            _ => self.no_verb_status(has_previous_state, cc.app.con),
        }
    }

Implementors§