summaryrefslogtreecommitdiffstats
path: root/zellij-tile/src
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2023-08-09 22:26:00 +0200
committerGitHub <noreply@github.com>2023-08-09 22:26:00 +0200
commit1bedfc90021558cb201695444107afe5bddd2c17 (patch)
tree38dd31b5ab112aa9b1c3a54edb07331013bf7d87 /zellij-tile/src
parentc3e140cb4b3c0897329bf07ee7f51e9fd402b3df (diff)
feat(plugins): use protocol buffers for serializing across the wasm boundary (#2686)
* work * almost done with command protobuffers * done translating command data structures * mid transferring of every command to protobuff command * transferred plugin_command.rs, now moving on to shim.rs * plugin command working with protobufs * protobuffers in update * protobuf event tests * various TODOs and comments * fix zellij-tile * clean up prost deps * remove version mismatch error * fix panic * some cleanups * clean up event protobuffers * clean up command protobuffers * clean up various protobufs * refactor protobufs * update comments * some transformation fixes * use protobufs for workers * style(fmt): rustfmt * style(fmt): rustfmt * chore(build): add protoc * chore(build): authenticate protoc
Diffstat (limited to 'zellij-tile/src')
-rw-r--r--zellij-tile/src/lib.rs50
-rw-r--r--zellij-tile/src/shim.rs529
2 files changed, 355 insertions, 224 deletions
diff --git a/zellij-tile/src/lib.rs b/zellij-tile/src/lib.rs
index 7bcaf4738..67b4a551c 100644
--- a/zellij-tile/src/lib.rs
+++ b/zellij-tile/src/lib.rs
@@ -22,6 +22,8 @@ use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use zellij_utils::data::Event;
+// use zellij_tile::shim::plugin_api::event::ProtobufEvent;
+
/// This trait should be implemented - once per plugin - on a struct (normally representing the
/// plugin state). This struct should then be registered with the
/// [`register_plugin!`](register_plugin) macro.
@@ -104,22 +106,31 @@ macro_rules! register_plugin {
#[no_mangle]
fn load() {
STATE.with(|state| {
- let configuration = $crate::shim::object_from_stdin()
- .context($crate::PLUGIN_MISMATCH)
- .to_stdout()
- .unwrap();
- state.borrow_mut().load(configuration);
+ use std::collections::BTreeMap;
+ use std::convert::TryInto;
+ use zellij_tile::shim::plugin_api::action::ProtobufPluginConfiguration;
+ use zellij_tile::shim::prost::Message;
+ let protobuf_bytes: Vec<u8> = $crate::shim::object_from_stdin().unwrap();
+ let protobuf_configuration: ProtobufPluginConfiguration =
+ ProtobufPluginConfiguration::decode(protobuf_bytes.as_slice()).unwrap();
+ let plugin_configuration: BTreeMap<String, String> =
+ BTreeMap::try_from(&protobuf_configuration).unwrap();
+ state.borrow_mut().load(plugin_configuration);
});
}
#[no_mangle]
pub fn update() -> bool {
+ let err_context = "Failed to deserialize event";
+ use std::convert::TryInto;
+ use zellij_tile::shim::plugin_api::event::ProtobufEvent;
+ use zellij_tile::shim::prost::Message;
STATE.with(|state| {
- let object = $crate::shim::object_from_stdin()
- .context($crate::PLUGIN_MISMATCH)
- .to_stdout()
- .unwrap();
- state.borrow_mut().update(object)
+ let protobuf_bytes: Vec<u8> = $crate::shim::object_from_stdin().unwrap();
+ let protobuf_event: ProtobufEvent =
+ ProtobufEvent::decode(protobuf_bytes.as_slice()).unwrap();
+ let event = protobuf_event.try_into().unwrap();
+ state.borrow_mut().update(event)
})
}
@@ -168,18 +179,15 @@ macro_rules! register_worker {
}
#[no_mangle]
pub fn $worker_name() {
-
+ use zellij_tile::shim::plugin_api::message::ProtobufMessage;
+ use zellij_tile::shim::prost::Message;
let worker_display_name = std::stringify!($worker_name);
-
- // read message from STDIN
- let (message, payload): (String, String) = $crate::shim::object_from_stdin()
- .unwrap_or_else(|e| {
- eprintln!(
- "Failed to deserialize message to worker \"{}\": {:?}",
- worker_display_name, e
- );
- Default::default()
- });
+ let protobuf_bytes: Vec<u8> = $crate::shim::object_from_stdin()
+ .unwrap();
+ let protobuf_message: ProtobufMessage = ProtobufMessage::decode(protobuf_bytes.as_slice())
+ .unwrap();
+ let message = protobuf_message.name;
+ let payload = protobuf_message.payload;
$worker_static_name.with(|worker_instance| {
let mut worker_instance = worker_instance.borrow_mut();
worker_instance.on_message(message, payload);
diff --git a/zellij-tile/src/shim.rs b/zellij-tile/src/shim.rs
index c12a61528..c3a772f96 100644
--- a/zellij-tile/src/shim.rs
+++ b/zellij-tile/src/shim.rs
@@ -1,375 +1,559 @@
use serde::{de::DeserializeOwned, Serialize};
+use std::collections::HashSet;
use std::{io, path::Path};
use zellij_utils::data::*;
use zellij_utils::errors::prelude::*;
+pub use zellij_utils::plugin_api;
+use zellij_utils::plugin_api::plugin_command::ProtobufPluginCommand;
+use zellij_utils::plugin_api::plugin_ids::{ProtobufPluginIds, ProtobufZellijVersion};
+
+pub use zellij_utils::prost::{self, *};
// Subscription Handling
/// Subscribe to a list of [`Event`]s represented by their [`EventType`]s that will then trigger the `update` method
pub fn subscribe(event_types: &[EventType]) {
- object_to_stdout(&event_types);
- unsafe { host_subscribe() };
+ let event_types: HashSet<EventType> = event_types.iter().cloned().collect();
+ let plugin_command = PluginCommand::Subscribe(event_types);
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Unsubscribe to a list of [`Event`]s represented by their [`EventType`]s.
pub fn unsubscribe(event_types: &[EventType]) {
- object_to_stdout(&event_types);
- unsafe { host_unsubscribe() };
+ let event_types: HashSet<EventType> = event_types.iter().cloned().collect();
+ let plugin_command = PluginCommand::Unsubscribe(event_types);
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
// Plugin Settings
/// Sets the plugin as selectable or unselectable to the user. Unselectable plugins might be desired when they do not accept user input.
pub fn set_selectable(selectable: bool) {
- unsafe { host_set_selectable(selectable as i32) };
+ let plugin_command = PluginCommand::SetSelectable(selectable);
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
// Query Functions
/// Returns the unique Zellij pane ID for the plugin as well as the Zellij process id.
pub fn get_plugin_ids() -> PluginIds {
- unsafe { host_get_plugin_ids() };
- object_from_stdin().unwrap()
+ let plugin_command = PluginCommand::GetPluginIds;
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
+ let protobuf_plugin_ids =
+ ProtobufPluginIds::decode(bytes_from_stdin().unwrap().as_slice()).unwrap();
+ PluginIds::try_from(protobuf_plugin_ids).unwrap()
}
/// Returns the version of the running Zellij instance - can be useful to check plugin compatibility
pub fn get_zellij_version() -> String {
- unsafe { host_get_zellij_version() };
- object_from_stdin().unwrap()
+ let plugin_command = PluginCommand::GetZellijVersion;
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
+ let protobuf_zellij_version =
+ ProtobufZellijVersion::decode(bytes_from_stdin().unwrap().as_slice()).unwrap();
+ protobuf_zellij_version.version
}
// Host Functions
/// Open a file in the user's default `$EDITOR` in a new pane
-pub fn open_file<P: AsRef<Path>>(path: P) {
- object_to_stdout(&path.as_ref());
- unsafe { host_open_file() };
+pub fn open_file(file_to_open: FileToOpen) {
+ let plugin_command = PluginCommand::OpenFile(file_to_open);
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Open a file in the user's default `$EDITOR` in a new floating pane
-pub fn open_file_floating<P: AsRef<Path>>(path: P) {
- object_to_stdout(&path.as_ref());
- unsafe { host_open_file_floating() };
-}
-
-/// Open a file to a specific line in the user's default `$EDITOR` (if it supports it, most do) in a new pane
-pub fn open_file_with_line<P: AsRef<Path>>(path: P, line: usize) {
- object_to_stdout(&(path.as_ref(), line));
- unsafe { host_open_file_with_line() };
-}
-
-/// Open a file to a specific line in the user's default `$EDITOR` (if it supports it, most do) in a new floating pane
-pub fn open_file_with_line_floating<P: AsRef<Path>>(path: P, line: usize) {
- object_to_stdout(&(path.as_ref(), line));
- unsafe { host_open_file_with_line_floating() };
+pub fn open_file_floating(file_to_open: FileToOpen) {
+ let plugin_command = PluginCommand::OpenFileFloating(file_to_open);
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Open a new terminal pane to the specified location on the host filesystem
pub fn open_terminal<P: AsRef<Path>>(path: P) {
- object_to_stdout(&path.as_ref());
- unsafe { host_open_terminal() };
+ let file_to_open = FileToOpen::new(path.as_ref().to_path_buf());
+ let plugin_command = PluginCommand::OpenTerminal(file_to_open);
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Open a new floating terminal pane to the specified location on the host filesystem
pub fn open_terminal_floating<P: AsRef<Path>>(path: P) {
- object_to_stdout(&path.as_ref());
- unsafe { host_open_terminal_floating() };
+ let file_to_open = FileToOpen::new(path.as_ref().to_path_buf());
+ let plugin_command = PluginCommand::OpenTerminalFloating(file_to_open);
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Open a new command pane with the specified command and args (this sort of pane allows the user to control the command, re-run it and see its exit status through the Zellij UI).
-pub fn open_command_pane<P: AsRef<Path>, A: AsRef<str>>(path: P, args: Vec<A>) {
- object_to_stdout(&(
- path.as_ref(),
- args.iter().map(|a| a.as_ref()).collect::<Vec<&str>>(),
- ));
- unsafe { host_open_command_pane() };
+// pub fn open_command_pane<P: AsRef<Path>, A: AsRef<str>>(path: P, args: Vec<A>) {
+pub fn open_command_pane(command_to_run: CommandToRun) {
+ let plugin_command = PluginCommand::OpenCommandPane(command_to_run);
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Open a new floating command pane with the specified command and args (this sort of pane allows the user to control the command, re-run it and see its exit status through the Zellij UI).
-pub fn open_command_pane_floating<P: AsRef<Path>, A: AsRef<str>>(path: P, args: Vec<A>) {
- object_to_stdout(&(
- path.as_ref(),
- args.iter().map(|a| a.as_ref()).collect::<Vec<&str>>(),
- ));
- unsafe { host_open_command_pane_floating() };
+// pub fn open_command_pane_floating<P: AsRef<Path>, A: AsRef<str>>(path: P, args: Vec<A>) {
+pub fn open_command_pane_floating(command_to_run: CommandToRun) {
+ let plugin_command = PluginCommand::OpenCommandPaneFloating(command_to_run);
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Change the focused tab to the specified index (corresponding with the default tab names, to starting at `1`, `0` will be considered as `1`).
pub fn switch_tab_to(tab_idx: u32) {
- unsafe { host_switch_tab_to(tab_idx) };
+ let plugin_command = PluginCommand::SwitchTabTo(tab_idx);
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Set a timeout in seconds (or fractions thereof) after which the plugins [update](./plugin-api-events#update) method will be called with the [`Timer`](./plugin-api-events.md#timer) event.
pub fn set_timeout(secs: f64) {
- unsafe { host_set_timeout(secs) };
+ let plugin_command = PluginCommand::SetTimeout(secs as f32);
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
#[doc(hidden)]
pub fn exec_cmd(cmd: &[&str]) {
- object_to_stdout(&cmd);
- unsafe { host_exec_cmd() };
+ let plugin_command =
+ PluginCommand::ExecCmd(cmd.iter().cloned().map(|s| s.to_owned()).collect());
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Hide the plugin pane (suppress it) from the UI
pub fn hide_self() {
- unsafe { host_hide_self() };
+ let plugin_command = PluginCommand::HideSelf;
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Show the plugin pane (unsuppress it if it is suppressed), focus it and switch to its tab
pub fn show_self(should_float_if_hidden: bool) {
- unsafe { host_show_self(should_float_if_hidden as i32) };
+ let plugin_command = PluginCommand::ShowSelf(should_float_if_hidden);
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Switch to the specified Input Mode (eg. `Normal`, `Tab`, `Pane`)
pub fn switch_to_input_mode(mode: &InputMode) {
- object_to_stdout(&mode);
- unsafe { host_switch_to_mode() };
+ let plugin_command = PluginCommand::SwitchToMode(*mode);
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Provide a stringified [`layout`](https://zellij.dev/documentation/layouts.html) to be applied to the current session. If the layout has multiple tabs, they will all be opened.
pub fn new_tabs_with_layout(layout: &str) {
- println!("{}", layout);
- unsafe { host_new_tabs_with_layout() }
+ let plugin_command = PluginCommand::NewTabsWithLayout(layout.to_owned());
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Open a new tab with the default layout
pub fn new_tab() {
- unsafe { host_new_tab() }
+ let plugin_command = PluginCommand::NewTab;
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Change focus to the next tab or loop back to the first
pub fn go_to_next_tab() {
- unsafe { host_go_to_next_tab() }
+ let plugin_command = PluginCommand::GoToNextTab;
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Change focus to the previous tab or loop back to the last
pub fn go_to_previous_tab() {
- unsafe { host_go_to_previous_tab() }
+ let plugin_command = PluginCommand::GoToPreviousTab;
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
pub fn report_panic(info: &std::panic::PanicInfo) {
- println!("");
- println!("A panic occured in a plugin");
- println!("{:#?}", info);
- unsafe { host_report_panic() };
+ let panic_payload = if let Some(s) = info.payload().downcast_ref::<&str>() {
+ format!("{}", s)
+ } else {
+ format!("<NO PAYLOAD>")
+ };
+ let panic_stringified = format!("{}\n\r{:#?}", panic_payload, info).replace("\n", "\r\n");
+ let plugin_command = PluginCommand::ReportPanic(panic_stringified);
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Either Increase or Decrease the size of the focused pane
pub fn resize_focused_pane(resize: Resize) {
- object_to_stdout(&resize);
- unsafe { host_resize() };
+ let plugin_command = PluginCommand::Resize(resize);
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Either Increase or Decrease the size of the focused pane in a specified direction (eg. `Left`, `Right`, `Up`, `Down`).
pub fn resize_focused_pane_with_direction(resize: Resize, direction: Direction) {
- object_to_stdout(&(resize, direction));
- unsafe { host_resize_with_direction() };
+ let resize_strategy = ResizeStrategy {
+ resize,
+ direction: Some(direction),
+ invert_on_boundaries: false,
+ };
+ let plugin_command = PluginCommand::ResizeWithDirection(resize_strategy);
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Change focus tot he next pane in chronological order
pub fn focus_next_pane() {
- unsafe { host_focus_next_pane() };
+ let plugin_command = PluginCommand::FocusNextPane;
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Change focus to the previous pane in chronological order
pub fn focus_previous_pane() {
- unsafe { host_focus_previous_pane() };
+ let plugin_command = PluginCommand::FocusPreviousPane;
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Change the focused pane in the specified direction
pub fn move_focus(direction: Direction) {
- object_to_stdout(&direction);
- unsafe { host_move_focus() };
+ let plugin_command = PluginCommand::MoveFocus(direction);
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Change the focused pane in the specified direction, if the pane is on the edge of the screen, the next tab is focused (next if right edge, previous if left edge).
pub fn move_focus_or_tab(direction: Direction) {
- object_to_stdout(&direction);
- unsafe { host_move_focus_or_tab() };
+ let plugin_command = PluginCommand::MoveFocusOrTab(direction);
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Detach the user from the active session
pub fn detach() {
- unsafe { host_detach() };
+ let plugin_command = PluginCommand::Detach;
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Edit the scrollback of the focused pane in the user's default `$EDITOR`
pub fn edit_scrollback() {
- unsafe { host_edit_scrollback() };
+ let plugin_command = PluginCommand::EditScrollback;
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Write bytes to the `STDIN` of the focused pane
pub fn write(bytes: Vec<u8>) {
- object_to_stdout(&bytes);
- unsafe { host_write() };
+ let plugin_command = PluginCommand::Write(bytes);
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Write characters to the `STDIN` of the focused pane
pub fn write_chars(chars: &str) {
- println!("{}", chars);
- unsafe { host_write_chars() };
+ let plugin_command = PluginCommand::WriteChars(chars.to_owned());
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Focused the previously focused tab (regardless of the tab position)
pub fn toggle_tab() {
- unsafe { host_toggle_tab() };
+ let plugin_command = PluginCommand::ToggleTab;
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Switch the position of the focused pane with a different pane
pub fn move_pane() {
- unsafe { host_move_pane() };
+ let plugin_command = PluginCommand::MovePane;
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Switch the position of the focused pane with a different pane in the specified direction (eg. `Down`, `Up`, `Left`, `Right`).
pub fn move_pane_with_direction(direction: Direction) {
- object_to_stdout(&direction);
- unsafe { host_move_pane_with_direction() };
+ let plugin_command = PluginCommand::MovePaneWithDirection(direction);
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Clear the scroll buffer of the focused pane
pub fn clear_screen() {
- unsafe { host_clear_screen() };
+ let plugin_command = PluginCommand::ClearScreen;
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Scroll the focused pane up 1 line
pub fn scroll_up() {
- unsafe { host_scroll_up() };
+ let plugin_command = PluginCommand::ScrollUp;
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Scroll the focused pane down 1 line
pub fn scroll_down() {
- unsafe { host_scroll_down() };
+ let plugin_command = PluginCommand::ScrollDown;
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Scroll the focused pane all the way to the top of the scrollbuffer
pub fn scroll_to_top() {
- unsafe { host_scroll_to_top() };
+ let plugin_command = PluginCommand::ScrollToTop;
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Scroll the focused pane all the way to the bottom of the scrollbuffer
pub fn scroll_to_bottom() {
- unsafe { host_scroll_to_bottom() };
+ let plugin_command = PluginCommand::ScrollToBottom;
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Scroll the focused pane up one page
pub fn page_scroll_up() {
- unsafe { host_page_scroll_up() };
+ let plugin_command = PluginCommand::PageScrollUp;
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Scroll the focused pane down one page
pub fn page_scroll_down() {
- unsafe { host_page_scroll_down() };
+ let plugin_command = PluginCommand::PageScrollDown;
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Toggle the focused pane to be fullscreen or normal sized
pub fn toggle_focus_fullscreen() {
- unsafe { host_toggle_focus_fullscreen() };
+ let plugin_command = PluginCommand::ToggleFocusFullscreen;
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Toggle the UI pane frames on or off
pub fn toggle_pane_frames() {
- unsafe { host_toggle_pane_frames() };
+ let plugin_command = PluginCommand::TogglePaneFrames;
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Embed the currently focused pane (make it stop floating) or turn it to a float pane if it is not
pub fn toggle_pane_embed_or_eject() {
- unsafe { host_toggle_pane_embed_or_eject() };
+ let plugin_command = PluginCommand::TogglePaneEmbedOrEject;
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
pub fn undo_rename_pane() {
- unsafe { host_undo_rename_pane() };
+ let plugin_command = PluginCommand::UndoRenamePane;
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Close the focused pane
pub fn close_focus() {
- unsafe { host_close_focus() };
+ let plugin_command = PluginCommand::CloseFocus;
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Turn the `STDIN` synchronization of the current tab on or off
pub fn toggle_active_tab_sync() {
- unsafe { host_toggle_active_tab_sync() };
+ let plugin_command = PluginCommand::ToggleActiveTabSync;
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Close the focused tab
pub fn close_focused_tab() {
- unsafe { host_close_focused_tab() };
+ let plugin_command = PluginCommand::CloseFocusedTab;
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
pub fn undo_rename_tab() {
- unsafe { host_undo_rename_tab() };
+ let plugin_command = PluginCommand::UndoRenameTab;
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Compeltely quit Zellij for this and all other connected clients
pub fn quit_zellij() {
- unsafe { host_quit_zellij() };
+ let plugin_command = PluginCommand::QuitZellij;
+ let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
+ object_to_stdout(&protobuf_plugin_command.encode_to_vec());
+ unsafe { host_run_plugin_command() };
}
/// Change to the previous [swap layout](https://zellij.dev/documentation/swap-layouts.html)
pub fn previous_swap_layout() {
- unsafe { host_previous_swap_layout() };