Skip to content

Commit

Permalink
feat: Add a plugins manifest to allow for more configuration of plugins
Browse files Browse the repository at this point in the history
* feat: Plugins can now be instantiated as headless (paneless)

* feat: Config field is passed through from manifest into plugins
  • Loading branch information
Jesse Tuchsen committed Sep 6, 2021
1 parent 6ec5195 commit 62d7b35
Show file tree
Hide file tree
Showing 19 changed files with 560 additions and 109 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion default-plugins/status-bar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ fn color_elements(palette: Palette) -> ColoredElements {
}

impl ZellijPlugin for State {
fn load(&mut self) {
fn load(&mut self, _: Options) {
set_selectable(false);
subscribe(&[
EventType::ModeUpdate,
Expand Down
2 changes: 1 addition & 1 deletion default-plugins/strider/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use zellij_tile::prelude::*;
register_plugin!(State);

impl ZellijPlugin for State {
fn load(&mut self) {
fn load(&mut self, _: Options) {
refresh_directory(self);
subscribe(&[EventType::KeyPress]);
}
Expand Down
2 changes: 1 addition & 1 deletion default-plugins/tab-bar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static ARROW_SEPARATOR: &str = "";
register_plugin!(State);

impl ZellijPlugin for State {
fn load(&mut self) {
fn load(&mut self, _: Options) {
set_selectable(false);
subscribe(&[EventType::TabUpdate, EventType::ModeUpdate]);
}
Expand Down
1 change: 1 addition & 0 deletions zellij-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ pub fn start_client(
Box::new(opts),
Box::new(config_options.clone()),
layout.unwrap(),
Some(config.plugins.clone()),
)
}
};
Expand Down
49 changes: 38 additions & 11 deletions zellij-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use zellij_utils::{
get_mode_info,
layout::LayoutFromYaml,
options::Options,
plugins::Plugins,
},
ipc::{ClientAttributes, ClientToServerMsg, ExitReason, ServerToClientMsg},
setup::get_default_data_dir,
Expand All @@ -46,7 +47,13 @@ use zellij_utils::{
/// Instructions related to server-side application
#[derive(Debug, Clone)]
pub(crate) enum ServerInstruction {
NewClient(ClientAttributes, Box<CliArgs>, Box<Options>, LayoutFromYaml),
NewClient(
ClientAttributes,
Box<CliArgs>,
Box<Options>,
LayoutFromYaml,
Option<Plugins>,
),
Render(Option<String>),
UnblockInputThread,
ClientExit,
Expand All @@ -58,8 +65,8 @@ pub(crate) enum ServerInstruction {
impl From<ClientToServerMsg> for ServerInstruction {
fn from(instruction: ClientToServerMsg) -> Self {
match instruction {
ClientToServerMsg::NewClient(attrs, opts, options, layout) => {
ServerInstruction::NewClient(attrs, opts, options, layout)
ClientToServerMsg::NewClient(attrs, opts, options, layout, plugins) => {
ServerInstruction::NewClient(attrs, opts, options, layout, plugins)
}
ClientToServerMsg::AttachClient(attrs, force, options) => {
ServerInstruction::AttachClient(attrs, force, options)
Expand Down Expand Up @@ -199,15 +206,24 @@ pub fn start_server(os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) {
let (instruction, mut err_ctx) = server_receiver.recv().unwrap();
err_ctx.add_call(ContextType::IPCServer((&instruction).into()));
match instruction {
ServerInstruction::NewClient(client_attributes, opts, config_options, layout) => {
ServerInstruction::NewClient(
client_attributes,
opts,
config_options,
layout,
plugins,
) => {
let session = init_session(
os_input.clone(),
opts,
config_options.clone(),
to_server.clone(),
client_attributes,
session_state.clone(),
layout.clone(),
SessionOptions {
opts,
layout: layout.clone(),
plugins,
config_options: config_options.clone(),
},
);
*session_data.write().unwrap() = Some(session);
*session_state.write().unwrap() = SessionState::Attached;
Expand Down Expand Up @@ -305,15 +321,26 @@ pub fn start_server(os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) {
drop(std::fs::remove_file(&socket_path));
}

pub struct SessionOptions {
pub opts: Box<CliArgs>,
pub config_options: Box<Options>,
pub layout: LayoutFromYaml,
pub plugins: Option<Plugins>,
}

fn init_session(
os_input: Box<dyn ServerOsApi>,
opts: Box<CliArgs>,
config_options: Box<Options>,
to_server: SenderWithContext<ServerInstruction>,
client_attributes: ClientAttributes,
session_state: Arc<RwLock<SessionState>>,
layout: LayoutFromYaml,
options: SessionOptions,
) -> SessionMetaData {
let SessionOptions {
opts,
config_options,
layout,
plugins,
} = options;
let (to_screen, screen_receiver): ChannelWithContext<ScreenInstruction> = channels::unbounded();
let to_screen = SenderWithContext::new(to_screen);

Expand Down Expand Up @@ -397,7 +424,7 @@ fn init_session(
);
let store = Store::default();

move || wasm_thread_main(plugin_bus, store, data_dir)
move || wasm_thread_main(plugin_bus, store, data_dir, plugins.unwrap_or_default())
})
.unwrap();
SessionMetaData {
Expand Down
6 changes: 3 additions & 3 deletions zellij-server/src/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,13 @@ impl Tab {

for (layout, position_and_size) in positions_and_size {
// A plugin pane
if let Some(Run::Plugin(Some(plugin))) = &layout.run {
if let Some(Run::Plugin(tag)) = layout.run.clone() {
let (pid_tx, pid_rx) = channel();
self.senders
.send_to_plugin(PluginInstruction::Load(pid_tx, plugin.clone(), tab_index))
.send_to_plugin(PluginInstruction::Load(pid_tx, tag.clone(), tab_index))
.unwrap();
let pid = pid_rx.recv().unwrap();
let title = String::from(plugin.as_path().as_os_str().to_string_lossy());
let title = String::from(tag);
let mut new_plugin = PluginPane::new(
pid,
*position_and_size,
Expand Down
Loading

0 comments on commit 62d7b35

Please sign in to comment.