1use crate::errors::ConfError;
8
9macro_rules! Internals {
10 (
11 $($name:ident: $description:literal $need_path:literal,)*
12 ) => {
13 #[derive(Debug, Clone, Copy, PartialEq)]
14 #[allow(non_camel_case_types)]
15 pub enum Internal {
16 $($name,)*
17 }
18 impl Internal {
19 pub fn try_from(verb: &str) -> Result<Internal, ConfError> {
20 use Internal::*;
21 match verb {
22 $(stringify!($name) => Ok($name),)*
23 _ => Err(ConfError::UnknownInternal{ verb: verb.to_string() }),
24 }
25 }
26 }
27 impl Internal {
28 pub fn name(self) -> &'static str {
29 use Internal::*;
30 match self {
31 $($name => stringify!($name),)*
32 }
33 }
34 pub fn description(self) -> &'static str {
35 use Internal::*;
36 match self {
37 $($name => $description,)*
38 }
39 }
40 pub fn need_path(self) -> bool {
41 use Internal::*;
42 match self {
43 $($name => $need_path,)*
44 }
45 }
46 }
47 }
48}
49
50Internals! {
53 apply_flags: "apply flags (eg `-sd` to show sizes and dates)" false,
54 back: "revert to the previous state (mapped to *esc*)" false,
55 default_layout: "restore default panel sizes" false,
56 clear_output: "clear the --verb-output file" false,
57 clear_stage: "empty the staging area" false,
58 close_panel_cancel: "close the panel, not using the selected path" false,
59 close_panel_ok: "close the panel, validating the selected path" false,
60 close_preview: "close the preview panel" false,
61 close_staging_area: "close the staging area panel" false,
62 copy_line: "copy selected line (in tree or preview)" true,
63 copy_path: "copy path to system clipboard" true,
64 escape: "escape from edition, completion, page, etc." false,
65 filesystems: "list mounted filesystems" false,
66 focus: "display the directory (mapped to *enter*)" true,
67 focus_staging_area_no_open: "focus the staging area if already open" false,
68 help: "display broot's help" false,
69 input_clear: "empty the input" false,
70 input_del_char_below: "delete the char left at the cursor's position" false,
71 input_del_char_left: "delete the char left of the cursor" false,
72 input_del_word_left: "delete the word left of the cursor" false,
73 input_del_word_right: "delete the word right of the cursor" false,
74 input_go_left: "move the cursor to the left" false,
75 input_go_right: "move the cursor to the right" false,
76 input_go_to_end: "move the cursor to the end of input" false,
77 input_go_to_start: "move the cursor to the start of input" false,
78 input_go_word_left: "move the cursor one word to the left" false,
79 input_go_word_right: "move the cursor one word to the right" false,
80 input_paste: "paste the clipboard content into the input" false,
81 input_selection_copy: "copy the selected part of the input into the selection" false,
82 input_selection_cut: "cut the selected part of the input into the selection" false,
83 line_down: "move one line down" false,
84 line_down_no_cycle: "move one line down" false,
85 line_up: "move one line up" false,
86 line_up_no_cycle: "move one line up" false,
87 mode_command: "enter the command mode" false,
88 mode_input: "enter the input mode" false,
89 move_panel_divider: "move a panel divider" false,
90 next_dir: "select the next directory" false,
91 next_match: "select the next match" false,
92 next_same_depth: "select the next file at the same depth" false,
93 no_sort: "don't sort" false,
94 open_leave: "open file or directory according to OS (quit broot)" true,
95 open_preview: "open the preview panel" true,
96 open_staging_area: "open the staging area" false,
97 open_stay: "open file or directory according to OS (stay in broot)" true,
98 open_stay_filter: "display the directory, keeping the current pattern" true,
99 open_trash: "show the content of the trash" false,
100 page_down: "scroll one page down" false,
101 page_up: "scroll one page up" false,
102 panel_left: "focus or open panel on left" false,
103 panel_left_no_open: "focus panel on left" false,
104 panel_right: "focus or open panel on right" false,
105 panel_right_no_open: "focus panel on right" false,
106 parent: "move to the parent directory" false,
107 preview_binary: "preview the selection as binary" true,
108 preview_image: "preview the selection as image" true,
109 preview_text: "preview the selection as text" true,
110 preview_tty: "preview the selection as tty" true,
111 previous_dir: "select the previous directory" false,
112 previous_match: "select the previous match" false,
113 previous_same_depth: "select the previous file at the same depth" false,
114 print_path: "print path and leaves broot" true,
115 print_relative_path: "print relative path and leaves broot" true,
116 print_tree: "print tree and leaves broot" true,
117 quit: "quit Broot" false,
118 refresh: "refresh tree and clear size cache" false,
119 delete_trashed_file: "irreversibly delete a file which is in the trash" false,
120 restore_trashed_file: "restore a file which is in the trash" false,
121 purge_trash: "irreversibly delete the trash's content" false,
122 root_down: "move tree root down" true,
123 root_up: "move tree root up" true,
124 select: "select a file by path" true,
125 show: "reveal and select a file by path" true,
126 select_first: "select the first item" false,
127 select_last: "select the last item" false,
128 set_panel_width: "set the width of a panel" false,
129 set_syntax_theme: "set the theme of code preview" false,
130 sort_by_count: "sort by count" false,
131 sort_by_date: "sort by date" false,
132 sort_by_size: "sort by size" false,
133 sort_by_type: "sort by type" false,
134 sort_by_type_dirs_first: "sort by type, dirs first" false,
135 sort_by_type_dirs_last: "sort by type, dirs last" false,
136 stage: "add selection to staging area" true,
137 stage_all_directories: "stage all matching directories" true,
138 stage_all_files: "stage all matching files" true,
139 start_end_panel: "either open or close an additional panel" true,
140 toggle_counts: "toggle showing number of files in directories" false,
141 toggle_dates: "toggle showing last modified dates" false,
142 toggle_device_id: "toggle showing device id" false,
143 toggle_files: "toggle showing files (or just folders)" false,
144 toggle_git_file_info: "toggle display of git file information" false,
145 toggle_git_ignore: "toggle use of .gitignore and .ignore" false,
146 toggle_git_status: "toggle showing only files relevant for git status" false,
147 toggle_hidden: "toggle showing hidden files" false,
148 toggle_ignore: "toggle use of .gitignore and .ignore" false,
149 toggle_perm: "toggle showing file permissions" false,
150 toggle_preview: "open/close the preview panel" false,
151 toggle_root_fs: "toggle showing filesystem info on top" false,
152 set_max_depth: "set the maximum directory depth shown" false,
153 unset_max_depth: "clear the max_depth" false,
154 toggle_second_tree: "toggle display of a second tree panel" true,
155 toggle_sizes: "toggle showing sizes" false,
156 toggle_stage: "add or remove selection to staging area" true,
157 toggle_staging_area: "open/close the staging area panel" false,
158 toggle_tree: "toggle showing more than one level of the tree" true,
159 toggle_trim_root: "toggle removing nodes at first level too" false,
160 total_search: "search again but on all children" false,
161 search_again: "either put back last search, or search deeper" false,
162 trash: "move file to system trash" true,
163 unstage: "remove selection from staging area" true,
164 up_tree: "focus the parent of the current root" true,
165 write_output: "write the argument to the --verb-output file" false,
166 toggle_watch: "toggle watching the current root for changes" false,
167
168 }
170
171impl Internal {
172 pub fn invocation_pattern(self) -> &'static str {
173 match self {
174 Self::apply_flags => r"-(?P<flags>\w+)?",
175 Self::focus => r"focus (?P<path>.*)?",
176 Self::select => r"select (?P<path>.*)?",
177 Self::show => r"show (?P<path>.*)?",
178 Self::line_down => r"line_down (?P<count>\d*)?",
179 Self::line_up => r"line_up (?P<count>\d*)?",
180 Self::line_down_no_cycle => r"line_down_no_cycle (?P<count>\d*)?",
181 Self::line_up_no_cycle => r"line_up_no_cycle (?P<count>\d*)?",
182 Self::move_panel_divider => r"move_panel_divider (?P<idx>\d+) (?P-?<dx>\d+)",
183 Self::set_panel_width => r"set_panel_width (?P<idx>\d+) (?P<width>\d+)",
184 Self::set_max_depth => r"set_max_depth (?P<depth>\d+)",
185 Self::set_syntax_theme => r"set_syntax_theme {theme:theme}",
186 Self::write_output => r"write_output (?P<line>.*)",
187 _ => self.name(),
188 }
189 }
190 pub fn exec_pattern(self) -> &'static str {
191 match self {
192 Self::apply_flags => r"apply_flags {flags}",
193 Self::focus => r"focus {path}",
194 Self::line_down => r"line_down {count}",
195 Self::line_up => r"line_up {count}",
196 Self::line_down_no_cycle => r"line_down_no_cycle {count}",
197 Self::line_up_no_cycle => r"line_up_no_cycle {count}",
198 Self::move_panel_divider => r"move_panel_divider {idx} {dx}",
199 Self::set_panel_width => r"set_panel_width {idx} {width}",
200 Self::write_output => r"write_output {line}",
201 _ => self.name(),
202 }
203 }
204 pub fn needs_selection(
205 self,
206 arg: &Option<String>,
207 ) -> bool {
208 match self {
209 Internal::focus => arg.is_none(),
210 _ => self.need_path(),
211 }
212 }
213 pub fn is_input_related(self) -> bool {
214 match self {
215 Self::input_clear => true,
216 Self::input_del_char_below => true,
217 Self::input_del_char_left => true,
218 Self::input_del_word_left => true,
219 Self::input_del_word_right => true,
220 Self::input_go_left => true,
221 Self::input_go_right => true,
222 Self::input_go_to_end => true,
223 Self::input_go_to_start => true,
224 Self::input_go_word_left => true,
225 Self::input_go_word_right => true,
226 Self::input_paste => true,
227 Self::input_selection_copy => true,
228 Self::input_selection_cut => true,
229 _ => false,
230 }
231 }
232}