1use once_cell::sync::Lazy;
2
3#[derive(Clone, Copy, Debug)]
5pub struct SlashCommandInfo {
6 pub name: &'static str,
7 pub description: &'static str,
8}
9
10pub static SLASH_COMMANDS: Lazy<Vec<SlashCommandInfo>> = Lazy::new(|| {
12 vec![
13 SlashCommandInfo {
14 name: "theme",
15 description: "Switch UI theme (usage: /theme <theme-id>)",
16 },
17 SlashCommandInfo {
18 name: "list-themes",
19 description: "List all available UI themes",
20 },
21 SlashCommandInfo {
22 name: "command",
23 description: "Run a terminal command (usage: /command <program> [args...])",
24 },
25 SlashCommandInfo {
26 name: "help",
27 description: "Show slash command help",
28 },
29 SlashCommandInfo {
30 name: "exit",
31 description: "Exit the session",
32 },
33 ]
34});
35
36pub fn suggestions_for(prefix: &str) -> Vec<&'static SlashCommandInfo> {
38 if prefix.is_empty() {
39 return SLASH_COMMANDS.iter().collect();
40 }
41 let query = prefix.to_ascii_lowercase();
42 let mut matches: Vec<&SlashCommandInfo> = SLASH_COMMANDS
43 .iter()
44 .filter(|info| info.name.starts_with(&query))
45 .collect();
46 if matches.is_empty() {
47 SLASH_COMMANDS.iter().collect()
48 } else {
49 matches.sort_by(|a, b| a.name.cmp(b.name));
50 matches
51 }
52}