hyprshell_core_lib/config/
explain.rs

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