1use anyhow::Result;
2use strum::IntoEnumIterator;
3use strum_macros::{Display, EnumIter, EnumString};
4
5use crate::app::Status;
6use crate::config::Bindings;
7use crate::event::EventAction;
8
9#[derive(Clone, Debug, Display, EnumString, EnumIter)]
14pub enum ActionMap {
15 Action,
16 Back,
17 Backspace,
18 Bulk,
19 Cd,
20 Chmod,
21 ClearFlags,
22 CliMenu,
23 CloudDrive,
24 Compress,
25 Context,
26 CopyContent,
27 CopyFilename,
28 CopyFilepath,
29 CopyPaste,
30 Cursor,
31 CutPaste,
32 Delete,
33 DeleteLeft,
34 DeleteLine,
35 DisplayFlagged,
36 End,
37 Enter,
38 Exec,
39 Filter,
40 FlagAll,
41 FlaggedToClipboard,
42 FlaggedFromClipboard,
43 FocusGoLeft,
44 FocusGoRight,
45 FocusGoDown,
46 FocusGoUp,
47 FuzzyFind,
48 FuzzyFindHelp,
49 FuzzyFindLine,
50 GoRoot,
51 GoStart,
52 Help,
53 History,
54 Home,
55 KeyHome,
56 Log,
57 MarksJump,
58 MarksNew,
59 MoveDown,
60 MoveLeft,
61 MoveRight,
62 MoveUp,
63 Mount,
64 NextThing,
65 NextWord,
66 NewDir,
67 NewFile,
68 Nothing,
69 NvimFilepicker,
70 NvimSetAddress,
71 OpenConfig,
72 OpenFile,
73 OpenAll,
74 PageDown,
75 PageUp,
76 Preview,
77 PreviousThing,
78 PreviousWord,
79 Quit,
80 RefreshIfNeeded,
81 RefreshView,
82 RegexMatch,
83 RemoteMount,
84 Rename,
85 ResetMode,
86 ReverseFlags,
87 Search,
88 SearchNext,
89 Shell,
90 ShellCommand,
91 TempMarksJump,
92 TempMarksNew,
93 TuiMenu,
94 Shortcut,
95 Sort,
96 Symlink,
97 SyncLTR,
98 Tab,
99 ToggleDisplayFull,
100 ToggleDualPane,
101 ToggleFlag,
102 ToggleFlagChildren,
103 ToggleHidden,
104 TogglePreviewSecond,
105 TrashEmpty,
106 TrashMoveFile,
107 TrashOpen,
108 TrashRestoreFile,
109 Tree,
110 TreeDepthDecr,
111 TreeDepthIncr,
112 TreeFold,
113 TreeFoldAll,
114 TreeUnFoldAll,
115 ToggleVisual,
116 Custom(String),
117}
118
119impl ActionMap {
120 pub fn matcher(&self, status: &mut Status, binds: &Bindings) -> Result<()> {
123 match self {
124 Self::Action => EventAction::action(status),
125 Self::Back => EventAction::back(status),
126 Self::Backspace => EventAction::backspace(status),
127 Self::Bulk => EventAction::bulk(status),
128 Self::Cd => EventAction::cd(status),
129 Self::Chmod => EventAction::chmod(status),
130 Self::ClearFlags => EventAction::clear_flags(status),
131 Self::CliMenu => EventAction::cli_menu(status),
132 Self::CloudDrive => EventAction::cloud_drive(status),
133 Self::Compress => EventAction::compress(status),
134 Self::Context => EventAction::context(status),
135 Self::CopyContent => EventAction::copy_content(status),
136 Self::CopyFilename => EventAction::copy_filename(status),
137 Self::CopyFilepath => EventAction::copy_filepath(status),
138 Self::CopyPaste => EventAction::copy_paste(status),
139 Self::Cursor => EventAction::cursor(status),
140 Self::CutPaste => EventAction::cut_paste(status),
141 Self::Delete => EventAction::delete(status),
142 Self::DeleteLeft => EventAction::delete_left(status),
143 Self::DeleteLine => EventAction::delete_line(status),
144 Self::DisplayFlagged => EventAction::display_flagged(status),
145 Self::End => EventAction::end(status),
146 Self::Enter => EventAction::enter(status, binds),
147 Self::Exec => EventAction::exec(status),
148 Self::Filter => EventAction::filter(status),
149 Self::FlagAll => EventAction::flag_all(status),
150 Self::FlaggedToClipboard => EventAction::flagged_to_clipboard(status),
151 Self::FlaggedFromClipboard => EventAction::flagged_from_clipboard(status),
152 Self::FocusGoLeft => EventAction::focus_go_left(status),
153 Self::FocusGoRight => EventAction::focus_go_right(status),
154 Self::FocusGoDown => EventAction::focus_go_down(status),
155 Self::FocusGoUp => EventAction::focus_go_up(status),
156 Self::FuzzyFind => EventAction::fuzzyfind(status),
157 Self::FuzzyFindHelp => EventAction::fuzzyfind_help(status, binds),
158 Self::FuzzyFindLine => EventAction::fuzzyfind_line(status),
159 Self::GoRoot => EventAction::go_root(status),
160 Self::GoStart => EventAction::go_start(status),
161 Self::Help => EventAction::help(status, binds),
162 Self::History => EventAction::history(status),
163 Self::Home => EventAction::home(status),
164 Self::KeyHome => EventAction::key_home(status),
165 Self::Log => EventAction::log(status),
166 Self::MarksJump => EventAction::marks_jump(status),
167 Self::MarksNew => EventAction::marks_new(status),
168 Self::Mount => EventAction::mount(status),
169 Self::MoveDown => EventAction::move_down(status),
170 Self::MoveLeft => EventAction::move_left(status),
171 Self::MoveRight => EventAction::move_right(status),
172 Self::MoveUp => EventAction::move_up(status),
173 Self::NextThing => EventAction::next_thing(status),
174 Self::NextWord => EventAction::next_word(status),
175 Self::NewDir => EventAction::new_dir(status),
176 Self::NewFile => EventAction::new_file(status),
177 Self::NvimFilepicker => EventAction::nvim_filepicker(status),
178 Self::NvimSetAddress => EventAction::set_nvim_server(status),
179 Self::OpenConfig => EventAction::open_config(status),
180 Self::OpenFile => EventAction::open_file(status),
181 Self::OpenAll => EventAction::open_all(status),
182 Self::PageDown => EventAction::page_down(status),
183 Self::PageUp => EventAction::page_up(status),
184 Self::Preview => EventAction::preview(status),
185 Self::PreviousThing => EventAction::previous_thing(status),
186 Self::PreviousWord => EventAction::previous_word(status),
187 Self::Quit => EventAction::quit(status),
188 Self::RefreshIfNeeded => EventAction::refresh_if_needed(status),
189 Self::RefreshView => EventAction::refresh_view(status),
190 Self::RegexMatch => EventAction::regex_match(status),
191 Self::RemoteMount => EventAction::remote_mount(status),
192 Self::Rename => EventAction::rename(status),
193 Self::ResetMode => EventAction::reset_mode(status),
194 Self::ReverseFlags => EventAction::reverse_flags(status),
195 Self::Search => EventAction::search(status),
196 Self::SearchNext => EventAction::search_next(status),
197 Self::Shell => EventAction::shell(status),
198 Self::ShellCommand => EventAction::shell_command(status),
199 Self::Shortcut => EventAction::shortcut(status),
200 Self::Sort => EventAction::sort(status),
201 Self::Symlink => EventAction::symlink(status),
202 Self::SyncLTR => EventAction::sync_ltr(status),
203 Self::Tab => EventAction::tab(status),
204 Self::TempMarksJump => EventAction::temp_marks_jump(status),
205 Self::TempMarksNew => EventAction::temp_marks_new(status),
206 Self::ToggleDisplayFull => EventAction::toggle_display_full(status),
207 Self::ToggleDualPane => EventAction::toggle_dualpane(status),
208 Self::ToggleFlag => EventAction::toggle_flag(status),
209 Self::ToggleFlagChildren => EventAction::toggle_flag_children(status),
210 Self::ToggleHidden => EventAction::toggle_hidden(status),
211 Self::TogglePreviewSecond => EventAction::toggle_preview_second(status),
212 Self::TrashEmpty => EventAction::trash_empty(status),
213 Self::TrashMoveFile => EventAction::trash_move_file(status),
214 Self::TrashOpen => EventAction::trash_open(status),
215 Self::TrashRestoreFile => EventAction::trash_restore(status),
216 Self::Tree => EventAction::tree(status),
217 Self::TreeDepthDecr => EventAction::tree_depth_decr(status),
218 Self::TreeDepthIncr => EventAction::tree_depth_incr(status),
219 Self::TreeFold => EventAction::tree_fold(status),
220 Self::TreeFoldAll => EventAction::tree_fold_all(status),
221 Self::TreeUnFoldAll => EventAction::tree_unfold_all(status),
222 Self::TuiMenu => EventAction::tui_menu(status),
223 Self::ToggleVisual => EventAction::visual(status),
224
225 Self::Custom(string) => EventAction::custom(status, string),
226
227 Self::Nothing => Ok(()),
228 }
229 }
230
231 pub fn description(&self) -> &'static str {
232 match self {
233 Self::Action => "ACTION",
234 Self::Back => "move back to previous dir",
235 Self::Backspace => "delete previous char",
236 Self::Bulk => "BULK",
237 Self::Cd => "CD",
238 Self::Chmod => "CHMOD ",
239 Self::ClearFlags => "clear flags",
240 Self::CliMenu => "CLI APPS",
241 Self::Compress => "compress into an archive",
242 Self::Context => "CONTEXT",
243 Self::CopyContent => "copy text file content to clipbloard",
244 Self::CopyFilename => "copy filename to clipboard",
245 Self::CopyFilepath => "copy filepath to clipboard",
246 Self::CopyPaste => "copy to current dir",
247 Self::CloudDrive => "navigate into a cloud drive",
248 Self::Cursor => "select text from terminal display",
249 Self::Custom(_) => "custom command",
250 Self::CutPaste => "move to current dir",
251 Self::Delete => "delete files permanently",
252 Self::DeleteLeft => "delete a word to the left",
253 Self::DeleteLine => "delete the whole line / Sync left tab from right tab",
254 Self::DisplayFlagged => "FLAGGED",
255 Self::End => "go to last line",
256 Self::Enter => "Execute mode then NORMAL",
257 Self::Exec => "OPEN WITH ",
258 Self::Filter => "FILTER ",
259 Self::FlagAll => "flag all",
260 Self::FlaggedFromClipboard => "flag existing files from primary clipboard",
261 Self::FlaggedToClipboard => "copy flagged files to primary clipbloard",
262 Self::FocusGoDown => "move focus to bottom",
263 Self::FocusGoLeft => "move focus to left",
264 Self::FocusGoRight => "move focus to right",
265 Self::FocusGoUp => "move focus to up",
266 Self::FuzzyFind => "fuzzy finder for file",
267 Self::FuzzyFindHelp => "fuzzy finder from help",
268 Self::FuzzyFindLine => "fuzzy finder for line",
269 Self::GoRoot => "move to root (/)",
270 Self::GoStart => "move to starting point",
271 Self::Help => "help",
272 Self::History => "HISTORY",
273 Self::Home => "move to $HOME",
274 Self::KeyHome => "go to first line",
275 Self::Log => "open the logs",
276 Self::MarksJump => "MARKS: Jump",
277 Self::MarksNew => "MARKS: Save",
278 Self::Mount => "MOUNTS",
279 Self::MoveDown => "one line down",
280 Self::MoveLeft => "cd to parent directory ",
281 Self::MoveRight => "cd to child directory",
282 Self::MoveUp => "one line up ",
283 Self::NewDir => "NEWDIR ",
284 Self::NewFile => "NEWFILE",
285 Self::NextThing => "select next 'thing'",
286 Self::NextWord => "go to next word in input",
287 Self::Nothing => "do nothing",
288 Self::NvimFilepicker => "open in current nvim session",
289 Self::NvimSetAddress => "setup the nvim rpc address",
290 Self::OpenAll => "open all flagged files",
291 Self::OpenConfig => "open the config file",
292 Self::OpenFile => {
293 "open the selected file with :
294 - default Self::Default
295 - audio Self::Audio
296 - images Self::Bitmap
297 - office Self::Office
298 - pdf, ebooks Self::Readable
299 - text Self::Text
300 - video Self::Video
301 - vectorials Self::Vectorial
302 - compressed files are decompressed
303 - iso images are mounted"
304 }
305 Self::PageDown => "10 lines down",
306 Self::PageUp => "10 lines up",
307 Self::Preview => "preview this file",
308 Self::PreviousThing => "select previous 'thing'",
309 Self::PreviousWord => "go to previous word in input",
310 Self::Quit => "quit",
311 Self::RefreshIfNeeded => "refresh the terminal if we have to",
312 Self::RefreshView => "refresh view",
313 Self::RegexMatch => "REGEXMATCH",
314 Self::RemoteMount => "MOUNT REMOTE PATH",
315 Self::Rename => "RENAME",
316 Self::ResetMode => "NORMAL",
317 Self::ReverseFlags => "reverse flags",
318 Self::Search => "SEARCH",
319 Self::SearchNext => "search next matching element",
320 Self::Shell => "shell in current directory",
321 Self::ShellCommand => "run a shell command",
322 Self::Shortcut => "SHORTCUT",
323 Self::Sort => "SORT",
324 Self::Symlink => "symlink to current dir",
325 Self::SyncLTR => "Sync right tab from left tab path",
326 Self::TempMarksJump => "TEMP MARKS: Jump",
327 Self::TempMarksNew => "TEMP MARKS: Save",
328 Self::Tab => "cycle tab",
329 Self::ToggleDisplayFull => "toggle full metadata display of files",
330 Self::ToggleDualPane => "toggle dual pane - if the width is sufficiant",
331 Self::ToggleFlag => "toggle flag on a file",
332 Self::ToggleFlagChildren => "toggle flag on every children file of a directory",
333 Self::ToggleHidden => "toggle hidden",
334 Self::TogglePreviewSecond => "toggle a preview on the second pane",
335 Self::TrashEmpty => "Empty the trash",
336 Self::TrashMoveFile => "move to trash",
337 Self::TrashOpen => "Open the trash (enter to restore, del clear)",
338 Self::TrashRestoreFile => "restore the trash file",
339 Self::Tree => "Toggle tree mode",
340 Self::TreeDepthDecr => "Decrease depth of tree",
341 Self::TreeDepthIncr => "Increase depth of tree",
342 Self::TreeFold => "Fold a node",
343 Self::TreeFoldAll => "Fold every node",
344 Self::TreeUnFoldAll => "Unfold every node",
345 Self::TuiMenu => "TUI APPS",
346 Self::ToggleVisual => "Visual selection",
347 }
348 }
349
350 pub fn actions_matching(key: String) -> Vec<String> {
351 Self::iter()
352 .filter(|action| action.to_string().to_lowercase().contains(&key))
353 .map(|action| action.to_string())
354 .collect()
355 }
356}