diff options
| author | Brooks J Rady <b.j.rady@gmail.com> | 2021-01-11 07:33:35 +0000 |
|---|---|---|
| committer | Brooks J Rady <b.j.rady@gmail.com> | 2021-01-11 07:33:35 +0000 |
| commit | efcd36a52c203b082e931ae06cecfb475e61547f (patch) | |
| tree | b0062a93edb85cb15346c126509693d9c104bdf9 /src/wasm_vm.rs | |
| parent | Add a plugin callback for global keypresses (diff) | |
| download | sl0ppij-efcd36a52c203b082e931ae06cecfb475e61547f.tar.gz sl0ppij-efcd36a52c203b082e931ae06cecfb475e61547f.tar.xz sl0ppij-efcd36a52c203b082e931ae06cecfb475e61547f.zip | |
Added the set_selectable plugin API function
Diffstat (limited to 'src/wasm_vm.rs')
| -rw-r--r-- | src/wasm_vm.rs | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/wasm_vm.rs b/src/wasm_vm.rs index 5324ee19..acb9e013 100644 --- a/src/wasm_vm.rs +++ b/src/wasm_vm.rs @@ -2,19 +2,22 @@ use std::{path::PathBuf, sync::mpsc::Sender}; use wasmer::{imports, Function, ImportObject, Store, WasmerEnv}; use wasmer_wasi::WasiEnv; -use crate::{panes::PaneId, pty_bus::PtyInstruction, SenderWithContext}; +use crate::{panes::PaneId, pty_bus::PtyInstruction, screen::ScreenInstruction, SenderWithContext}; #[derive(Clone, Debug)] pub enum PluginInstruction { Load(Sender<u32>, PathBuf), Draw(Sender<String>, u32, usize, usize), // String buffer, plugin id, rows, cols - Input(PaneId, Vec<u8>), // pane id, input bytes + Input(u32, Vec<u8>), // plugin id, input bytes + GlobalInput(Vec<u8>), // input bytes Unload(u32), Quit, } #[derive(WasmerEnv, Clone)] pub struct PluginEnv { + pub plugin_id: u32, + pub send_screen_instructions: SenderWithContext<ScreenInstruction>, pub send_pty_instructions: SenderWithContext<PtyInstruction>, // FIXME: This should be a big bundle of all of the channels pub wasi_env: WasiEnv, } @@ -24,7 +27,8 @@ pub struct PluginEnv { pub fn mosaic_imports(store: &Store, plugin_env: &PluginEnv) -> ImportObject { imports! { "mosaic" => { - "host_open_file" => Function::new_native_with_env(store, plugin_env.clone(), host_open_file) + "host_open_file" => Function::new_native_with_env(store, plugin_env.clone(), host_open_file), + "host_set_selectable" => Function::new_native_with_env(store, plugin_env.clone(), host_set_selectable), } } } @@ -38,6 +42,18 @@ fn host_open_file(plugin_env: &PluginEnv) { .unwrap(); } +// FIXME: Think about these naming conventions – should everything be prefixed by 'host'? +fn host_set_selectable(plugin_env: &PluginEnv, selectable: i32) { + let selectable = selectable != 0; + plugin_env + .send_screen_instructions + .send(ScreenInstruction::SetSelectable( + PaneId::Plugin(plugin_env.plugin_id), + selectable, + )) + .unwrap() +} + // Helper Functions --------------------------------------------------------------------------------------------------- // FIXME: Unwrap city |
