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
//! Event handling for the TUI.
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers, MouseButton, MouseEvent, MouseEventKind};
/// Key action that can be performed in the TUI.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum KeyAction {
// Navigation
MoveUp,
MoveDown,
MoveLeft,
MoveRight,
JumpToTop,
JumpToBottom,
PageUp,
PageDown,
// Tree operations
#[allow(dead_code)]
Expand,
#[allow(dead_code)]
Collapse,
ToggleExpand,
// Directory navigation
DrillDown,
NavigateBack,
/// Open file with configured opener (Enter on file).
#[allow(dead_code)]
OpenFile,
// Selection
/// Toggle mark on current item (Space).
ToggleMark,
/// Enter visual selection mode (Shift+V).
EnterVisual,
/// Clear all marks.
ClearMarks,
// Clipboard operations (vim-style)
/// Yank (copy) marked/current to clipboard.
Yank,
/// Cut (move) marked/current to clipboard.
Cut,
/// Paste from clipboard to current directory.
Paste,
// File operations
/// Delete marked/current items (with confirmation).
Delete,
/// Rename current item.
Rename,
/// Create new file.
CreateFile,
/// Create new directory.
CreateDirectory,
/// Create directory and navigate into it (like zsh's `take`).
Take,
/// Undo last operation.
Undo,
// UI toggles
ToggleDetails,
ToggleHelp,
ToggleTheme,
/// Toggle between tree and miller layout.
ToggleLayout,
/// Cycle preview mode (auto/text/hex/metadata).
CyclePreviewMode,
/// Open settings modal.
OpenSettings,
// Other actions
Refresh,
Search,
Sort,
ReverseSort,
CommandMode,
/// Go to a specific directory (opens path input).
GoTo,
// Confirmation
/// Explicit confirmation action (e.g. mapped from 'y' via dedicated confirm logic).
#[allow(dead_code)]
Confirm,
Cancel,
// View switching (for View enum: Explorer, Duplicates, Age, Errors)
NextView,
PrevView,
// Bookmarks
/// Set a bookmark (m<key>).
SetBookmark,
/// Jump to a bookmark ('<key>).
JumpToBookmark,
/// Show bookmark list modal.
ShowBookmarkList,
// Directory tabs (multiple directory contexts)
/// Create a new directory tab.
NewDirTab,
/// Close the current directory tab.
CloseDirTab,
/// Switch to next directory tab.
NextDirTab,
/// Switch to previous directory tab.
PrevDirTab,
/// Switch to directory tab 1-9 (Alt+1 through Alt+9).
DirTab(u8),
// Application
Quit,
ForceQuit,
// No action
None,
}
/// Mouse action that can be performed in the TUI.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MouseAction {
/// Left click at a position.
Click { x: u16, y: u16 },
/// Double click at a position.
/// Reserved for future double-click detection with timing logic.
#[allow(dead_code)]
DoubleClick { x: u16, y: u16 },
/// Right click at a position.
RightClick { x: u16, y: u16 },
/// Scroll up at a position.
ScrollUp { x: u16, y: u16 },
/// Scroll down at a position.
ScrollDown { x: u16, y: u16 },
/// Drag started at a position.
/// Reserved for future drag-and-drop support.
#[allow(dead_code)]
DragStart { x: u16, y: u16 },
/// Drag continued to a position.
DragTo { x: u16, y: u16 },
/// Drag ended.
DragEnd,
/// No action.
None,
}
impl MouseAction {
/// Convert a mouse event to an action.
pub fn from_mouse_event(event: MouseEvent) -> Self {
let x = event.column;
let y = event.row;
match event.kind {
MouseEventKind::Down(MouseButton::Left) => MouseAction::Click { x, y },
MouseEventKind::Down(MouseButton::Right) => MouseAction::RightClick { x, y },
MouseEventKind::Up(_) => MouseAction::DragEnd,
MouseEventKind::Drag(MouseButton::Left) => MouseAction::DragTo { x, y },
MouseEventKind::ScrollUp => MouseAction::ScrollUp { x, y },
MouseEventKind::ScrollDown => MouseAction::ScrollDown { x, y },
_ => MouseAction::None,
}
}
}
impl KeyAction {
/// Convert a key event to an action.
pub fn from_key_event(event: KeyEvent) -> Self {
match (event.code, event.modifiers) {
// Quit - only 'q' quits, Esc is for clearing selection/clipboard
(KeyCode::Char('q'), KeyModifiers::NONE) => KeyAction::Quit,
(KeyCode::Char('c'), KeyModifiers::CONTROL) => KeyAction::ForceQuit,
// Cancel/Clear - Esc clears selection, clipboard, or closes dialogs
(KeyCode::Esc, _) => KeyAction::Cancel,
// Navigation - vim style
(KeyCode::Char('j'), KeyModifiers::NONE) => KeyAction::MoveDown,
(KeyCode::Char('k'), KeyModifiers::NONE) => KeyAction::MoveUp,
(KeyCode::Char('h'), KeyModifiers::NONE) => KeyAction::MoveLeft,
(KeyCode::Char('l'), KeyModifiers::NONE) => KeyAction::MoveRight,
// Navigation - arrow keys (without modifiers; Ctrl+arrows for tabs)
(KeyCode::Down, KeyModifiers::NONE) => KeyAction::MoveDown,
(KeyCode::Up, KeyModifiers::NONE) => KeyAction::MoveUp,
(KeyCode::Left, KeyModifiers::NONE) => KeyAction::MoveLeft,
(KeyCode::Right, KeyModifiers::NONE) => KeyAction::MoveRight,
// Jump
(KeyCode::Char('g'), KeyModifiers::NONE) => KeyAction::JumpToTop,
(KeyCode::Char('G'), KeyModifiers::SHIFT) => KeyAction::JumpToBottom,
(KeyCode::Home, _) => KeyAction::JumpToTop,
(KeyCode::End, _) => KeyAction::JumpToBottom,
// Page navigation
(KeyCode::PageUp, _) => KeyAction::PageUp,
(KeyCode::PageDown, _) => KeyAction::PageDown,
(KeyCode::Char('u'), KeyModifiers::CONTROL) => KeyAction::PageUp,
(KeyCode::Char('d'), KeyModifiers::CONTROL) => KeyAction::PageDown,
// Selection and marking
(KeyCode::Char(' '), KeyModifiers::NONE) => KeyAction::ToggleMark,
(KeyCode::Char('V'), KeyModifiers::SHIFT) => KeyAction::EnterVisual,
(KeyCode::Char('u'), KeyModifiers::NONE) => KeyAction::ClearMarks,
// Tree expand/collapse with 'o'
(KeyCode::Char('o'), KeyModifiers::NONE) => KeyAction::ToggleExpand,
// Clipboard operations (vim-style)
(KeyCode::Char('y'), KeyModifiers::NONE) => KeyAction::Yank,
(KeyCode::Char('x'), KeyModifiers::NONE) => KeyAction::Cut,
(KeyCode::Char('p'), KeyModifiers::NONE) => KeyAction::Paste,
// File operations
(KeyCode::Char('d'), KeyModifiers::NONE) => KeyAction::Delete,
(KeyCode::Char('D'), KeyModifiers::SHIFT) => KeyAction::Delete,
(KeyCode::Delete, _) => KeyAction::Delete,
(KeyCode::Char('r'), KeyModifiers::NONE) => KeyAction::Rename,
(KeyCode::Char('a'), KeyModifiers::NONE) => KeyAction::CreateFile,
(KeyCode::Char('A'), KeyModifiers::SHIFT) => KeyAction::CreateDirectory,
(KeyCode::Char('T'), KeyModifiers::SHIFT) => KeyAction::Take,
// Undo
(KeyCode::Char('z'), KeyModifiers::CONTROL) => KeyAction::Undo,
// UI toggles
(KeyCode::Char('i'), KeyModifiers::NONE) => KeyAction::ToggleDetails,
(KeyCode::Char('?'), KeyModifiers::NONE) => KeyAction::ToggleHelp,
(KeyCode::Char('t'), KeyModifiers::NONE) => KeyAction::ToggleTheme,
(KeyCode::Char('P'), KeyModifiers::SHIFT) => KeyAction::CyclePreviewMode,
(KeyCode::Char('v'), KeyModifiers::NONE) => KeyAction::ToggleLayout,
(KeyCode::Char(','), KeyModifiers::NONE) => KeyAction::OpenSettings,
// Refresh (Shift-R since r is rename)
(KeyCode::Char('R'), KeyModifiers::SHIFT) => KeyAction::Refresh,
// Search and sort
(KeyCode::Char('/'), KeyModifiers::NONE) => KeyAction::Search,
(KeyCode::Char('s'), KeyModifiers::NONE) => KeyAction::Sort,
(KeyCode::Char('S'), KeyModifiers::SHIFT) => KeyAction::ReverseSort,
// Directory navigation
(KeyCode::Enter, _) => KeyAction::DrillDown,
(KeyCode::Backspace, _) => KeyAction::NavigateBack,
(KeyCode::Char('-'), KeyModifiers::NONE) => KeyAction::NavigateBack,
// Command palette
(KeyCode::Char(':'), KeyModifiers::NONE) => KeyAction::CommandMode,
(KeyCode::Char(':'), KeyModifiers::SHIFT) => KeyAction::CommandMode,
// Go to directory
(KeyCode::Char('g'), KeyModifiers::CONTROL) => KeyAction::GoTo,
// Bookmarks
(KeyCode::Char('m'), KeyModifiers::NONE) => KeyAction::SetBookmark,
(KeyCode::Char('\''), KeyModifiers::NONE) => KeyAction::JumpToBookmark,
(KeyCode::Char('`'), KeyModifiers::NONE) => KeyAction::JumpToBookmark,
(KeyCode::Char('B'), KeyModifiers::SHIFT) => KeyAction::ShowBookmarkList,
// Confirmation (for dialogs)
(KeyCode::Char('n'), KeyModifiers::NONE) => KeyAction::Cancel,
// ClearMarks available via Escape when items are marked, or :clear command
// View switching (Explorer, Duplicates, Age, Errors)
(KeyCode::Tab, KeyModifiers::NONE) => KeyAction::NextView,
(KeyCode::BackTab, _) => KeyAction::PrevView,
// Directory tabs
(KeyCode::Char('t'), KeyModifiers::CONTROL) => KeyAction::NewDirTab,
(KeyCode::Char('w'), KeyModifiers::CONTROL) => KeyAction::CloseDirTab,
(KeyCode::Char(']'), KeyModifiers::NONE) => KeyAction::NextDirTab,
(KeyCode::Char('['), KeyModifiers::NONE) => KeyAction::PrevDirTab,
// Direct tab switching: 1-9 keys (only when multiple tabs exist)
(KeyCode::Char('1'), KeyModifiers::NONE) => KeyAction::DirTab(1),
(KeyCode::Char('2'), KeyModifiers::NONE) => KeyAction::DirTab(2),
(KeyCode::Char('3'), KeyModifiers::NONE) => KeyAction::DirTab(3),
(KeyCode::Char('4'), KeyModifiers::NONE) => KeyAction::DirTab(4),
(KeyCode::Char('5'), KeyModifiers::NONE) => KeyAction::DirTab(5),
(KeyCode::Char('6'), KeyModifiers::NONE) => KeyAction::DirTab(6),
(KeyCode::Char('7'), KeyModifiers::NONE) => KeyAction::DirTab(7),
(KeyCode::Char('8'), KeyModifiers::NONE) => KeyAction::DirTab(8),
(KeyCode::Char('9'), KeyModifiers::NONE) => KeyAction::DirTab(9),
_ => KeyAction::None,
}
}
}
/// A section of key bindings for the help display.
pub struct HelpSection {
pub title: &'static str,
pub bindings: Vec<KeyBinding>,
}
/// Key binding for display in help.
pub struct KeyBinding {
pub keys: &'static str,
pub description: &'static str,
}
/// Get all key bindings organized by section for help display.
pub fn get_help_sections() -> Vec<HelpSection> {
vec![
HelpSection {
title: "Navigation",
bindings: vec![
KeyBinding {
keys: "j/k ↑/↓",
description: "Move up/down",
},
KeyBinding {
keys: "h/l ←/→",
description: "Collapse/expand",
},
KeyBinding {
keys: "Enter",
description: "Drill into directory",
},
KeyBinding {
keys: "Backspace/-",
description: "Navigate back",
},
KeyBinding {
keys: "g/G",
description: "Jump to top/bottom",
},
KeyBinding {
keys: "Ctrl-u/d",
description: "Page up/down",
},
KeyBinding {
keys: "Ctrl-g",
description: "Go to directory",
},
KeyBinding {
keys: "o",
description: "Toggle expand node",
},
],
},
HelpSection {
title: "Selection & Clipboard",
bindings: vec![
KeyBinding {
keys: "Space",
description: "Mark item for multi-select",
},
KeyBinding {
keys: "y",
description: "Yank (copy) to clipboard",
},
KeyBinding {
keys: "x",
description: "Cut to clipboard",
},
KeyBinding {
keys: "p",
description: "Paste from clipboard",
},
KeyBinding {
keys: "Esc",
description: "Clear clipboard/marks",
},
],
},
HelpSection {
title: "File Operations",
bindings: vec![
KeyBinding {
keys: "d/Del",
description: "Delete item(s)",
},
KeyBinding {
keys: "r",
description: "Rename",
},
KeyBinding {
keys: "a",
description: "Create file (touch)",
},
KeyBinding {
keys: "A",
description: "Create directory (mkdir)",
},
KeyBinding {
keys: "T",
description: "Take (mkdir + cd)",
},
KeyBinding {
keys: "Ctrl-z",
description: "Undo",
},
],
},
HelpSection {
title: "Views & Display",
bindings: vec![
KeyBinding {
keys: "Tab/S-Tab",
description: "Switch view (Explorer/Dups/Age)",
},
KeyBinding {
keys: "v",
description: "Toggle Tree/Miller",
},
KeyBinding {
keys: "s",
description: "Cycle sort mode",
},
KeyBinding {
keys: "S",
description: "Reverse sort order",
},
KeyBinding {
keys: "i",
description: "Toggle details panel",
},
KeyBinding {
keys: "t",
description: "Toggle dark/light theme",
},
KeyBinding {
keys: "R",
description: "Refresh/rescan",
},
],
},
HelpSection {
title: "Duplicates View",
bindings: vec![
KeyBinding {
keys: "j/k",
description: "Navigate groups/files",
},
KeyBinding {
keys: "h/l",
description: "Collapse/expand group",
},
KeyBinding {
keys: "d (on group)",
description: "Mark all duplicates (keeps 1st)",
},
KeyBinding {
keys: "d (on file)",
description: "Mark single file for deletion",
},
KeyBinding {
keys: "Space (group)",
description: "Select/deselect all in group",
},
KeyBinding {
keys: "Space (file)",
description: "Toggle single file selection",
},
],
},
HelpSection {
title: "Bookmarks",
bindings: vec![
KeyBinding {
keys: "m<key>",
description: "Set bookmark",
},
KeyBinding {
keys: "'<key>",
description: "Jump to bookmark",
},
KeyBinding {
keys: "B",
description: "Show bookmark list",
},
],
},
HelpSection {
title: "Mouse",
bindings: vec![
KeyBinding {
keys: "Click",
description: "Select item",
},
KeyBinding {
keys: "Double-click",
description: "Enter directory",
},
KeyBinding {
keys: "Right-click",
description: "Toggle mark",
},
KeyBinding {
keys: "Scroll",
description: "Move up/down",
},
],
},
HelpSection {
title: "Directory Tabs",
bindings: vec![
KeyBinding {
keys: "Ctrl-t",
description: "New tab (current dir)",
},
KeyBinding {
keys: "Ctrl-w",
description: "Close current tab",
},
KeyBinding {
keys: "]/[",
description: "Next/prev tab",
},
KeyBinding {
keys: "1-9",
description: "Jump to tab N",
},
],
},
HelpSection {
title: "Commands",
bindings: vec![
KeyBinding {
keys: ":",
description: "Open command palette",
},
KeyBinding {
keys: ",",
description: "Open settings",
},
KeyBinding {
keys: "?",
description: "Show this help",
},
KeyBinding {
keys: "q",
description: "Quit",
},
],
},
]
}
/// Get command palette commands for help display.
pub fn get_command_help() -> Vec<(&'static str, &'static str)> {
vec![
(":q :quit", "Quit application"),
(":cd <path>", "Change directory"),
(":touch <name>", "Create file"),
(":mkdir <name>", "Create directory"),
(":take <name>", "Create dir and cd into it"),
(":yank :y", "Copy to clipboard"),
(":cut :x", "Cut to clipboard"),
(":paste :p", "Paste from clipboard"),
(":delete :rm", "Delete marked items"),
(":rename <name>", "Rename current item"),
(":rename-bulk :brn", "Bulk rename marked items"),
(":clear", "Clear all marks"),
(":theme dark|light", "Set theme"),
(":layout tree|miller", "Set layout"),
(":sort <mode>", "Set sort (size/name/date/count)"),
(":bookmark [key]", "Set bookmark (or list all)"),
(":bookmarks", "Show bookmark list"),
(":delmark <key>", "Delete a bookmark"),
(":help", "Show help"),
]
}
/// Get all key bindings as a flat list (for backwards compatibility).
#[allow(dead_code)]
pub fn get_key_bindings() -> Vec<KeyBinding> {
get_help_sections()
.into_iter()
.flat_map(|s| s.bindings)
.collect()
}