delta-gitu 0.1.8

An experimental fork of gitu (a git client inspired by Magit), published as a library for delta to embed
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
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
use super::{Action, OpTrait};
use crate::{
    Res,
    app::{App, PromptParams, State},
    error::Error,
    item_data::ItemData,
    menu::PendingMenu,
    picker::{Picked, PickerData, PickerItem, PickerState},
    screen::NavMode,
    term::Term,
};
use std::cell::RefCell;
use std::rc::Rc;

pub(crate) struct Quit;
impl OpTrait for Quit {
    fn get_action(&self, _target: &ItemData) -> Option<Action> {
        Some(Rc::new(|app, term| {
            let menu = app
                .state
                .pending_menu
                .as_ref()
                .map(|pending_menu| pending_menu.menu);

            if menu == app.base_menu() {
                if app.state.screens.len() == 1 {
                    if app.state.config.general.confirm_quit.enabled {
                        app.confirm(term, "Really quit? (y or n)")?;
                    };

                    app.state.quit = true;
                } else {
                    app.state.screens.pop();
                }
            }

            Ok(())
        }))
    }

    fn display(&self, _state: &State) -> String {
        "Quit/Close".into()
    }
}

pub(crate) struct OpenMenu(pub crate::menu::Menu);
impl OpTrait for OpenMenu {
    fn get_action(&self, _target: &ItemData) -> Option<Action> {
        let submenu = self.0;
        Some(Rc::new(move |app, _term| {
            app.state.pending_menu = Some(PendingMenu::init(submenu));
            app.inhibit_close_menu();
            Ok(())
        }))
    }

    fn display(&self, _state: &State) -> String {
        "Submenu".into()
    }
}

pub(crate) struct Refresh;
impl OpTrait for Refresh {
    fn get_action(&self, _target: &ItemData) -> Option<Action> {
        Some(Rc::new(|app, _term| app.update_screens()))
    }

    fn display(&self, _state: &State) -> String {
        "Refresh".into()
    }
}

pub(crate) struct ToggleArg(pub String);
impl OpTrait for ToggleArg {
    fn get_action(&self, _target: &ItemData) -> Option<Action> {
        let arg_name = self.0.clone();
        Some(Rc::new(move |app, term| {
            let mut need_prompt = None;
            let mut default = None;

            let maybe_entry = if let Some(menu) = &mut app.state.pending_menu {
                Some(menu.args.entry(arg_name.clone().into()))
            } else {
                None
            };

            if let Some(entry) = maybe_entry {
                entry.and_modify(|arg| {
                    if arg.is_active() {
                        arg.unset();
                    } else if arg.expects_value() {
                        default = arg.default_as_string();
                        need_prompt = Some(arg.display);
                    } else {
                        arg.set("").expect("Should succeed");
                    }
                });
            }

            let arg_name = arg_name.clone();
            let parse_and_set_arg =
                Box::new(move |app: &mut App, _term: &mut Term, value: &str| {
                    if let Some(menu) = &mut app.state.pending_menu
                        && let Some(entry) = menu.args.get_mut(arg_name.as_str())
                    {
                        return entry.set(value);
                    }

                    Ok(())
                });

            if let Some(display) = need_prompt {
                let arg = app.prompt(
                    term,
                    &PromptParams {
                        prompt: display,
                        create_default_value: Box::new(move |_| default.clone()),
                        hide_menu: false,
                        prefill: false,
                        history: None,
                    },
                )?;

                parse_and_set_arg(app, term, &arg)?;
            }

            app.inhibit_close_menu();
            Ok(())
        }))
    }

    fn display(&self, _state: &State) -> String {
        self.0.clone()
    }
}

pub(crate) struct ToggleSection;
impl OpTrait for ToggleSection {
    fn get_action(&self, target: &ItemData) -> Option<Action> {
        if target.is_section() {
            Some(Rc::new(|app, _term| {
                app.screen_mut().toggle_section()?;
                Ok(())
            }))
        } else {
            None
        }
    }

    fn is_target_op(&self) -> bool {
        true
    }

    fn display(&self, state: &State) -> String {
        let item = state.screens.last().unwrap().get_selected_item();
        if state.screens.last().unwrap().is_collapsed(item) {
            "Unfold".into()
        } else {
            "Fold".into()
        }
    }
}

/// Ask git for a different amount of the file around each change: a number of
/// lines, or the whole enclosing function.
pub(crate) struct DiffContext;
impl OpTrait for DiffContext {
    fn get_action(&self, _target: &ItemData) -> Option<Action> {
        Some(Rc::new(|app: &mut App, term: &mut Term| {
            let current = app.state.context.clone();
            let answer = app.prompt(
                term,
                &PromptParams {
                    prompt: "",
                    create_default_value: Box::new(move |_| {
                        current.as_deref().map(|flag| match flag {
                            "-W" => "W".to_owned(),
                            flag => flag.trim_start_matches("-U").to_owned(),
                        })
                    }),
                    hide_menu: false,
                    prefill: true,
                    history: None,
                },
            )?;

            let Some(flag) = context_flag(&answer) else {
                app.display_error(format!("Not a number of lines, nor W: {answer}"));
                return Ok(());
            };

            app.state.context = flag;
            app.rerender_screens()
        }))
    }

    fn display(&self, _state: &State) -> String {
        "Diff context".into()
    }
}

/// Edit the question git is being asked. Everything a view is — the revs, what
/// is compared with what, which paths, how much context — is in that command,
/// so this is the general case of which [`DiffContext`] is one canned edit.
pub(crate) struct EditGitCommand;
impl OpTrait for EditGitCommand {
    fn get_action(&self, _target: &ItemData) -> Option<Action> {
        Some(Rc::new(|app: &mut App, term: &mut Term| {
            let Some(git) = app.screen().git_command.clone() else {
                app.display_error(NOT_ASKED_FOR);
                return Ok(());
            };

            let line = git.borrow().line(app.state.context.as_deref());
            let answer = app.prompt(
                term,
                &PromptParams {
                    prompt: "",
                    create_default_value: Box::new(move |_| Some(line.clone())),
                    prefill: true,
                    history: Some(crate::prompt::HistoryKind::GitCommand),
                    ..Default::default()
                },
            )?;

            let edited = git.borrow().edited(&answer);
            match edited {
                Ok(edited) => *git.borrow_mut() = edited,
                Err(err) => {
                    app.display_error(err.to_string());
                    return Ok(());
                }
            }

            // The edit said what context it wants, in the line it was given.
            app.state.context = None;
            app.rerender_screens()
        }))
    }

    fn display(&self, _state: &State) -> String {
        "Edit git command".into()
    }
}

/// Limit the view to some of the files it covers, or drop some of them. Both
/// are edits of the same command, and so of the same kind as [`EditGitCommand`]
/// — this only saves writing the pathspec magic out.
pub(crate) struct FilePatterns;
impl OpTrait for FilePatterns {
    fn get_action(&self, _target: &ItemData) -> Option<Action> {
        Some(Rc::new(|app: &mut App, term: &mut Term| {
            let Some(git) = app.screen().git_command.clone() else {
                app.display_error(NOT_ASKED_FOR);
                return Ok(());
            };

            let patterns = git.borrow().file_patterns().join(" ");
            let answer = app.prompt(
                term,
                &PromptParams {
                    prompt: "Files",
                    create_default_value: Box::new(move |_| Some(patterns.clone())),
                    prefill: true,
                    history: Some(crate::prompt::HistoryKind::FilePatterns),
                    ..Default::default()
                },
            )?;

            let patterns = match shell_words::split(&answer) {
                Ok(patterns) => patterns,
                Err(_) => {
                    app.display_error(Error::EditedCommandQuotes.to_string());
                    return Ok(());
                }
            };

            ask_for(app, &git, &patterns)
        }))
    }

    fn display(&self, _state: &State) -> String {
        "Files".into()
    }
}

/// Drop the file whose header is under the cursor from the view, as if it were
/// not in the patch. The frequent case, and the one worth a keystroke: the noise is in
/// front of you and it goes away.
pub(crate) struct HideFile;
impl OpTrait for HideFile {
    fn get_action(&self, target: &ItemData) -> Option<Action> {
        let path = file_of(target)?;

        Some(Rc::new(move |app: &mut App, _term: &mut Term| {
            let Some(git) = app.screen().git_command.clone() else {
                app.display_error(NOT_ASKED_FOR);
                return Ok(());
            };

            let mut patterns = git.borrow().file_patterns();
            patterns.push(crate::calling_process::excluding(&path));

            ask_for(app, &git, &patterns)
        }))
    }

    fn is_target_op(&self) -> bool {
        true
    }

    fn display(&self, _state: &State) -> String {
        "Hide file".into()
    }
}

const NOT_ASKED_FOR: &str = "This view is not something gitu asked git for";

/// Put the held command again, for these paths, and remember it as if typed
/// at `:`.
fn ask_for(
    app: &mut App,
    git: &Rc<RefCell<crate::calling_process::GitCommand>>,
    patterns: &[String],
) -> Res<()> {
    let asking_for = git.borrow().asking_for(patterns);
    app.state.prompt.remember(
        crate::prompt::HistoryKind::GitCommand,
        &asking_for.line(app.state.context.as_deref()),
    )?;
    *git.borrow_mut() = asking_for;
    app.rerender_screens()
}

/// The file a row is the header of.
fn file_of(target: &ItemData) -> Option<String> {
    let ItemData::Delta { diff, file_i, .. } = target else {
        return None;
    };

    let header = &diff.file_diffs[*file_i].header;
    let path = match header.status {
        crate::gitu_diff::Status::Deleted => &header.old_file,
        _ => &header.new_file,
    };

    Some(path.fmt(&diff.text).into_owned())
}

/// The git flag an answer asks for: `None` for no answer, which is to pass no
/// flag at all and leave the context to the command and git's config. An
/// answer that is neither a count nor the whole function isn't one, since a
/// flag that leaves no hunks leaves nothing to act on.
fn context_flag(answer: &str) -> Option<Option<Rc<str>>> {
    match answer {
        "" => Some(None),
        "W" | "w" => Some(Some(Rc::from("-W"))),
        lines if !lines.is_empty() && lines.chars().all(|c| c.is_ascii_digit()) => {
            Some(Some(Rc::from(format!("-U{lines}").as_str())))
        }
        _ => None,
    }
}

/// Fold the whole view down to its headings, or open all of it.
pub(crate) struct ToggleAllSections;
impl OpTrait for ToggleAllSections {
    fn get_action(&self, _target: &ItemData) -> Option<Action> {
        Some(Rc::new(|app, _term| {
            app.screen_mut().toggle_all_sections();
            Ok(())
        }))
    }

    fn display(&self, _state: &State) -> String {
        "Fold all".into()
    }
}

/// Show or hide the list of what a screen's own keymap does.
pub(crate) struct ToggleMenu;
impl OpTrait for ToggleMenu {
    fn get_action(&self, _target: &ItemData) -> Option<Action> {
        Some(Rc::new(|app: &mut App, _term: &mut Term| {
            let screen = app.screen_mut();
            screen.show_menu = !screen.show_menu;
            Ok(())
        }))
    }

    fn display(&self, state: &State) -> String {
        if state.screens.last().unwrap().show_menu {
            "Hide keys".into()
        } else {
            "Show keys".into()
        }
    }
}

/// Turn one of the configured renderer features on or off, re-rendering with
/// it. The diff is what changes, not the position in it: a row's identity is
/// its place in the patch, which no amount of re-rendering moves.
pub(crate) struct RendererFeatures;
impl OpTrait for RendererFeatures {
    fn get_action(&self, _target: &ItemData) -> Option<Action> {
        Some(Rc::new(|app: &mut App, term: &mut Term| {
            let offered = crate::diff_renderer::offered_features(
                &app.state.config.general.diff_renderer.features,
                &app.state.repo.config().map_err(Error::ReadGitConfig)?,
            )?;
            if offered.is_empty() {
                app.display_error("No renderer features are configured");
                return Ok(());
            }

            let mut cursor = 0;
            loop {
                let picker = PickerState::new("Features", feature_items(app, &offered), false)
                    .assigning_keys()
                    .with_cursor(cursor);
                match app.pick_or_set_key(term, picker)? {
                    None => return Ok(()),
                    Some(Picked::Item(picked)) => return toggle_feature(app, picked.display()),
                    Some(Picked::KeySet(key, picked)) => {
                        let feature = picked.display();
                        cursor = offered
                            .iter()
                            .position(|offered| offered == feature)
                            .unwrap_or(0);
                        set_feature_key(app, feature, key);
                    }
                }
            }
        }))
    }

    fn display(&self, _state: &State) -> String {
        "Features".into()
    }
}

/// Each feature, marked if it is on, beside its key if it has one.
fn feature_items(app: &App, offered: &[String]) -> Vec<PickerItem> {
    offered
        .iter()
        .map(|feature| {
            let mark = if app.state.features.contains(feature) {
                '●'
            } else {
                ' '
            };
            let key = app.state.feature_keys.get(feature).copied().unwrap_or(' ');
            PickerItem::new(
                format!("{mark} {key} {feature}"),
                PickerData::Item(feature.clone()),
            )
        })
        .collect()
}

pub(crate) fn toggle_feature(app: &mut App, feature: &str) -> Res<()> {
    app.state.features = toggled(&app.state.features, feature);
    app.rerender_screens()
}

/// Make `key` toggle `feature` at the top level, in this session and, by saving
/// it to the config file, the next. `feature`'s own key unsets it, and a key
/// bound already is refused.
fn set_feature_key(app: &mut App, feature: &str, key: char) {
    let key = if app.state.feature_keys.get(feature) == Some(&key) {
        None
    } else if app.state.config.bindings.binds_at_top_level(key) {
        app.display_error(format!("{key} is bound already"));
        return;
    } else {
        Some(key)
    };

    app.state
        .feature_keys
        .retain(|name, held| name != feature && Some(*held) != key);
    if let Some(key) = key {
        app.state.feature_keys.insert(feature.to_owned(), key);
    }

    if let Err(e) = crate::config_edit::set_feature_key(&app.state.config.path, feature, key) {
        app.display_error(e.to_string());
    }
}

/// `features` with `feature` removed if present and appended if not. Order is
/// otherwise kept, since delta resolves a conflict between two features in
/// favour of the later one.
fn toggled(features: &[String], feature: &str) -> Rc<[String]> {
    if features.iter().any(|held| held == feature) {
        return features
            .iter()
            .filter(|held| *held != feature)
            .cloned()
            .collect();
    }

    features
        .iter()
        .cloned()
        .chain([feature.to_owned()])
        .collect()
}

/// Name the commit under the cursor as the one [`App::pick_commit`] was after.
pub(crate) struct SelectCommit;
impl OpTrait for SelectCommit {
    fn get_action(&self, target: &ItemData) -> Option<Action> {
        let ItemData::Commit { oid, .. } = target else {
            return None;
        };
        let oid = oid.clone();

        Some(Rc::new(move |app: &mut App, _term: &mut Term| {
            app.state.picked_commit = Some(oid.clone());
            Ok(())
        }))
    }

    fn is_target_op(&self) -> bool {
        true
    }

    fn display(&self, _state: &State) -> String {
        "Select".into()
    }
}

pub(crate) struct MoveUp;
impl OpTrait for MoveUp {
    fn get_action(&self, _target: &ItemData) -> Option<Action> {
        Some(Rc::new(|app, _term| {
            app.screen_mut().select_previous(NavMode::Normal);
            Ok(())
        }))
    }

    fn display(&self, _state: &State) -> String {
        "Up".into()
    }
}

pub(crate) struct MoveDown;
impl OpTrait for MoveDown {
    fn get_action(&self, _target: &ItemData) -> Option<Action> {
        Some(Rc::new(|app, _term| {
            app.screen_mut().select_next(NavMode::Normal);
            Ok(())
        }))
    }

    fn display(&self, _state: &State) -> String {
        "Down".into()
    }
}

pub(crate) struct MoveDownLine;
impl OpTrait for MoveDownLine {
    fn get_action(&self, _target: &ItemData) -> Option<Action> {
        Some(Rc::new(|app, _term| {
            app.screen_mut().select_next(NavMode::IncludeSubLines);
            Ok(())
        }))
    }

    fn display(&self, _state: &State) -> String {
        "Down line".into()
    }
}

pub(crate) struct MoveUpLine;
impl OpTrait for MoveUpLine {
    fn get_action(&self, _target: &ItemData) -> Option<Action> {
        Some(Rc::new(|app, _term| {
            app.screen_mut().select_previous(NavMode::IncludeSubLines);
            Ok(())
        }))
    }

    fn display(&self, _state: &State) -> String {
        "Up line".into()
    }
}

/// Reach the selection out over another line, towards the end of the hunk or
/// back towards its start.
pub(crate) struct ExtendSelection(pub bool);
impl OpTrait for ExtendSelection {
    fn get_action(&self, _target: &ItemData) -> Option<Action> {
        let forwards = self.0;
        Some(Rc::new(move |app: &mut App, _term: &mut Term| {
            app.screen_mut().extend_selection(forwards);
            Ok(())
        }))
    }

    fn display(&self, _state: &State) -> String {
        if self.0 {
            "Select down".into()
        } else {
            "Select up".into()
        }
    }
}

pub(crate) struct MoveToScreenLine(pub usize);
impl OpTrait for MoveToScreenLine {
    fn get_action(&self, _target: &ItemData) -> Option<Action> {
        let screen_line = self.0;
        Some(Rc::new(move |app, _term| {
            app.screen_mut().move_cursor_to_screen_line(screen_line);
            Ok(())
        }))
    }

    fn display(&self, _state: &State) -> String {
        "Move to line".into()
    }
}

pub(crate) struct MoveNextSection;
impl OpTrait for MoveNextSection {
    fn get_action(&self, _target: &ItemData) -> Option<Action> {
        Some(Rc::new(|app, _term| {
            let depth = app.screen().get_selected_item().depth;
            app.screen_mut().select_next(NavMode::Siblings { depth });
            Ok(())
        }))
    }

    fn display(&self, _state: &State) -> String {
        "Next section".into()
    }
}

pub(crate) struct MovePrevSection;
impl OpTrait for MovePrevSection {
    fn get_action(&self, _target: &ItemData) -> Option<Action> {
        Some(Rc::new(|app, _term| {
            let depth = app.screen().get_selected_item().depth;
            app.screen_mut()
                .select_previous(NavMode::Siblings { depth });
            Ok(())
        }))
    }

    fn display(&self, _state: &State) -> String {
        "Prev section".into()
    }
}

pub(crate) struct MoveParentSection;
impl OpTrait for MoveParentSection {
    fn get_action(&self, _target: &ItemData) -> Option<Action> {
        Some(Rc::new(|app, _term| {
            let depth = app.screen().get_selected_item().depth.saturating_sub(1);
            app.screen_mut()
                .select_previous(NavMode::Siblings { depth });
            Ok(())
        }))
    }

    fn display(&self, _state: &State) -> String {
        "Parent section".into()
    }
}

pub(crate) struct HalfPageUp;
impl OpTrait for HalfPageUp {
    fn get_action(&self, _target: &ItemData) -> Option<Action> {
        Some(Rc::new(|app, _term| {
            app.screen_mut().half_page_up();
            Ok(())
        }))
    }

    fn display(&self, _state: &State) -> String {
        "Scroll half page up".into()
    }
}

pub(crate) struct HalfPageDown;
impl OpTrait for HalfPageDown {
    fn get_action(&self, _target: &ItemData) -> Option<Action> {
        Some(Rc::new(|app, _term| {
            app.screen_mut().half_page_down();
            Ok(())
        }))
    }

    fn display(&self, _state: &State) -> String {
        "Scroll half page down".into()
    }
}

pub(crate) struct FullPageUp;
impl OpTrait for FullPageUp {
    fn get_action(&self, _target: &ItemData) -> Option<Action> {
        Some(Rc::new(|app, _term| {
            app.screen_mut().full_page_up();
            Ok(())
        }))
    }

    fn display(&self, _state: &State) -> String {
        "Scroll page up".into()
    }
}

pub(crate) struct FullPageDown;
impl OpTrait for FullPageDown {
    fn get_action(&self, _target: &ItemData) -> Option<Action> {
        Some(Rc::new(|app, _term| {
            app.screen_mut().full_page_down();
            Ok(())
        }))
    }

    fn display(&self, _state: &State) -> String {
        "Scroll page down".into()
    }
}

pub(crate) struct ScrollViewUp;
impl OpTrait for ScrollViewUp {
    fn get_action(&self, _target: &ItemData) -> Option<Action> {
        Some(Rc::new(|app, _term| {
            app.close_menu();
            app.screen_mut().scroll_view_up(1);
            Ok(())
        }))
    }

    fn display(&self, _state: &State) -> String {
        "Scroll view up".into()
    }
}

pub(crate) struct ScrollViewDown;
impl OpTrait for ScrollViewDown {
    fn get_action(&self, _target: &ItemData) -> Option<Action> {
        Some(Rc::new(|app, _term| {
            app.close_menu();
            app.screen_mut().scroll_view_down(1);
            Ok(())
        }))
    }

    fn display(&self, _state: &State) -> String {
        "Scroll view down".into()
    }
}

pub(crate) struct MoveTop;
impl OpTrait for MoveTop {
    fn get_action(&self, _target: &ItemData) -> Option<Action> {
        Some(Rc::new(|app, _term| {
            app.screen_mut().move_cursor_to_top();
            Ok(())
        }))
    }

    fn display(&self, _state: &State) -> String {
        "Top".into()
    }
}

pub(crate) struct MoveBottom;
impl OpTrait for MoveBottom {
    fn get_action(&self, _target: &ItemData) -> Option<Action> {
        Some(Rc::new(|app, _term| {
            app.screen_mut().move_cursor_to_bottom();
            Ok(())
        }))
    }

    fn display(&self, _state: &State) -> String {
        "Bottom".into()
    }
}