Skip to main content

corty_tui/
slash_command.rs

1//! Slash commands for the Corty TUI
2//!
3//! This module defines the available slash commands that can be invoked
4//! by typing '/' followed by the command name in the chat input.
5
6use crate::widgets::constants::{
7    SLASH_COMMAND_ASK_AI_DESC, SLASH_COMMAND_CLEAR_DESC, SLASH_COMMAND_FULLSCREEN_DESC,
8};
9use strum::IntoEnumIterator;
10use strum_macros::{AsRefStr, EnumIter, EnumString, IntoStaticStr};
11
12/// Commands that can be invoked by starting a message with a leading slash.
13#[derive(
14    Debug, Clone, Copy, PartialEq, Eq, Hash, EnumString, EnumIter, AsRefStr, IntoStaticStr,
15)]
16#[strum(serialize_all = "kebab-case")]
17pub enum SlashCommand {
18    /// Clear the chat history
19    Clear,
20    /// Ask the AI assistant for help
21    AskAI,
22    /// Toggle fullscreen mode
23    Fullscreen,
24}
25
26impl SlashCommand {
27    /// User-visible description shown in the popup.
28    pub fn description(self) -> &'static str {
29        match self {
30            SlashCommand::Clear => SLASH_COMMAND_CLEAR_DESC,
31            SlashCommand::AskAI => SLASH_COMMAND_ASK_AI_DESC,
32            SlashCommand::Fullscreen => SLASH_COMMAND_FULLSCREEN_DESC,
33        }
34    }
35
36    /// Command string without the leading '/'.
37    pub fn command(self) -> &'static str {
38        self.into()
39    }
40
41    /// Returns true if this command requires additional input after selection
42    pub fn requires_input(self) -> bool {
43        match self {
44            SlashCommand::Clear => false,
45            SlashCommand::AskAI => true,
46            SlashCommand::Fullscreen => false,
47        }
48    }
49}
50
51/// Return all built-in commands as a vector.
52pub fn built_in_slash_commands() -> Vec<SlashCommand> {
53    SlashCommand::iter().collect()
54}