diff options
| author | Daniel Jankowski <daniel.jankowski@rub.de> | 2024-05-25 16:37:00 +0200 |
|---|---|---|
| committer | Daniel Jankowski <daniel.jankowski@rub.de> | 2024-05-25 16:37:00 +0200 |
| commit | 4c7d7a38804ea33e131dea5eabc0aca7477a642b (patch) | |
| tree | 7b87b0f7dd5da18d7d4618ad344993a90b3da8b8 /src | |
| parent | feat: implement format precedence to hide overflown parts (diff) | |
| download | sl0pstatus-4c7d7a38804ea33e131dea5eabc0aca7477a642b.tar.gz sl0pstatus-4c7d7a38804ea33e131dea5eabc0aca7477a642b.tar.xz sl0pstatus-4c7d7a38804ea33e131dea5eabc0aca7477a642b.zip | |
feat: print config errors for users
Diffstat (limited to 'src')
| -rw-r--r-- | src/bin/zjstatus.rs | 15 | ||||
| -rw-r--r-- | src/config.rs | 23 |
2 files changed, 30 insertions, 8 deletions
diff --git a/src/bin/zjstatus.rs b/src/bin/zjstatus.rs index aac574c..388f9e8 100644 --- a/src/bin/zjstatus.rs +++ b/src/bin/zjstatus.rs @@ -27,6 +27,7 @@ struct State { userspace_configuration: BTreeMap<String, String>, module_config: config::ModuleConfig, widget_map: BTreeMap<String, Arc<dyn Widget>>, + err: Option<anyhow::Error>, } #[cfg(not(test))] @@ -73,7 +74,13 @@ impl ZellijPlugin for State { EventType::RunCommandResult, ]); - self.module_config = ModuleConfig::new(&configuration); + self.module_config = match ModuleConfig::new(&configuration) { + Ok(mc) => mc, + Err(e) => { + self.err = Some(e); + return; + } + }; self.widget_map = register_widgets(&configuration); self.userspace_configuration = configuration; self.pending_events = Vec::new(); @@ -147,6 +154,12 @@ impl ZellijPlugin for State { return; } + if let Some(err) = &self.err { + println!("Error: {:?}", err); + + return; + } + self.state.cols = cols; tracing::debug!("{:?}", self.state.mode.session_name); diff --git a/src/config.rs b/src/config.rs index a58007c..2a8ca81 100644 --- a/src/config.rs +++ b/src/config.rs @@ -82,7 +82,7 @@ pub struct ModuleConfig { } impl ModuleConfig { - pub fn new(config: &BTreeMap<String, String>) -> Self { + pub fn new(config: &BTreeMap<String, String>) -> anyhow::Result<Self> { let format_space_config = match config.get("format_space") { Some(space_config) => space_config, None => "", @@ -109,10 +109,19 @@ impl ModuleConfig { }; let format_precedence = match config.get("format_precedence") { - Some(conf) => conf - .chars() - .map(|c| Part::from_str(&c.to_string()).expect("Invalid part")) - .collect(), + Some(conf) => { + let prec = conf + .chars() + .map(|c| Part::from_str(&c.to_string())) + .collect(); + + match prec { + Ok(prec) => prec, + Err(e) => { + anyhow::bail!("Invalid format_precedence: {}", e); + } + } + } None => vec![Part::Left, Part::Center, Part::Right], }; @@ -121,7 +130,7 @@ impl ModuleConfig { None => BorderConfig::default(), }; - Self { + Ok(Self { left_parts_config: left_parts_config.to_owned(), left_parts: parts_from_config(Some(&left_parts_config.to_owned())), center_parts_config: center_parts_config.to_owned(), @@ -132,7 +141,7 @@ impl ModuleConfig { hide_frame_for_single_pane, border: border_config, format_precedence, - } + }) } pub fn handle_mouse_action( |
