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
use strfmt::strfmt;

use crate::fm_error::FmResult;
use crate::keybindings::Bindings;

/// Help message to be displayed when help key is pressed.
/// Default help key is `'h'`.

static HELP_TO_FORMAT: &str = "
{Quit}:      quit
{Help}:      help

- Navigation -
{MoveLeft}:           cd to parent directory 
{MoveRight}:          cd to child directory
{MoveUp}:             one line up  
{MoveDown}:           one line down
{KeyHome}:           go to first line
{End}:            go to last line
{PageUp}:         10 lines up
{PageDown}:       10 lines down
{Tab}:            cycle tab

- Actions -
{ToggleDualPane}:      toggle dual pane - if the width is sufficiant
{ToggleHidden}:      toggle hidden
{Shell}:      shell in current directory
{OpenFile}:      open the selected file
{NvimFilepicker}:      open in current nvim session
{Preview}:      preview this file
{Thumbnail}:      display a thumbnail of an image
{Back}:      move back to previous dir
{Home}:      move to $HOME
{MarksNew}:      mark current path
{MarksJump}:     jump to a mark
{DisplayFull}:      toggle metadata on files
{SearchNext}:      Search next matching element
{FuzzyFind}:      fuzzy finder
{RefreshView}:      refresh view
{CopyFilename}:      copy filename to clipboard
{CopyFilepath}:      copy filepath to clipboard
{DragNDrop}:       dragon-drop selected file

- Action on flagged files - 
{ToggleFlag}:      toggle flag on a file 
{FlagAll}:      flag all
{ClearFlags}:      clear flags
{ReverseFlags}:      reverse flags
{Symlink}:      symlink files
{Bulkrename}:      bulkrename files
{CopyPaste}:      copy to current dir
{CutPaste}:      move to current dir
{DeleteFile}:      delete files permanently
{TrashMoveFile}:      move to trash

- Trash -
{TrashOpen}:       Open the trash (enter to restore, del clear)
{TrashEmpty}:       Empty the trash

- MODES - 
{Chmod}:      CHMOD 
{Exec}:      EXEC 
{NewDir}:      NEWDIR 
{NewFile}:      NEWFILE
{Rename}:      RENAME
{Goto}:      GOTO
{RegexMatch}:      REGEXMATCH
{Jump}:      JUMP
{Sort}:      SORT
{History}:      HISTORY
{Shortcut}:      SHORTCUT
{Search}:      SEARCH
{Filter}:      FILTER 
    (by name \"n name\", by ext \"e ext\", only directories d or all for reset)
{Enter}:  Execute mode then NORMAL
{ModeNormal}:    NORMAL
";

/// Holds the help string, formated with current keybindings.
pub struct Help {
    /// The help string, formated with current keybindings.
    pub help: String,
}

impl Help {
    /// Creates an Help instance from keybindings.
    /// If multiple keybindings are bound to the same action, the last one
    /// is displayed.
    pub fn from_keybindings(binds: &Bindings) -> FmResult<Self> {
        let help = strfmt(HELP_TO_FORMAT, &binds.keybind_reversed())?;
        Ok(Self { help })
    }
}