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