hyprshell_core_lib/config/
check.rs

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