Skip to main content

seal_tui/
command.rs

1//! Command definitions for the command palette.
2
3use crate::message::Message;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum CommandId {
7    Quit,
8    SelectTheme,
9    ToggleDiffView,
10    ToggleDiffWrap,
11    ToggleSidebar,
12    OpenFileInEditor,
13}
14
15#[derive(Clone)]
16pub struct CommandSpec {
17    pub name: &'static str,
18    pub description: &'static str,
19    pub id: CommandId,
20    pub category: &'static str,
21    pub shortcut: Option<&'static str>,
22    /// Whether this command represents the currently active state (shows bullet).
23    pub active: bool,
24}
25
26#[must_use]
27pub fn get_commands() -> Vec<CommandSpec> {
28    vec![
29        // --- View ---
30        CommandSpec {
31            name: "Toggle diff view",
32            description: "Toggle between unified and side-by-side diff",
33            id: CommandId::ToggleDiffView,
34            category: "View",
35            shortcut: Some("v"),
36            active: false,
37        },
38        CommandSpec {
39            name: "Toggle line wrap",
40            description: "Toggle line wrapping in diffs",
41            id: CommandId::ToggleDiffWrap,
42            category: "View",
43            shortcut: Some("w"),
44            active: false,
45        },
46        CommandSpec {
47            name: "Toggle sidebar",
48            description: "Show or hide the file sidebar",
49            id: CommandId::ToggleSidebar,
50            category: "View",
51            shortcut: Some("s"),
52            active: false,
53        },
54        CommandSpec {
55            name: "Select theme",
56            description: "Choose a theme from the list",
57            id: CommandId::SelectTheme,
58            category: "View",
59            shortcut: None,
60            active: false,
61        },
62        // --- Session ---
63        CommandSpec {
64            name: "Open in editor",
65            description: "Open the current file in an external editor",
66            id: CommandId::OpenFileInEditor,
67            category: "Session",
68            shortcut: Some("o"),
69            active: false,
70        },
71        CommandSpec {
72            name: "Quit",
73            description: "Quit the application",
74            id: CommandId::Quit,
75            category: "Session",
76            shortcut: Some("q"),
77            active: false,
78        },
79    ]
80}
81
82#[must_use]
83pub const fn command_id_to_message(id: CommandId) -> Message {
84    match id {
85        CommandId::Quit => Message::Quit,
86        CommandId::SelectTheme => Message::ShowThemePicker,
87        CommandId::ToggleDiffView => Message::ToggleDiffView,
88        CommandId::ToggleDiffWrap => Message::ToggleDiffWrap,
89        CommandId::ToggleSidebar => Message::ToggleSidebar,
90        CommandId::OpenFileInEditor => Message::OpenFileInEditor,
91    }
92}