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
|
use std::fmt;
use crate::completion::CompletionKind;
/// Different kind of mark actions.
/// Either we jump to an existing mark or we save current path to a mark.
/// In both case, we'll have to listen to the next char typed.
#[derive(Clone)]
pub enum MarkAction {
/// Jump to a selected mark (ie a path associated to a char)
Jump,
/// Creates a new mark (a path associated to a char)
New,
}
/// Different kind of last edition command received requiring a confirmation.
/// Copy, move and delete require a confirmation to prevent big mistakes.
#[derive(Clone, Copy, Debug)]
pub enum ConfirmedAction {
/// Copy flagged files
Copy,
/// Delete flagged files
Delete,
/// Move flagged files
Move,
}
impl ConfirmedAction {
/// Offset before the cursor.
/// Since we ask the user confirmation, we need to know how much space
/// is needed.
pub fn cursor_offset(&self) -> usize {
match *self {
Self::Copy => 25,
Self::Delete => 21,
Self::Move => 25,
}
}
}
impl std::fmt::Display for ConfirmedAction {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Self::Delete => write!(f, "Delete files :"),
Self::Move => write!(f, "Move files here :"),
Self::Copy => write!(f, "Copy files here :"),
}
}
}
#[derive(Clone)]
pub enum InputKind {
/// Rename the selected file
Rename,
/// Change permissions of the selected file
Chmod,
/// Touch a new file
Newfile,
/// Mkdir a new directory
Newdir,
/// Flag files matching a regex
RegexMatch,
/// Change the type of sort
Sort,
/// Jump to a saved mark
Marks(MarkAction),
/// Filter by extension, name, directory or no filter
Filter,
}
/// Different mode in which the application can be.
/// It dictates the reaction to event and what to display.
#[derive(Clone)]
pub enum Mode {
/// Default mode: display the files
Normal,
/// We'll be able to complete the input string with
/// different kind of completed items (exec, goto, search)
InputCompleted(CompletionKind),
/// Display the help
Jump,
/// Confirmation is required before modification is made to existing files :
/// delete, move, copy
NeedConfirmation(ConfirmedAction),
/// Preview a file content
Preview,
/// Display a sort of stack of visited directories
History,
/// Display predefined shortcuts
Shortcut,
/// Modes requiring an input that can't be completed
InputSimple(InputKind),
}
impl fmt::Display for Mode {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Mode::Normal => write!(f, "Normal: "),
Mode::InputSimple(InputKind::Rename) => write!(f, "Rename: "),
Mode::InputSimple(InputKind::Chmod) => write!(f, "Chmod: "),
Mode::InputSimple(InputKind::Newfile) => write!(f, "Newfile: "),
Mode::InputSimple(InputKind::Newdir) => write!(f, "Newdir: "),
Mode::InputSimple(InputKind::RegexMatch) => write!(f, "Regex: "),
Mode::InputSimple(InputKind::Sort) => write!(f, "Sort: Kind Name Modif Size Ext Rev :"),
Mode::InputSimple(InputKind::Marks(_)) => write!(f, "Marks jump:"),
Mode::InputSimple(InputKind::Filter) => write!(f, "Filter: "),
Mode::InputCompleted(CompletionKind::Exec) => write!(f, "Exec: "),
Mode::InputCompleted(CompletionKind::Goto) => write!(f, "Goto : "),
Mode::InputCompleted(CompletionKind::Search) => write!(f, "Search: "),
Mode::InputCompleted(CompletionKind::Nothing) => write!(f, "Nothing: "),
Mode::Jump => write!(f, "Jump : "),
Mode::History => write!(f, "History :"),
Mode::NeedConfirmation(_) => write!(f, "Y/N :"),
Mode::Preview => write!(f, "Preview : "),
Mode::Shortcut => write!(f, "Shortcut :"),
}
}
}
|