kaspa_cli_lib/modules/
theme.rs

1use crate::imports::*;
2use application_runtime::*;
3
4#[derive(Describe, Debug, Clone, Serialize, Deserialize, Hash, Eq, PartialEq, Ord, PartialOrd)]
5#[serde(rename_all = "lowercase")]
6pub enum ThemeSettings {
7    #[describe("Theme name")]
8    Name,
9}
10
11#[async_trait]
12impl DefaultSettings for ThemeSettings {
13    async fn defaults() -> Vec<(Self, Value)> {
14        vec![(Self::Name, to_value("default").unwrap())]
15    }
16}
17
18pub struct Theme {
19    settings: SettingsStore<ThemeSettings>,
20}
21
22impl Default for Theme {
23    fn default() -> Self {
24        Theme { settings: SettingsStore::try_new("theme").expect("Failed to create theme settings store") }
25    }
26}
27
28#[async_trait]
29impl Handler for Theme {
30    fn verb(&self, _ctx: &Arc<dyn Context>) -> Option<&'static str> {
31        (is_nw() || is_web()).then_some("theme")
32    }
33
34    fn help(&self, _ctx: &Arc<dyn Context>) -> &'static str {
35        "Change application theme"
36    }
37
38    async fn start(self: Arc<Self>, _ctx: &Arc<dyn Context>) -> cli::Result<()> {
39        self.settings.try_load().await.ok();
40        if let Some(_name) = self.settings.get::<String>(ThemeSettings::Name) {
41            // TODO - set theme
42        }
43        Ok(())
44    }
45
46    async fn handle(self: Arc<Self>, ctx: &Arc<dyn Context>, argv: Vec<String>, cmd: &str) -> cli::Result<()> {
47        let ctx = ctx.clone().downcast_arc::<KaspaCli>()?;
48        self.main(ctx, argv, cmd).await.map_err(|e| e.into())
49    }
50}
51
52impl Theme {
53    async fn main(self: Arc<Self>, ctx: Arc<KaspaCli>, argv: Vec<String>, _cmd: &str) -> Result<()> {
54        if argv.is_empty() {
55            return self.display_help(ctx, argv).await;
56        }
57
58        Ok(())
59    }
60
61    async fn display_help(self: Arc<Self>, ctx: Arc<KaspaCli>, _argv: Vec<String>) -> Result<()> {
62        let help = "\n\
63        \n\
64        ";
65
66        tprintln!(ctx, "{}", help.crlf());
67
68        Ok(())
69    }
70}