excel_cli/app/
ui.rs

1use crate::app::AppState;
2use crate::app::InputMode;
3
4impl AppState<'_> {
5    pub fn show_help(&mut self) {
6        self.help_scroll = 0;
7
8        self.help_text = "FILE OPERATIONS:\n\
9             :w          - Save file\n\
10             :wq, :x     - Save and quit\n\
11             :q          - Quit (will warn if unsaved changes)\n\
12             :q!         - Force quit without saving\n\n\
13             NAVIGATION:\n\
14             :[cell]     - Jump to cell (e.g., :B10)\n\
15             hjkl        - Move cursor (left, down, up, right)\n\
16             0           - Jump to first column\n\
17             ^           - Jump to first non-empty column\n\
18             $           - Jump to last column\n\
19             gg          - Jump to first row\n\
20             G           - Jump to last row\n\
21             Ctrl+arrows - Jump to next non-empty cell\n\
22             [           - Switch to previous sheet\n\
23             ]           - Switch to next sheet\n\
24             :sheet [name/number] - Switch to sheet by name or index\n\n\
25             EDITING:\n\
26             Enter       - Edit current cell\n\
27             :y          - Copy current cell\n\
28             :d          - Cut current cell\n\
29             :put, :pu   - Paste to current cell\n\
30             u           - Undo last operation\n\
31             Ctrl+r      - Redo last undone operation\n\n\
32             SEARCH:\n\
33             /           - Search forward\n\
34             ?           - Search backward\n\
35             n           - Jump to next search result\n\
36             N           - Jump to previous search result\n\
37             :nohlsearch, :noh - Disable search highlighting\n\n\
38             COLUMN OPERATIONS:\n\
39             :cw fit     - Adjust width of current column to fit its content\n\
40             :cw fit all - Adjust width of all columns to fit their content\n\
41             :cw min     - Set current column width to minimum (5 characters)\n\
42             :cw min all - Set all columns width to minimum\n\
43             :cw [number] - Set current column width to specific number of characters\n\
44             :dc         - Delete current column\n\
45             :dc [col]   - Delete specific column (e.g., :dc A or :dc 1)\n\
46             :dc [start] [end] - Delete columns from start to end (e.g., :dc A C)\n\n\
47             ROW OPERATIONS:\n\
48             :dr         - Delete current row\n\
49             :dr [row]   - Delete specific row\n\
50             :dr [start] [end] - Delete rows from start to end\n\n\
51             EXPORT:\n\
52             :ej [h|v] [rows]  - Export current sheet to JSON\n\
53             :eja [h|v] [rows] - Export all sheets to a single JSON file\n\
54                                h=horizontal (default), v=vertical\n\
55                                [rows]=number of header rows (default: 1)\n\n\
56             SHEET OPERATIONS:\n\
57             :delsheet   - Delete the current sheet\n\n\
58             UI ADJUSTMENTS:\n\
59             +/=         - Increase info panel height\n\
60             -           - Decrease info panel height\n\n\
61             EDITING MODE:\n\
62             Esc         - Exit Vim mode and save changes\n\
63             i           - Enter Insert mode\n\
64             v           - Enter Visual mode\n\
65             y           - Yank (copy) text in Visual mode or with operator\n\
66             d           - Delete text in Visual mode or with operator\n\
67             c           - Change text in Visual mode or with operator\n\
68             p           - Paste yanked or deleted text\n\
69             u           - Undo last change\n\
70             Ctrl+r      - Redo last undone change\n\
71             h,j,k,l     - Move cursor left, down, up, right\n\
72             w           - Move to next word\n\
73             b           - Move to beginning of word\n\
74             e           - Move to end of word\n\
75             $           - Move to end of line\n\
76             ^           - Move to first non-blank character of line\n\
77             gg          - Move to first line\n\
78             G           - Move to last line\n\
79             x           - Delete character under cursor\n\
80             D           - Delete to end of line\n\
81             C           - Change to end of line\n\
82             o           - Open new line below and enter Insert mode\n\
83             O           - Open new line above and enter Insert mode\n\
84             A           - Append at end of line\n\
85             I           - Insert at beginning of line"
86            .to_string();
87
88        self.input_mode = InputMode::Help;
89    }
90
91    pub fn save_and_exit(&mut self) {
92        if !self.workbook.is_modified() {
93            self.add_notification("No changes to save".to_string());
94            self.should_quit = true;
95            return;
96        }
97
98        match self.workbook.save() {
99            Ok(_) => {
100                self.undo_history.clear();
101                self.add_notification("File saved".to_string());
102                self.should_quit = true;
103            }
104            Err(e) => {
105                self.add_notification(format!("Save failed: {e}"));
106                self.input_mode = InputMode::Normal;
107            }
108        }
109    }
110
111    pub fn save(&mut self) -> Result<(), anyhow::Error> {
112        if !self.workbook.is_modified() {
113            self.add_notification("No changes to save".to_string());
114            return Ok(());
115        }
116
117        match self.workbook.save() {
118            Ok(_) => {
119                self.undo_history.clear();
120                self.add_notification("File saved".to_string());
121            }
122            Err(e) => {
123                self.add_notification(format!("Save failed: {e}"));
124            }
125        }
126        Ok(())
127    }
128
129    pub fn exit_without_saving(&mut self) {
130        self.should_quit = true;
131    }
132}