summaryrefslogtreecommitdiffstats
path: root/zellij-tile/src
diff options
context:
space:
mode:
authordenis <denismaximov98@gmail.com>2021-05-01 13:45:01 +0300
committerdenis <denismaximov98@gmail.com>2021-05-01 13:45:01 +0300
commiteabecde90b1617ce4c29be9d5af3f52ccb67e45f (patch)
tree0d0dafa594269045f084383a9719f2a4995fe7ea /zellij-tile/src
parenta8adfdfd60c73109c5febf470f639862b331ed94 (diff)
parent325fc5620f07412381dd47dcf7cf9e141a3d66bf (diff)
chore: painless merge this time
Diffstat (limited to 'zellij-tile/src')
-rw-r--r--zellij-tile/src/data.rs15
-rw-r--r--zellij-tile/src/shim.rs31
2 files changed, 36 insertions, 10 deletions
diff --git a/zellij-tile/src/data.rs b/zellij-tile/src/data.rs
index 02a6217a7..3b53ed136 100644
--- a/zellij-tile/src/data.rs
+++ b/zellij-tile/src/data.rs
@@ -23,13 +23,15 @@ pub enum Key {
Esc,
}
-#[derive(Debug, Clone, EnumDiscriminants, ToString, Serialize, Deserialize)]
+#[derive(Debug, Clone, PartialEq, EnumDiscriminants, ToString, Serialize, Deserialize)]
#[strum_discriminants(derive(EnumString, Hash, Serialize, Deserialize))]
#[strum_discriminants(name(EventType))]
+#[non_exhaustive]
pub enum Event {
ModeUpdate(ModeInfo),
TabUpdate(Vec<TabInfo>),
KeyPress(Key),
+ Timer(f64),
}
/// Describes the different input modes, which change the way that keystrokes will be interpreted.
@@ -126,7 +128,7 @@ impl Default for Palette {
/// Represents the contents of the help message that is printed in the status bar,
/// which indicates the current [`InputMode`] and what the keybinds for that mode
/// are. Related to the default `status-bar` plugin.
-#[derive(Default, Debug, Clone, Serialize, Deserialize)]
+#[derive(Default, Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct ModeInfo {
pub mode: InputMode,
// FIXME: This should probably return Keys and Actions, then sort out strings plugin-side
@@ -134,10 +136,17 @@ pub struct ModeInfo {
pub palette: Palette,
}
-#[derive(Debug, Default, Clone, Deserialize, Serialize)]
+#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)]
pub struct TabInfo {
/* subset of fields to publish to plugins */
pub position: usize,
pub name: String,
pub active: bool,
+ pub is_sync_panes_active: bool,
+}
+
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)]
+pub struct PluginIds {
+ pub plugin_id: u32,
+ pub zellij_pid: u32,
}
diff --git a/zellij-tile/src/shim.rs b/zellij-tile/src/shim.rs
index 42a646a1f..856dcc54d 100644
--- a/zellij-tile/src/shim.rs
+++ b/zellij-tile/src/shim.rs
@@ -1,4 +1,4 @@
-use serde::de::DeserializeOwned;
+use serde::{de::DeserializeOwned, Serialize};
use std::{io, path::Path};
use crate::data::*;
@@ -6,12 +6,12 @@ use crate::data::*;
// Subscription Handling
pub fn subscribe(event_types: &[EventType]) {
- println!("{}", serde_json::to_string(event_types).unwrap());
+ object_to_stdout(&event_types);
unsafe { host_subscribe() };
}
pub fn unsubscribe(event_types: &[EventType]) {
- println!("{}", serde_json::to_string(event_types).unwrap());
+ object_to_stdout(&event_types);
unsafe { host_unsubscribe() };
}
@@ -21,21 +21,31 @@ pub fn set_max_height(max_height: i32) {
unsafe { host_set_max_height(max_height) };
}
+pub fn set_selectable(selectable: bool) {
+ unsafe { host_set_selectable(if selectable { 1 } else { 0 }) };
+}
+
pub fn set_invisible_borders(invisible_borders: bool) {
unsafe { host_set_invisible_borders(if invisible_borders { 1 } else { 0 }) };
}
-pub fn set_selectable(selectable: bool) {
- unsafe { host_set_selectable(if selectable { 1 } else { 0 }) };
+// Query Functions
+pub fn get_plugin_ids() -> PluginIds {
+ unsafe { host_get_plugin_ids() };
+ object_from_stdin()
}
// Host Functions
pub fn open_file(path: &Path) {
- println!("{}", path.to_string_lossy());
+ object_to_stdout(&path);
unsafe { host_open_file() };
}
+pub fn set_timeout(secs: f64) {
+ unsafe { host_set_timeout(secs) };
+}
+
// Internal Functions
#[doc(hidden)]
@@ -45,12 +55,19 @@ pub fn object_from_stdin<T: DeserializeOwned>() -> T {
serde_json::from_str(&json).unwrap()
}
+#[doc(hidden)]
+pub fn object_to_stdout(object: &impl Serialize) {
+ println!("{}", serde_json::to_string(object).unwrap());
+}
+
#[link(wasm_import_module = "zellij")]
extern "C" {
fn host_subscribe();
fn host_unsubscribe();
- fn host_open_file();
fn host_set_max_height(max_height: i32);
fn host_set_selectable(selectable: i32);
fn host_set_invisible_borders(invisible_borders: i32);
+ fn host_get_plugin_ids();
+ fn host_open_file();
+ fn host_set_timeout(secs: f64);
}