hyprshell_core_lib/config/
check.rs

1use crate::config::structs::ToKey;
2use crate::config::{load_config, Config, Reverse};
3use crate::daemon_running;
4use std::path::Path;
5
6pub fn check_config(config_path: &Path) -> anyhow::Result<()> {
7    let config = load_config(config_path)
8        .inspect_err(|err| eprintln!("\x1b[1m\x1b[31mConfig is invalid:\x1b[0m {err:?}\n"))?;
9    let info = generate_info(config);
10    println!("{info}");
11
12    if daemon_running() {
13        println!("Daemon \x1b[32mrunning\x1b[0m")
14    } else {
15        println!("Daemon \x1b[31mnot running\x1b[0m, start it with `hyprshell run` or `systemctl --user enable --now hyprshell`");
16    }
17    Ok(())
18}
19
20pub fn generate_info(config: Config) -> String {
21    let mut builder = String::from("\x1b[1m\x1b[32mConfig is valid\x1b[0m\n\n");
22
23    if let Some(windows) = &config.windows {
24        if let Some(overview) = &windows.overview {
25            builder.push_str(&format!(
26                "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\
27                You can also use the \x1b[34marrow keys\x1b[0m to navigate the workspaces. Use \x1b[34mEsc\x1b[0m to close the overview.\n",
28                overview.open.modifier,
29                overview.open.key.to_key(),
30                overview.navigate.forward,
31                match &overview.navigate.reverse {
32                    Reverse::Key(k) => k.clone(),
33                    Reverse::Mod(m) => format!("{} + {}", m, overview.navigate.forward),
34                }
35            ));
36        } else {
37            builder.push_str("<Overview disabled>\n");
38        };
39    };
40
41    if let Some(_launcher) = &config.launcher {
42        builder.push_str("After opening the Overview, start typing to search through applications (sorted by how often they were opened).\n\
43                    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");
44    } else {
45        builder.push_str("<Launcher disabled>\n");
46    }
47
48    builder.push('\n');
49
50    if let Some(windows) = &config.windows {
51        if let Some(switch) = &windows.switch {
52            builder.push_str(&format!(
53                "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\
54                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",
55                switch.navigate.forward,
56                switch.open.modifier,
57                switch.open.modifier,
58                switch.navigate.forward,
59                match &switch.navigate.reverse {
60                    Reverse::Key(k) => k.clone(),
61                    Reverse::Mod(m) => format!("{} + {}", m, switch.navigate.forward),
62                },
63                switch.open.modifier,
64            ));
65        } else {
66            builder.push_str("<Recent Apps disabled>\n");
67        };
68    }
69
70    builder
71}