diff options
author | Brooks J Rady <b.j.rady@gmail.com> | 2021-04-27 17:13:25 +0100 |
---|---|---|
committer | Brooks J Rady <b.j.rady@gmail.com> | 2021-04-27 17:13:25 +0100 |
commit | e163bd56e7e0965ea1b96ca90851f118b54c377c (patch) | |
tree | 909ef1a1251c4a402b1521979d1af4abda877c0a /zellij-tile/src | |
parent | 3d926d6c03f0eaf53d86b48b2ea9d26866f8618e (diff) |
feat(plugin): simple timers implemented via the `set_timeout()` call
Diffstat (limited to 'zellij-tile/src')
-rw-r--r-- | zellij-tile/src/data.rs | 5 | ||||
-rw-r--r-- | zellij-tile/src/shim.rs | 18 |
2 files changed, 16 insertions, 7 deletions
diff --git a/zellij-tile/src/data.rs b/zellij-tile/src/data.rs index f1a77130a..fec37b173 100644 --- a/zellij-tile/src/data.rs +++ b/zellij-tile/src/data.rs @@ -23,9 +23,7 @@ pub enum Key { Esc, } -#[derive( - Debug, Clone, PartialEq, Eq, Hash, 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] @@ -33,6 +31,7 @@ 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. diff --git a/zellij-tile/src/shim.rs b/zellij-tile/src/shim.rs index ca15919fe..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() }; } @@ -38,10 +38,14 @@ pub fn get_plugin_ids() -> PluginIds { // 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)] @@ -51,6 +55,11 @@ 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(); @@ -60,4 +69,5 @@ extern "C" { fn host_set_invisible_borders(invisible_borders: i32); fn host_get_plugin_ids(); fn host_open_file(); + fn host_set_timeout(secs: f64); } |