aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-server/src/screen.rs
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2023-06-15 17:07:40 +0200
committerGitHub <noreply@github.com>2023-06-15 17:07:40 +0200
commitbcbd940bf94cd76751af9b5fad64b716ce2cd3e6 (patch)
tree3bfed3792edd57f074c4aed9093c90bc6ed215fe /zellij-server/src/screen.rs
parentdocs(changelog): relative plugin urls (diff)
downloadsl0ppij-bcbd940bf94cd76751af9b5fad64b716ce2cd3e6.tar.gz
sl0ppij-bcbd940bf94cd76751af9b5fad64b716ce2cd3e6.tar.xz
sl0ppij-bcbd940bf94cd76751af9b5fad64b716ce2cd3e6.zip
feat(plugins): plugin pane state events (#2545)
* feat(plugins): report pane state to plugins * refactor(plugins): rename some stuff * tests(plugins): adjust for new behavior * style(fmt): rustfmt
Diffstat (limited to 'zellij-server/src/screen.rs')
-rw-r--r--zellij-server/src/screen.rs144
1 files changed, 104 insertions, 40 deletions
diff --git a/zellij-server/src/screen.rs b/zellij-server/src/screen.rs
index 81177748..ae62be37 100644
--- a/zellij-server/src/screen.rs
+++ b/zellij-server/src/screen.rs
@@ -6,7 +6,7 @@ use std::path::PathBuf;
use std::rc::Rc;
use std::str;
-use zellij_utils::data::{Direction, Resize, ResizeStrategy};
+use zellij_utils::data::{Direction, PaneManifest, Resize, ResizeStrategy};
use zellij_utils::errors::prelude::*;
use zellij_utils::input::command::RunCommand;
use zellij_utils::input::options::Clipboard;
@@ -714,7 +714,8 @@ impl Screen {
.non_fatal();
}
- self.update_tabs().with_context(err_context)?;
+ self.report_tab_state().with_context(err_context)?;
+ self.report_pane_state().with_context(err_context)?;
return self.render().with_context(err_context);
},
Err(err) => Err::<(), _>(err).with_context(err_context).non_fatal(),
@@ -843,7 +844,8 @@ impl Screen {
t.position -= 1;
}
}
- self.update_tabs().with_context(err_context)?;
+ self.report_tab_state().with_context(err_context)?;
+ self.report_pane_state().with_context(err_context)?;
self.render().with_context(err_context)
}
}
@@ -880,6 +882,7 @@ impl Screen {
.with_context(err_context)?;
tab.set_force_render();
}
+ self.report_pane_state().with_context(err_context)?;
self.render().with_context(err_context)
}
@@ -1145,9 +1148,10 @@ impl Screen {
self.add_client(client_id).with_context(err_context)?;
}
- self.update_tabs()
+ self.report_tab_state()
.and_then(|_| self.render())
- .with_context(err_context)
+ .with_context(err_context)?;
+ self.report_pane_state().with_context(err_context)
}
pub fn add_client(&mut self, client_id: ClientId) -> Result<()> {
@@ -1198,10 +1202,10 @@ impl Screen {
self.tab_history.remove(&client_id);
}
self.connected_clients.borrow_mut().remove(&client_id);
- self.update_tabs().with_context(err_context)
+ self.report_tab_state().with_context(err_context)
}
- pub fn update_tabs(&self) -> Result<()> {
+ pub fn report_tab_state(&self) -> Result<()> {
let mut plugin_updates = vec![];
for (client_id, active_tab_index) in self.active_tab_indices.iter() {
let mut tab_data = vec![];
@@ -1240,6 +1244,21 @@ impl Screen {
.context("failed to update tabs")?;
Ok(())
}
+ fn report_pane_state(&self) -> Result<()> {
+ let mut pane_manifest = PaneManifest::default();
+ for tab in self.tabs.values() {
+ pane_manifest.panes.insert(tab.position, tab.pane_infos());
+ }
+ self.bus
+ .senders
+ .send_to_plugin(PluginInstruction::Update(vec![(
+ None,
+ None,
+ Event::PaneUpdate(pane_manifest),
+ )]))
+ .context("failed to update tabs")?;
+ Ok(())
+ }
pub fn update_active_tab_name(&mut self, buf: Vec<u8>, client_id: ClientId) -> Result<()> {
let err_context =
@@ -1273,7 +1292,7 @@ impl Screen {
}
},
}
- self.update_tabs().with_context(err_context)
+ self.report_tab_state().with_context(err_context)
},
Err(err) => {
Err::<(), _>(err).with_context(err_context).non_fatal();
@@ -1298,7 +1317,7 @@ impl Screen {
Ok(active_tab) => {
if active_tab.name != active_tab.prev_name {
active_tab.name = active_tab.prev_name.clone();
- self.update_tabs()
+ self.report_tab_state()
.context("failed to undo renaming of active tab")?;
}
},
@@ -1418,6 +1437,7 @@ impl Screen {
Err(err) => Err::<(), _>(err).with_context(err_context).non_fatal(),
};
}
+ self.report_pane_state().with_context(err_context)?;
Ok(())
}
pub fn move_focus_right_or_next_tab(&mut self, client_id: ClientId) -> Result<()> {
@@ -1452,6 +1472,7 @@ impl Screen {
Err(err) => Err::<(), _>(err).with_context(err_context).non_fatal(),
};
}
+ self.report_pane_state().with_context(err_context)?;
Ok(())
}
pub fn toggle_tab(&mut self, client_id: ClientId) -> Result<()> {
@@ -1464,7 +1485,8 @@ impl Screen {
.context("failed to toggle tabs")?;
};
- self.update_tabs().context("failed to toggle tabs")?;
+ self.report_tab_state().context("failed to toggle tabs")?;
+ self.report_pane_state().context("failed to toggle tabs")?;
self.render()
}
@@ -1492,6 +1514,7 @@ impl Screen {
.with_context(err_context)?
.focus_pane_with_id(plugin_pane_id, should_float, client_id)
.context("failed to focus plugin pane")?;
+ self.report_pane_state().with_context(err_context)?;
Ok(true)
},
None => Ok(false),
@@ -1631,7 +1654,8 @@ pub(crate) fn screen_thread_main(
},
};
screen.unblock_input()?;
- screen.update_tabs()?;
+ screen.report_tab_state()?;
+ screen.report_pane_state()?;
screen.render()?;
},
@@ -1639,7 +1663,8 @@ pub(crate) fn screen_thread_main(
active_tab!(screen, client_id, |tab: &mut Tab| tab
.suppress_active_pane(pid, client_id), ?);
screen.unblock_input()?;
- screen.update_tabs()?;
+ screen.report_tab_state()?;
+ screen.report_pane_state()?;
screen.render()?;
},
@@ -1647,7 +1672,8 @@ pub(crate) fn screen_thread_main(
active_tab_and_connected_client_id!(screen, client_id, |tab: &mut Tab, client_id: ClientId| tab
.toggle_pane_embed_or_floating(client_id), ?);
screen.unblock_input()?;
- screen.update_tabs()?; // update tabs so that the ui indication will be send to the plugins
+ screen.report_tab_state()?; // update tabs so that the ui indication will be send to the plugins
+ screen.report_pane_state()?;
screen.render()?;
},
@@ -1655,7 +1681,8 @@ pub(crate) fn screen_thread_main(
active_tab_and_connected_client_id!(screen, client_id, |tab: &mut Tab, client_id: ClientId| tab
.toggle_floating_panes(Some(client_id), default_shell), ?);
screen.unblock_input()?;
- screen.update_tabs()?; // update tabs so that the ui indication will be send to the plugins
+ screen.report_tab_state()?; // update tabs so that the ui indication will be send to the plugins
+ screen.report_pane_state()?;
screen.render()?;
},
@@ -1685,7 +1712,8 @@ pub(crate) fn screen_thread_main(
);
}
screen.unblock_input()?;
- screen.update_tabs()?;
+ screen.report_tab_state()?;
+ screen.report_pane_state()?;
screen.render()?;
},
ScreenInstruction::VerticalSplit(
@@ -1714,11 +1742,12 @@ pub(crate) fn screen_thread_main(
);
}
screen.unblock_input()?;
- screen.update_tabs()?;
+ screen.report_tab_state()?;
+ screen.report_pane_state()?;
screen.render()?;
},
ScreenInstruction::WriteCharacter(bytes, client_id) => {
- let mut should_update_tabs = false;
+ let mut state_changed = false;
active_tab_and_connected_client_id!(
screen,
client_id,
@@ -1728,14 +1757,15 @@ pub(crate) fn screen_thread_main(
false => tab.write_to_active_terminal(bytes, client_id),
};
if let Ok(true) = write_result {
- should_update_tabs = true;
+ state_changed = true;
}
write_result
},
?
);
- if should_update_tabs {
- screen.update_tabs()?;
+ if state_changed {
+ screen.report_tab_state()?;
+ screen.report_pane_state()?;
}
},
ScreenInstruction::Resize(client_id, strategy) => {
@@ -1747,7 +1777,8 @@ pub(crate) fn screen_thread_main(
);
screen.unblock_input()?;
screen.render()?;
- screen.update_tabs()?; // TODO: no every time
+ screen.report_tab_state()?;
+ screen.report_pane_state()?;
},
ScreenInstruction::SwitchFocus(client_id) => {
active_tab_and_connected_client_id!(
@@ -1757,6 +1788,7 @@ pub(crate) fn screen_thread_main(
);
screen.unblock_input()?;
screen.render()?;
+ screen.report_pane_state()?;
},
ScreenInstruction::FocusNextPane(client_id) => {
active_tab_and_connected_client_id!(
@@ -1775,6 +1807,7 @@ pub(crate) fn screen_thread_main(
);
screen.render()?;
screen.unblock_input()?;
+ screen.report_pane_state()?;
},
ScreenInstruction::MoveFocusLeft(client_id) => {
active_tab_and_connected_client_id!(
@@ -1785,11 +1818,13 @@ pub(crate) fn screen_thread_main(
);
screen.render()?;
screen.unblock_input()?;
+ screen.report_pane_state()?;
},
ScreenInstruction::MoveFocusLeftOrPreviousTab(client_id) => {
screen.move_focus_left_or_previous_tab(client_id)?;
screen.unblock_input()?;
screen.render()?;
+ screen.report_pane_state()?;
},
ScreenInstruction::MoveFocusDown(client_id) => {
active_tab_and_connected_client_id!(
@@ -1800,6 +1835,7 @@ pub(crate) fn screen_thread_main(
);
screen.render()?;
screen.unblock_input()?;
+ screen.report_pane_state()?;
},
ScreenInstruction::MoveFocusRight(client_id) => {
active_tab_and_connected_client_id!(
@@ -1810,11 +1846,13 @@ pub(crate) fn screen_thread_main(
);
screen.render()?;
screen.unblock_input()?;
+ screen.report_pane_state()?;
},
ScreenInstruction::MoveFocusRightOrNextTab(client_id) => {
screen.move_focus_right_or_next_tab(client_id)?;
screen.unblock_input()?;
screen.render()?;
+ screen.report_pane_state()?;
},
ScreenInstruction::MoveFocusUp(client_id) => {
active_tab_and_connected_client_id!(
@@ -1825,6 +1863,7 @@ pub(crate) fn screen_thread_main(
);
screen.render()?;
screen.unblock_input()?;
+ screen.report_pane_state()?;
},
ScreenInstruction::ClearScreen(client_id) => {
active_tab_and_connected_client_id!(
@@ -1860,6 +1899,7 @@ pub(crate) fn screen_thread_main(
?
);
screen.render()?;
+ screen.report_pane_state()?;
},
ScreenInstruction::ScrollUp(client_id) => {
active_tab_and_connected_client_id!(
@@ -1876,9 +1916,10 @@ pub(crate) fn screen_thread_main(
client_id,
|tab: &mut Tab, client_id: ClientId| tab.move_active_pane(client_id)
);
- screen.update_tabs()?; // update tabs so that the ui indication will be send to the plugins
+ screen.report_tab_state()?; // update tabs so that the ui indication will be send to the plugins
screen.render()?;
screen.unblock_input()?;
+ screen.report_pane_state()?;
},
ScreenInstruction::MovePaneBackwards(client_id) => {
active_tab_and_connected_client_id!(
@@ -1886,9 +1927,10 @@ pub(crate) fn screen_thread_main(
client_id,
|tab: &mut Tab, client_id: ClientId| tab.move_active_pane_backwards(client_id)
);
- screen.update_tabs()?; // update tabs so that the ui indication will be send to the plugins
+ screen.report_tab_state()?; // update tabs so that the ui indication will be send to the plugins
screen.render()?;
screen.unblock_input()?;
+ screen.report_pane_state()?;
},
ScreenInstruction::MovePaneDown(client_id) => {
active_tab_and_connected_client_id!(
@@ -1896,9 +1938,10 @@ pub(crate) fn screen_thread_main(
client_id,
|tab: &mut Tab, client_id: ClientId| tab.move_active_pane_down(client_id)
);
- screen.update_tabs()?; // update tabs so that the ui indication will be send to the plugins
+ screen.report_tab_state()?; // update tabs so that the ui indication will be send to the plugins
screen.render()?;
screen.unblock_input()?;
+ screen.report_pane_state()?;
},
ScreenInstruction::MovePaneUp(client_id) => {
active_tab_and_connected_client_id!(
@@ -1906,9 +1949,10 @@ pub(crate) fn screen_thread_main(
client_id,
|tab: &mut Tab, client_id: ClientId| tab.move_active_pane_up(client_id)
);
- screen.update_tabs()?; // update tabs so that the ui indication will be send to the plugins
+ screen.report_tab_state()?; // update tabs so that the ui indication will be send to the plugins
screen.render()?;
screen.unblock_input()?;
+ screen.report_pane_state()?;
},
ScreenInstruction::MovePaneRight(client_id) => {
active_tab_and_connected_client_id!(
@@ -1916,9 +1960,10 @@ pub(crate) fn screen_thread_main(
client_id,
|tab: &mut Tab, client_id: ClientId| tab.move_active_pane_right(client_id)
);
- screen.update_tabs()?; // update tabs so that the ui indication will be send to the plugins
+ screen.report_tab_state()?; // update tabs so that the ui indication will be send to the plugins
screen.render()?;
screen.unblock_input()?;
+ screen.report_pane_state()?;
},
ScreenInstruction::MovePaneLeft(client_id) => {
active_tab_and_connected_client_id!(
@@ -1926,9 +1971,10 @@ pub(crate) fn screen_thread_main(
client_id,
|tab: &mut Tab, client_id: ClientId| tab.move_active_pane_left(client_id)
);
- screen.update_tabs()?; // update tabs so that the ui indication will be send to the plugins
+ screen.report_tab_state()?; // update tabs so that the ui indication will be send to the plugins
screen.render()?;
screen.unblock_input()?;
+ screen.report_pane_state()?;
},
ScreenInstruction::ScrollUpAt(point, client_id) => {
active_tab_and_connected_client_id!(
@@ -2035,9 +2081,10 @@ pub(crate) fn screen_thread_main(
client_id,
|tab: &mut Tab, client_id: ClientId| tab.close_focused_pane(client_id), ?
);
- screen.update_tabs()?;
+ screen.report_tab_state()?;
screen.render()?;
screen.unblock_input()?;
+ screen.report_pane_state()?;
},
ScreenInstruction::SetSelectable(id, selectable, tab_index) => {
screen.get_indexed_tab_mut(tab_index).map_or_else(
@@ -2052,6 +2099,7 @@ pub(crate) fn screen_thread_main(
);
screen.render()?;
+ screen.report_pane_state()?;
},
ScreenInstruction::ClosePane(id, client_id) => {
match client_id {
@@ -2071,8 +2119,9 @@ pub(crate) fn screen_thread_main(
}
},
}
- screen.update_tabs()?;
+ screen.report_tab_state()?;
screen.unblock_input()?;
+ screen.report_pane_state()?;
},
ScreenInstruction::HoldPane(id, exit_status, run_command, tab_index, client_id) => {
let is_first_run = false;
@@ -2101,8 +2150,9 @@ pub(crate) fn screen_thread_main(
}
},
}
- screen.update_tabs()?;
+ screen.report_tab_state()?;
screen.unblock_input()?;
+ screen.report_pane_state()?;
},
ScreenInstruction::UpdatePaneName(c, client_id) => {
active_tab_and_connected_client_id!(
@@ -2112,6 +2162,7 @@ pub(crate) fn screen_thread_main(
);
screen.render()?;
screen.unblock_input()?;
+ screen.report_pane_state()?;
},
ScreenInstruction::UndoRenamePane(client_id) => {
active_tab_and_connected_client_id!(
@@ -2129,9 +2180,10 @@ pub(crate) fn screen_thread_main(
|tab: &mut Tab, client_id: ClientId| tab
.toggle_active_pane_fullscreen(client_id)
);
- screen.update_tabs()?;
+ screen.report_tab_state()?;
screen.render()?;
screen.unblock_input()?;
+ screen.report_pane_state()?;
},
ScreenInstruction::TogglePaneFrames => {
screen.draw_pane_frames = !screen.draw_pane_frames;
@@ -2140,6 +2192,7 @@ pub(crate) fn screen_thread_main(
}
screen.render()?;
screen.unblock_input()?;
+ screen.report_pane_state()?;
},
ScreenInstruction::SwitchTabNext(client_id) => {
screen.switch_tab_next(None, client_id)?;
@@ -2287,7 +2340,7 @@ pub(crate) fn screen_thread_main(
},
ScreenInstruction::TerminalResize(new_size) => {
screen.resize_to_screen(new_size)?;
- screen.update_tabs()?; // update tabs so that the ui indication will be send to the plugins
+ screen.report_tab_state()?; // update tabs so that the ui indication will be send to the plugins
screen.render()?;
},
ScreenInstruction::TerminalPixelDimensions(pixel_dimensions) => {
@@ -2318,28 +2371,31 @@ pub(crate) fn screen_thread_main(
client_id,
|tab: &mut Tab, _client_id: ClientId| tab.toggle_sync_panes_is_active()
);
- screen.update_tabs()?;
+ screen.report_tab_state()?;
screen.render()?;
screen.unblock_input()?;
},
ScreenInstruction::LeftClick(point, client_id) => {
active_tab!(screen, client_id, |tab: &mut Tab| tab
.handle_left_click(&point, client_id), ?);
- screen.update_tabs()?;
+ screen.report_tab_state()?;
+ screen.report_pane_state()?;
screen.render()?;
screen.unblock_input()?;
},
ScreenInstruction::RightClick(point, client_id) => {
active_tab!(screen, client_id, |tab: &mut Tab| tab
.handle_right_click(&point, client_id), ?);
- screen.update_tabs()?;
+ screen.report_tab_state()?;
+ screen.report_pane_state()?;
screen.render()?;
screen.unblock_input()?;
},
ScreenInstruction::MiddleClick(point, client_id) => {
active_tab!(screen, client_id, |tab: &mut Tab| tab
.handle_middle_click(&point, client_id), ?);
- screen.update_tabs()?;
+ screen.report_tab_state()?;
+ screen.report_pane_state()?;
screen.render()?;
screen.unblock_input()?;
},
@@ -2389,11 +2445,13 @@ pub(crate) fn screen_thread_main(
},
ScreenInstruction::AddClient(client_id) => {
screen.add_client(client_id)?;
- screen.update_tabs()?;
+ screen.report_tab_state()?;
+ screen.report_pane_state()?;
screen.render()?;
},
ScreenInstruction::RemoveClient(client_id) => {
screen.remove_client(client_id)?;
+ screen.report_pane_state()?;
screen.render()?;
},
ScreenInstruction::AddOverlay(overlay, _client_id) => {
@@ -2508,7 +2566,8 @@ pub(crate) fn screen_thread_main(
?
);
screen.render()?;
- screen.update_tabs()?;
+ screen.report_tab_state()?;
+ screen.report_pane_state()?;
screen.unblock_input()?;
},
ScreenInstruction::NextSwapLayout(client_id) => {
@@ -2519,7 +2578,8 @@ pub(crate) fn screen_thread_main(
?
);
screen.render()?;
- screen.update_tabs()?;
+ screen.report_tab_state()?;
+ screen.report_pane_state()?;
screen.unblock_input()?;
},
ScreenInstruction::QueryTabNames(client_id) => {
@@ -2609,6 +2669,7 @@ pub(crate) fn screen_thread_main(
} else {
log::error!("Tab index not found: {:?}", tab_index);
}
+ screen.report_pane_state()?;
screen.unblock_input()?;
},
ScreenInstruction::UpdatePluginLoadingStage(pid, loading_indication) => {
@@ -2646,7 +2707,8 @@ pub(crate) fn screen_thread_main(
for tab in all_tabs.values_mut() {
tab.update_input_modes()?;
}
- screen.update_tabs()?;
+ screen.report_tab_state()?;
+ screen.report_pane_state()?;
screen.render()?;
},
ScreenInstruction::LaunchOrFocusPlugin(run_plugin, should_float, client_id) => {
@@ -2665,6 +2727,7 @@ pub(crate) fn screen_thread_main(
Some((tab_index, client_id)) => {
if screen.focus_plugin_pane(&run_plugin, should_float, client_id)? {
screen.render()?;
+ screen.report_pane_state()?;
} else {
screen.bus.senders.send_to_plugin(PluginInstruction::Load(
Some(should_float),
@@ -2688,6 +2751,7 @@ pub(crate) fn screen_thread_main(
break;
}
}
+ screen.report_pane_state()?;
},
}
}