From 6d948537c76e52f702641f3c22790b9f15d10955 Mon Sep 17 00:00:00 2001 From: jaeheonji Date: Wed, 24 Nov 2021 05:06:43 +0900 Subject: [PATCH 1/3] feat: add draft of feature --- zellij-server/src/wasm_vm.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/zellij-server/src/wasm_vm.rs b/zellij-server/src/wasm_vm.rs index 5e1b159d7d..7440eaa21c 100644 --- a/zellij-server/src/wasm_vm.rs +++ b/zellij-server/src/wasm_vm.rs @@ -238,6 +238,8 @@ fn start_plugin( let start = instance.exports.get_function("_start").unwrap(); // This eventually calls the `.load()` method + // TODO: pass the zellij version to the plugins. + // zellij version can be obtained from [`zellij-utils::consts`] by calling [`zellij-utils::consts::VERSION`] start.call(&[]).unwrap(); (instance, plugin_env) From 960344ea681448c55d6ae56c2c574df088667a97 Mon Sep 17 00:00:00 2001 From: jaeheonji Date: Thu, 25 Nov 2021 00:45:15 +0900 Subject: [PATCH 2/3] feat(wasm): add plugin API for getting of zellij version --- zellij-server/src/wasm_vm.rs | 9 ++++++--- zellij-tile/src/shim.rs | 13 +++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/zellij-server/src/wasm_vm.rs b/zellij-server/src/wasm_vm.rs index 7440eaa21c..6ee37ad3e9 100644 --- a/zellij-server/src/wasm_vm.rs +++ b/zellij-server/src/wasm_vm.rs @@ -28,7 +28,7 @@ use crate::{ }; use zellij_utils::{ - consts::ZELLIJ_PROJ_DIR, + consts::{VERSION, ZELLIJ_PROJ_DIR}, errors::{ContextType, PluginContext}, }; use zellij_utils::{ @@ -238,8 +238,6 @@ fn start_plugin( let start = instance.exports.get_function("_start").unwrap(); // This eventually calls the `.load()` method - // TODO: pass the zellij version to the plugins. - // zellij version can be obtained from [`zellij-utils::consts`] by calling [`zellij-utils::consts::VERSION`] start.call(&[]).unwrap(); (instance, plugin_env) @@ -264,6 +262,7 @@ pub(crate) fn zellij_exports(store: &Store, plugin_env: &PluginEnv) -> ImportObj host_unsubscribe, host_set_selectable, host_get_plugin_ids, + host_get_zellij_version, host_open_file, host_switch_tab_to, host_set_timeout, @@ -313,6 +312,10 @@ fn host_get_plugin_ids(plugin_env: &PluginEnv) { wasi_write_object(&plugin_env.wasi_env, &ids); } +fn host_get_zellij_version(plugin_env: &PluginEnv) { + wasi_write_string(&plugin_env.wasi_env, VERSION); +} + fn host_open_file(plugin_env: &PluginEnv) { let path: PathBuf = wasi_read_object(&plugin_env.wasi_env); plugin_env diff --git a/zellij-tile/src/shim.rs b/zellij-tile/src/shim.rs index c664d36b04..c0eef23b7a 100644 --- a/zellij-tile/src/shim.rs +++ b/zellij-tile/src/shim.rs @@ -27,6 +27,11 @@ pub fn get_plugin_ids() -> PluginIds { object_from_stdin().unwrap() } +pub fn get_zellij_version() -> String { + unsafe { host_get_zellij_version() }; + string_from_stdin() +} + // Host Functions pub fn open_file(path: &Path) { @@ -48,6 +53,13 @@ pub fn exec_cmd(cmd: &[&str]) { // Internal Functions +#[doc(hidden)] +pub fn string_from_stdin() -> String { + let mut buffer = String::new(); + io::stdin().read_line(&mut buffer).unwrap(); + buffer.trim().to_string() +} + #[doc(hidden)] pub fn object_from_stdin() -> Result { let mut json = String::new(); @@ -66,6 +78,7 @@ extern "C" { fn host_unsubscribe(); fn host_set_selectable(selectable: i32); fn host_get_plugin_ids(); + fn host_get_zellij_version(); fn host_open_file(); fn host_switch_tab_to(tab_idx: u32); fn host_set_timeout(secs: f64); From 1b5de99d80080a10063eb76ffeb0a4b049323894 Mon Sep 17 00:00:00 2001 From: jaeheonji Date: Fri, 26 Nov 2021 18:11:46 +0900 Subject: [PATCH 3/3] feat(wasm): update feedback * delete unnecessary function --- zellij-tile/src/shim.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/zellij-tile/src/shim.rs b/zellij-tile/src/shim.rs index c0eef23b7a..e3537053ca 100644 --- a/zellij-tile/src/shim.rs +++ b/zellij-tile/src/shim.rs @@ -29,7 +29,7 @@ pub fn get_plugin_ids() -> PluginIds { pub fn get_zellij_version() -> String { unsafe { host_get_zellij_version() }; - string_from_stdin() + object_from_stdin().unwrap() } // Host Functions @@ -53,13 +53,6 @@ pub fn exec_cmd(cmd: &[&str]) { // Internal Functions -#[doc(hidden)] -pub fn string_from_stdin() -> String { - let mut buffer = String::new(); - io::stdin().read_line(&mut buffer).unwrap(); - buffer.trim().to_string() -} - #[doc(hidden)] pub fn object_from_stdin() -> Result { let mut json = String::new();