rush_sync_server/commands/theme/
command.rs

1use super::ThemeSystem;
2use crate::commands::command::Command;
3use crate::core::prelude::*;
4use std::future::Future;
5use std::pin::Pin;
6
7#[derive(Debug)]
8pub struct ThemeCommand {
9    theme_system: std::sync::Mutex<Option<ThemeSystem>>,
10}
11
12impl ThemeCommand {
13    pub fn new() -> Self {
14        Self {
15            theme_system: std::sync::Mutex::new(None),
16        }
17    }
18
19    fn get_or_init_theme_system(&self) -> Result<std::sync::MutexGuard<Option<ThemeSystem>>> {
20        let mut guard = self.theme_system.lock().unwrap();
21        if guard.is_none() {
22            *guard = Some(ThemeSystem::load()?);
23        }
24        Ok(guard)
25    }
26}
27
28impl Command for ThemeCommand {
29    fn name(&self) -> &'static str {
30        "theme"
31    }
32
33    fn description(&self) -> &'static str {
34        "Change application theme (live update without restart, loaded from TOML)"
35    }
36
37    fn matches(&self, command: &str) -> bool {
38        command.trim().to_lowercase().starts_with("theme")
39    }
40
41    fn execute_sync(&self, args: &[&str]) -> Result<String> {
42        let mut guard = self.get_or_init_theme_system()?;
43        let theme_system = guard.as_mut().unwrap();
44
45        match args.first() {
46            None => Ok(theme_system.show_status()),
47            Some(&"--help" | &"-h") => Ok(Self::create_help_text(theme_system)),
48            Some(&"debug") => match args.get(1) {
49                Some(&theme_name) => Ok(theme_system.debug_theme_details(theme_name)),
50                None => Ok("❌ Theme name missing. Usage: theme debug <name>".to_string()),
51            },
52            Some(&"preview") => match args.get(1) {
53                Some(&theme_name) => theme_system.preview_theme(theme_name),
54                None => Ok("❌ Theme name missing. Usage: theme preview <name>".to_string()),
55            },
56            Some(&theme_name) => theme_system.change_theme(theme_name),
57        }
58    }
59
60    fn execute_async<'a>(
61        &'a self,
62        args: &'a [&'a str],
63    ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'a>> {
64        Box::pin(async move { self.execute_sync(args) })
65    }
66
67    fn supports_async(&self) -> bool {
68        true
69    }
70
71    fn priority(&self) -> u8 {
72        65
73    }
74}
75
76impl ThemeCommand {
77    fn create_help_text(theme_system: &ThemeSystem) -> String {
78        let available_themes = theme_system.get_available_names();
79
80        if available_themes.is_empty() {
81            return "❌ Keine Themes verfügbar!\n\n📝 Füge [theme.xyz] Sektionen zur rush.toml hinzu:\n\n[theme.mein_theme]\ninput_text = \"White\"\ninput_bg = \"Black\"\ncursor = \"Green\"\noutput_text = \"Gray\"\noutput_bg = \"Black\"\nprompt_text = \">> \"\nprompt_color = \"Cyan\"\noutput_cursor = \"BLOCK\"    # ✅ NEU!\noutput_color = \"LightGreen\" # ✅ NEU!".to_string();
82        }
83
84        let themes_list = available_themes.join(", ");
85
86        format!(
87            "🎨 TOML-Theme Commands (Live Update - Geladen aus rush.toml!):\n\
88            theme                Show available TOML-themes\n\
89            theme <name>         Select theme: {}\n\
90            theme preview <name> Preview theme colors + cursor config ✅ NEW!\n\
91            theme -h             Show this help\n\n\
92            ✨ Alle Themes werden LIVE aus [theme.*] Sektionen der rush.toml geladen!\n\
93            🎯 NEU: Cursor-Konfiguration per output_cursor + output_color!\n\
94            📁 Füge beliebige [theme.dein_name] Sektionen hinzu für neue Themes\n\
95            🔄 Änderungen werden sofort angewendet (kein Restart nötig)\n\n\
96            🎛️ Cursor-Optionen:\n\
97            • output_cursor: BLOCK, PIPE, UNDERSCORE\n\
98            • output_color: Jede unterstützte Farbe (White, Green, etc.)",
99            themes_list
100        )
101    }
102}
103
104impl Default for ThemeCommand {
105    fn default() -> Self {
106        Self::new()
107    }
108}