Skip to content

Commit

Permalink
fix(plugins): display errors properly (#2975)
Browse files Browse the repository at this point in the history
* fix(plugins): format errors and make sure file not found errors appear

* style(fmt): rustfmt
  • Loading branch information
imsnif authored Dec 1, 2023
1 parent 3aa72ba commit ac47ff4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
47 changes: 39 additions & 8 deletions zellij-server/src/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2058,6 +2058,22 @@ impl Screen {
}
session_layout_metadata
}
fn update_plugin_loading_stage(
&mut self,
pid: u32,
loading_indication: LoadingIndication,
) -> bool {
let all_tabs = self.get_tabs_mut();
let mut found_plugin = false;
for tab in all_tabs.values_mut() {
if tab.has_plugin(pid) {
found_plugin = true;
tab.update_plugin_loading_stage(pid, loading_indication);
break;
}
}
found_plugin
}
}

// The box is here in order to make the
Expand Down Expand Up @@ -2117,6 +2133,7 @@ pub(crate) fn screen_thread_main(
let mut pending_tab_switches: HashSet<(usize, ClientId)> = HashSet::new(); // usize is the
// tab_index

let mut plugin_loading_message_cache = HashMap::new();
loop {
let (event, mut err_ctx) = screen
.bus
Expand Down Expand Up @@ -2793,9 +2810,9 @@ pub(crate) fn screen_thread_main(
screen.apply_layout(
layout,
floating_panes_layout,
new_pane_pids,
new_pane_pids.clone(),
new_floating_pane_pids,
new_plugin_ids,
new_plugin_ids.clone(),
tab_index,
client_id,
)?;
Expand All @@ -2805,6 +2822,18 @@ pub(crate) fn screen_thread_main(
screen.go_to_tab(tab_index as usize, client_id)?;
}
}

for plugin_ids in new_plugin_ids.values() {
for plugin_id in plugin_ids {
if let Some(loading_indication) =
plugin_loading_message_cache.remove(plugin_id)
{
screen.update_plugin_loading_stage(*plugin_id, loading_indication);
screen.render()?;
}
}
}

screen.unblock_input()?;
screen.render()?;
},
Expand Down Expand Up @@ -3307,16 +3336,18 @@ pub(crate) fn screen_thread_main(
} else {
log::error!("Tab index not found: {:?}", tab_index);
}
if let Some(loading_indication) = plugin_loading_message_cache.remove(&plugin_id) {
screen.update_plugin_loading_stage(plugin_id, loading_indication);
screen.render()?;
}
screen.log_and_report_session_state()?;
screen.unblock_input()?;
},
ScreenInstruction::UpdatePluginLoadingStage(pid, loading_indication) => {
let all_tabs = screen.get_tabs_mut();
for tab in all_tabs.values_mut() {
if tab.has_plugin(pid) {
tab.update_plugin_loading_stage(pid, loading_indication);
break;
}
let found_plugin =
screen.update_plugin_loading_stage(pid, loading_indication.clone());
if !found_plugin {
plugin_loading_message_cache.insert(pid, loading_indication);
}
screen.render()?;
},
Expand Down
6 changes: 5 additions & 1 deletion zellij-server/src/ui/loading_indication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,11 @@ impl Display for LoadingIndication {
None => {},
}
if let Some(error_text) = &self.error {
stringified.push_str(&format!("\n\r{} {error_text}", red.bold().paint("ERROR:")));
stringified.push_str(&format!(
"\n\r{} {}",
red.bold().paint("ERROR: "),
error_text.replace('\n', "\n\r")
));
// we add this additional line explicitly to make it easier to realize when something
// is wrong in very small plugins (eg. the tab-bar and status-bar)
stringified.push_str(&format!(
Expand Down

0 comments on commit ac47ff4

Please sign in to comment.