hyprshell_core_lib/config/
explain.rs

1use crate::config::{Config, Reverse, load_config};
2use crate::daemon_running;
3use std::path::Path;
4use tracing::{error, info};
5
6pub fn check_config(config_path: &Path) -> anyhow::Result<()> {
7    let config = load_config(config_path)
8        .inspect_err(|err| error!("\x1b[1m\x1b[31mConfig is invalid:\x1b[0m {err:?}\n"))?;
9    let info = explain(config);
10    println!("{info}");
11
12    if daemon_running() {
13        info!("Daemon \x1b[32mrunning\x1b[0m")
14    } else {
15        info!(
16            "Daemon \x1b[31mnot running\x1b[0m, start it with `hyprshell run` or `systemctl --user enable --now hyprshell`"
17        );
18    }
19    Ok(())
20}
21
22pub fn explain(config: Config) -> String {
23    let mut builder = String::from("\x1b[1m\x1b[32mConfig is valid\x1b[0m\n\n");
24
25    if let Some(windows) = &config.windows {
26        if let Some(overview) = &windows.overview {
27            builder.push_str(&format!(
28                "Use \x1b[1m\x1b[34m{} + {}\x1b[0m to open the Overview. Use \x1b[1m\x1b[34m{}\x1b[0m and \x1b[1m\x1b[34m{}\x1b[0m to select a different window, press \x1b[34mreturn\x1b[0m to switch\n\
29                You can also use the \x1b[34marrow keys\x1b[0m to navigate the workspaces. Use \x1b[34mEsc\x1b[0m to close the overview.\n",
30                overview.open.modifier,
31                overview.open.key.to_key(),
32                overview.navigate.forward,
33                match &overview.navigate.reverse {
34                    Reverse::Key(k) => k.clone(),
35                    Reverse::Mod(m) => format!("{} + {}", m, overview.navigate.forward),
36                }
37            ));
38        } else {
39            builder.push_str("<Overview disabled>\n");
40        };
41    };
42
43    if let Some(launcher) = &config.launcher {
44        builder.push_str("After opening the Overview the launcher is available.\n");
45        if let Some(_applications) = launcher.plugins.applications.as_ref() {
46            builder.push_str("Start typing to search through applications (sorted by how often they were opened).\n\
47                    Press \x1b[34mreturn\x1b[0m to launch the first app, use \x1b[34mCtrl + 1/2/3/...\x1b[0m to open the second, third, etc.\n");
48        }
49        if launcher.plugins.terminal.is_some() {
50            builder.push_str(
51                "Press \x1b[34mCtrl + t\x1b[0m to run the typed command in a terminal.\n",
52            );
53        }
54        if launcher.plugins.shell.is_some() {
55            builder.push_str(
56                "Press \x1b[34mCtrl + r\x1b[0m to run the typed command in the background.\n",
57            );
58        }
59        if let Some(engines) = &launcher.plugins.websearch {
60            builder.push_str(&format!("Press \x1b[34mCtrl + \x1b[1m\x1b[34m<key>\x1b[0m to search the typed text in any of the configured SearchEngines: {}.\n",
61                                      engines.engines.iter().map(|e| e.name.as_str()).collect::<Vec<_>>().join(", ")));
62        }
63    } else {
64        builder.push_str("<Launcher disabled>\n");
65    }
66
67    builder.push('\n');
68
69    if let Some(windows) = &config.windows {
70        if let Some(switch) = &windows.switch {
71            builder.push_str(&format!(
72                "Press \x1b[1m\x1b[34m{} + {}\x1b[0m and hold \x1b[1m\x1b[34m{}\x1b[0m to view recently used applications. Press/hold \x1b[1m\x1b[34m{}\x1b[0m and \x1b[1m\x1b[34m{}\x1b[0m to select a different window,\n\
73                release \x1b[1m\x1b[34m{}\x1b[0m to close the window. You can also use the \x1b[34marrow keys\x1b[0m to navigate the clients.\n",
74                switch.navigate.forward,
75                switch.open.modifier,
76                switch.open.modifier,
77                switch.navigate.forward,
78                match &switch.navigate.reverse {
79                    Reverse::Key(k) => k.clone(),
80                    Reverse::Mod(m) => format!("{} + {}", m, switch.navigate.forward),
81                },
82                switch.open.modifier,
83            ));
84        } else {
85            builder.push_str("<Recent Apps disabled>\n");
86        };
87    }
88
89    builder
90}