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