envelope_cli/tui/
commands.rs

1//! Command definitions for the command palette
2//!
3//! Defines all available commands that can be executed via the command palette
4
5/// A command that can be executed
6#[derive(Debug, Clone)]
7pub struct Command {
8    /// Command name (what user types)
9    pub name: &'static str,
10    /// Short description
11    pub description: &'static str,
12    /// Keyboard shortcut (if any)
13    pub shortcut: Option<&'static str>,
14    /// Command action
15    pub action: CommandAction,
16}
17
18/// Actions that commands can perform
19#[derive(Debug, Clone, Copy, PartialEq, Eq)]
20pub enum CommandAction {
21    // Navigation
22    ViewAccounts,
23    ViewBudget,
24    ViewReports,
25    ViewRegister,
26
27    // Account operations
28    AddAccount,
29    EditAccount,
30    ArchiveAccount,
31
32    // Transaction operations
33    AddTransaction,
34    EditTransaction,
35    DeleteTransaction,
36    ClearTransaction,
37
38    // Budget operations
39    MoveFunds,
40    AssignBudget,
41    NextPeriod,
42    PrevPeriod,
43
44    // Income operations
45    SetIncome,
46
47    // Category operations
48    AddCategory,
49    AddGroup,
50    EditCategory,
51    DeleteCategory,
52    EditGroup,
53    DeleteGroup,
54
55    // General
56    Help,
57    Quit,
58    Refresh,
59    ToggleArchived,
60
61    // Target operations
62    AutoFillTargets,
63}
64
65/// All available commands
66pub static COMMANDS: &[Command] = &[
67    // Navigation commands
68    Command {
69        name: "accounts",
70        description: "View all accounts",
71        shortcut: Some("1"),
72        action: CommandAction::ViewAccounts,
73    },
74    Command {
75        name: "budget",
76        description: "View budget",
77        shortcut: Some("2"),
78        action: CommandAction::ViewBudget,
79    },
80    Command {
81        name: "reports",
82        description: "View reports",
83        shortcut: Some("3"),
84        action: CommandAction::ViewReports,
85    },
86    Command {
87        name: "register",
88        description: "View transactions for selected account",
89        shortcut: Some("Enter"),
90        action: CommandAction::ViewRegister,
91    },
92    // Transaction commands
93    Command {
94        name: "add-transaction",
95        description: "Add a new transaction",
96        shortcut: Some("a"),
97        action: CommandAction::AddTransaction,
98    },
99    Command {
100        name: "edit-transaction",
101        description: "Edit selected transaction",
102        shortcut: Some("e"),
103        action: CommandAction::EditTransaction,
104    },
105    Command {
106        name: "delete-transaction",
107        description: "Delete selected transaction",
108        shortcut: Some("Ctrl+d"),
109        action: CommandAction::DeleteTransaction,
110    },
111    Command {
112        name: "clear-transaction",
113        description: "Toggle transaction cleared status",
114        shortcut: Some("c"),
115        action: CommandAction::ClearTransaction,
116    },
117    // Budget commands
118    Command {
119        name: "move-funds",
120        description: "Move funds between categories",
121        shortcut: Some("m"),
122        action: CommandAction::MoveFunds,
123    },
124    Command {
125        name: "assign",
126        description: "Assign funds to category",
127        shortcut: None,
128        action: CommandAction::AssignBudget,
129    },
130    Command {
131        name: "next-period",
132        description: "Go to next budget period",
133        shortcut: Some("]"),
134        action: CommandAction::NextPeriod,
135    },
136    Command {
137        name: "prev-period",
138        description: "Go to previous budget period",
139        shortcut: Some("["),
140        action: CommandAction::PrevPeriod,
141    },
142    // Income commands
143    Command {
144        name: "set-income",
145        description: "Set expected income for current period",
146        shortcut: Some("i"),
147        action: CommandAction::SetIncome,
148    },
149    // Account commands
150    Command {
151        name: "add-account",
152        description: "Create a new account",
153        shortcut: None,
154        action: CommandAction::AddAccount,
155    },
156    Command {
157        name: "edit-account",
158        description: "Edit selected account",
159        shortcut: None,
160        action: CommandAction::EditAccount,
161    },
162    Command {
163        name: "archive-account",
164        description: "Archive selected account",
165        shortcut: None,
166        action: CommandAction::ArchiveAccount,
167    },
168    Command {
169        name: "toggle-archived",
170        description: "Show/hide archived accounts",
171        shortcut: Some("A"),
172        action: CommandAction::ToggleArchived,
173    },
174    // Category commands
175    Command {
176        name: "add-category",
177        description: "Create a new category",
178        shortcut: Some("a"),
179        action: CommandAction::AddCategory,
180    },
181    Command {
182        name: "add-group",
183        description: "Create a new category group",
184        shortcut: Some("A"),
185        action: CommandAction::AddGroup,
186    },
187    Command {
188        name: "edit-category",
189        description: "Edit selected category",
190        shortcut: None,
191        action: CommandAction::EditCategory,
192    },
193    Command {
194        name: "delete-category",
195        description: "Delete selected category",
196        shortcut: None,
197        action: CommandAction::DeleteCategory,
198    },
199    Command {
200        name: "edit-group",
201        description: "Edit selected category group",
202        shortcut: Some("E"),
203        action: CommandAction::EditGroup,
204    },
205    Command {
206        name: "delete-group",
207        description: "Delete selected category group",
208        shortcut: Some("D"),
209        action: CommandAction::DeleteGroup,
210    },
211    // General commands
212    Command {
213        name: "help",
214        description: "Show help",
215        shortcut: Some("?"),
216        action: CommandAction::Help,
217    },
218    Command {
219        name: "quit",
220        description: "Quit application",
221        shortcut: Some("q"),
222        action: CommandAction::Quit,
223    },
224    Command {
225        name: "refresh",
226        description: "Refresh data from disk",
227        shortcut: None,
228        action: CommandAction::Refresh,
229    },
230    // Target commands
231    Command {
232        name: "auto-fill-targets",
233        description: "Fill budgets from targets",
234        shortcut: None,
235        action: CommandAction::AutoFillTargets,
236    },
237];
238
239/// Find a command by name
240pub fn find_command(name: &str) -> Option<&'static Command> {
241    COMMANDS.iter().find(|cmd| cmd.name == name)
242}
243
244/// Filter commands by search query
245pub fn filter_commands(query: &str) -> Vec<&'static Command> {
246    if query.is_empty() {
247        COMMANDS.iter().collect()
248    } else {
249        let query_lower = query.to_lowercase();
250        COMMANDS
251            .iter()
252            .filter(|cmd| {
253                cmd.name.to_lowercase().contains(&query_lower)
254                    || cmd.description.to_lowercase().contains(&query_lower)
255            })
256            .collect()
257    }
258}