Skip to content

Commit

Permalink
feat: print config errors for users
Browse files Browse the repository at this point in the history
  • Loading branch information
dj95 committed May 25, 2024
1 parent 63b13dd commit 4c7d7a3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion plugin-dev-workspace.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ layout {
format_center "{command_0} {command_1} {command_git_branch} {command_3}"
format_right "{notifications}{swap_layout}{datetime}"
format_space "#[bg=#181825]"
format_precedence "lcq"
format_precedence "lcr"

notification_format_unread "#[fg=#89B4FA,bg=#181825,blink]  #[fg=#89B4FA,bg=#181825] {message} "
notification_format_no_notifications "#[fg=#89B4FA,bg=#181825,dim]  "
Expand Down
15 changes: 14 additions & 1 deletion src/bin/zjstatus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
23 changes: 16 additions & 7 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => "",
Expand All @@ -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],
};

Expand All @@ -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(),
Expand All @@ -132,7 +141,7 @@ impl ModuleConfig {
hide_frame_for_single_pane,
border: border_config,
format_precedence,
}
})
}

pub fn handle_mouse_action(
Expand Down

0 comments on commit 4c7d7a3

Please sign in to comment.