summaryrefslogtreecommitdiffstats
path: root/zellij-tile/src
diff options
context:
space:
mode:
authorBrooks J Rady <b.j.rady@gmail.com>2021-03-25 17:22:10 +0000
committerBrooks J Rady <b.j.rady@gmail.com>2021-03-25 17:22:10 +0000
commitb6f945da35065f0a0d3b384b4d0f167908c0140f (patch)
tree2fe792360569c829ca4bdd2c66f3a6a9e0748e7f /zellij-tile/src
parent84a5cf95d1168db47931f81774e1210e1f022a69 (diff)
Wrap up the plugin system refactor, running everything through update()
Diffstat (limited to 'zellij-tile/src')
-rw-r--r--zellij-tile/src/lib.rs15
-rw-r--r--zellij-tile/src/shim.rs29
2 files changed, 16 insertions, 28 deletions
diff --git a/zellij-tile/src/lib.rs b/zellij-tile/src/lib.rs
index cff3624d0..72211764b 100644
--- a/zellij-tile/src/lib.rs
+++ b/zellij-tile/src/lib.rs
@@ -9,8 +9,6 @@ pub trait ZellijTile {
fn load(&mut self) {}
fn update(&mut self, event: Event) {}
fn render(&mut self, rows: usize, cols: usize) {}
- // FIXME: Everything below this line should be purged
- fn handle_tab_rename_keypress(&mut self, key: Key) {}
}
#[macro_export]
@@ -29,9 +27,7 @@ macro_rules! register_tile {
#[no_mangle]
pub fn update() {
STATE.with(|state| {
- state
- .borrow_mut()
- .update($crate::shim::deserialize_from_stdin().unwrap());
+ state.borrow_mut().update($crate::shim::object_from_stdin());
});
}
@@ -41,14 +37,5 @@ macro_rules! register_tile {
state.borrow_mut().render(rows as usize, cols as usize);
});
}
-
- #[no_mangle]
- pub fn handle_tab_rename_keypress() {
- STATE.with(|state| {
- state
- .borrow_mut()
- .handle_tab_rename_keypress($crate::shim::get_key());
- })
- }
};
}
diff --git a/zellij-tile/src/shim.rs b/zellij-tile/src/shim.rs
index 1bb8ccabc..42a646a1f 100644
--- a/zellij-tile/src/shim.rs
+++ b/zellij-tile/src/shim.rs
@@ -3,9 +3,7 @@ use std::{io, path::Path};
use crate::data::*;
-pub fn get_key() -> Key {
- deserialize_from_stdin().unwrap()
-}
+// Subscription Handling
pub fn subscribe(event_types: &[EventType]) {
println!("{}", serde_json::to_string(event_types).unwrap());
@@ -17,31 +15,34 @@ pub fn unsubscribe(event_types: &[EventType]) {
unsafe { host_unsubscribe() };
}
-pub fn open_file(path: &Path) {
- println!("{}", path.to_string_lossy());
- unsafe { host_open_file() };
-}
+// Plugin Settings
pub fn set_max_height(max_height: i32) {
unsafe { host_set_max_height(max_height) };
}
pub fn set_invisible_borders(invisible_borders: bool) {
- let invisible_borders = if invisible_borders { 1 } else { 0 };
- unsafe { host_set_invisible_borders(invisible_borders) };
+ unsafe { host_set_invisible_borders(if invisible_borders { 1 } else { 0 }) };
}
pub fn set_selectable(selectable: bool) {
- let selectable = if selectable { 1 } else { 0 };
- unsafe { host_set_selectable(selectable) };
+ unsafe { host_set_selectable(if selectable { 1 } else { 0 }) };
+}
+
+// Host Functions
+
+pub fn open_file(path: &Path) {
+ println!("{}", path.to_string_lossy());
+ unsafe { host_open_file() };
}
+// Internal Functions
+
#[doc(hidden)]
-// FIXME: Make this just return T and do a .unwrap() at the end; also naming?
-pub fn deserialize_from_stdin<T: DeserializeOwned>() -> Option<T> {
+pub fn object_from_stdin<T: DeserializeOwned>() -> T {
let mut json = String::new();
io::stdin().read_line(&mut json).unwrap();
- serde_json::from_str(&json).ok()
+ serde_json::from_str(&json).unwrap()
}
#[link(wasm_import_module = "zellij")]