summaryrefslogtreecommitdiffstats
path: root/zellij-server/src/screen.rs
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2023-03-27 19:19:34 +0200
committerGitHub <noreply@github.com>2023-03-27 19:19:34 +0200
commit341f9eb8c8771a59b2e4d238ba49ba88c3720d6d (patch)
tree51205536dd0789efb770dbe0095af7210a60eed3 /zellij-server/src/screen.rs
parent7b609b053f3aaf466258e12be53d57614c8884c7 (diff)
feat(plugins): async plugin loading (#2327)
* work * refactor(plugins): break down start plugin async function * work * loading messages * nice ui * floating panes and error handling * cleanups and conflicting plugin/direction * find exact pane when relayouting * fix plugin pane titles * kill loading tasks on exit * refactor: move stuff around * style(fmt): rustfmt * various fixes and refactors
Diffstat (limited to 'zellij-server/src/screen.rs')
-rw-r--r--zellij-server/src/screen.rs112
1 files changed, 110 insertions, 2 deletions
diff --git a/zellij-server/src/screen.rs b/zellij-server/src/screen.rs
index 5a4223142..f1dd38741 100644
--- a/zellij-server/src/screen.rs
+++ b/zellij-server/src/screen.rs
@@ -13,7 +13,8 @@ use zellij_utils::pane_size::{Size, SizeInPixels};
use zellij_utils::{
input::command::TerminalAction,
input::layout::{
- FloatingPaneLayout, RunPluginLocation, SwapFloatingLayout, SwapTiledLayout, TiledPaneLayout,
+ FloatingPaneLayout, Run, RunPlugin, RunPluginLocation, SwapFloatingLayout, SwapTiledLayout,
+ TiledPaneLayout,
},
position::Position,
};
@@ -29,7 +30,10 @@ use crate::{
pty::{ClientOrTabIndex, PtyInstruction, VteBytes},
tab::Tab,
thread_bus::Bus,
- ui::overlay::{Overlay, OverlayWindow, Overlayable},
+ ui::{
+ loading_indication::LoadingIndication,
+ overlay::{Overlay, OverlayWindow, Overlayable},
+ },
ClientId, ServerInstruction,
};
use zellij_utils::{
@@ -250,6 +254,18 @@ pub enum ScreenInstruction {
PreviousSwapLayout(ClientId),
NextSwapLayout(ClientId),
QueryTabNames(ClientId),
+ NewTiledPluginPane(RunPluginLocation, Option<String>, ClientId), // Option<String> is
+ NewFloatingPluginPane(RunPluginLocation, Option<String>, ClientId), // Option<String> is an
+ // optional pane title
+ AddPlugin(
+ Option<bool>, // should_float
+ RunPlugin,
+ Option<String>, // pane title
+ usize, // tab index
+ u32, // plugin id
+ ),
+ UpdatePluginLoadingStage(u32, LoadingIndication), // u32 - plugin_id
+ ProgressPluginLoadingOffset(u32), // u32 - plugin id
}
impl From<&ScreenInstruction> for ScreenContext {
@@ -393,6 +409,15 @@ impl From<&ScreenInstruction> for ScreenContext {
ScreenInstruction::PreviousSwapLayout(..) => ScreenContext::PreviousSwapLayout,
ScreenInstruction::NextSwapLayout(..) => ScreenContext::NextSwapLayout,
ScreenInstruction::QueryTabNames(..) => ScreenContext::QueryTabNames,
+ ScreenInstruction::NewTiledPluginPane(..) => ScreenContext::NewTiledPluginPane,
+ ScreenInstruction::NewFloatingPluginPane(..) => ScreenContext::NewFloatingPluginPane,
+ ScreenInstruction::AddPlugin(..) => ScreenContext::AddPlugin,
+ ScreenInstruction::UpdatePluginLoadingStage(..) => {
+ ScreenContext::UpdatePluginLoadingStage
+ },
+ ScreenInstruction::ProgressPluginLoadingOffset(..) => {
+ ScreenContext::ProgressPluginLoadingOffset
+ },
}
}
}
@@ -2426,6 +2451,89 @@ pub(crate) fn screen_thread_main(
.senders
.send_to_server(ServerInstruction::Log(tab_names, client_id))?;
},
+ ScreenInstruction::NewTiledPluginPane(run_plugin_location, pane_title, client_id) => {
+ let tab_index = screen.active_tab_indices.values().next().unwrap_or(&1);
+ let size = Size::default();
+ let should_float = Some(false);
+ let run_plugin = RunPlugin {
+ _allow_exec_host_cmd: false,
+ location: run_plugin_location,
+ };
+ screen.bus.senders.send_to_plugin(PluginInstruction::Load(
+ should_float,
+ pane_title,
+ run_plugin,
+ *tab_index,
+ client_id,
+ size,
+ ))?;
+ },
+ ScreenInstruction::NewFloatingPluginPane(
+ run_plugin_location,
+ pane_title,
+ client_id,
+ ) => {
+ let tab_index = screen.active_tab_indices.values().next().unwrap(); // TODO: no
+ // unwrap and
+ // better
+ let size = Size::default(); // TODO: ???
+ let should_float = Some(true);
+ let run_plugin = RunPlugin {
+ _allow_exec_host_cmd: false,
+ location: run_plugin_location,
+ };
+ screen.bus.senders.send_to_plugin(PluginInstruction::Load(
+ should_float,
+ pane_title,
+ run_plugin,
+ *tab_index,
+ client_id,
+ size,
+ ))?;
+ },
+ ScreenInstruction::AddPlugin(
+ should_float,
+ run_plugin_location,
+ pane_title,
+ tab_index,
+ plugin_id,
+ ) => {
+ let pane_title =
+ pane_title.unwrap_or_else(|| run_plugin_location.location.to_string());
+ let run_plugin = Run::Plugin(run_plugin_location);
+ if let Some(active_tab) = screen.tabs.get_mut(&tab_index) {
+ active_tab.new_plugin_pane(
+ PaneId::Plugin(plugin_id),
+ pane_title,
+ should_float,
+ run_plugin,
+ None,
+ )?;
+ } else {
+ log::error!("Tab index not found: {:?}", tab_index);
+ }
+ 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;
+ }
+ }
+ screen.render()?;
+ },
+ ScreenInstruction::ProgressPluginLoadingOffset(pid) => {
+ let all_tabs = screen.get_tabs_mut();
+ for tab in all_tabs.values_mut() {
+ if tab.has_plugin(pid) {
+ tab.progress_plugin_loading_offset(pid);
+ break;
+ }
+ }
+ screen.render()?;
+ },
}
}
Ok(())