diff options
| author | Brooks J Rady <b.j.rady@gmail.com> | 2021-01-10 23:02:41 +0000 |
|---|---|---|
| committer | Brooks J Rady <b.j.rady@gmail.com> | 2021-01-10 23:02:41 +0000 |
| commit | 7e308515e5af960857504fc583b5900b3dc4edd4 (patch) | |
| tree | 3c8728db22ca457fc430dd73ab05e387b1f378d5 | |
| parent | Add support for layouts with parts of a fixed or unspecified size (diff) | |
| download | sl0ppij-7e308515e5af960857504fc583b5900b3dc4edd4.tar.gz sl0ppij-7e308515e5af960857504fc583b5900b3dc4edd4.tar.xz sl0ppij-7e308515e5af960857504fc583b5900b3dc4edd4.zip | |
Add a plugin callback for global keypresses
| -rw-r--r-- | src/main.rs | 27 | ||||
| -rw-r--r-- | src/tab.rs | 34 | ||||
| -rw-r--r-- | src/wasm_vm.rs | 4 | ||||
| -rw-r--r-- | strider.wasm | bin | 529703 -> 530189 bytes |
4 files changed, 35 insertions, 30 deletions
diff --git a/src/main.rs b/src/main.rs index 84dfac62..6800691d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -458,17 +458,22 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) { buf_tx.send(wasi_stdout(&plugin_env.wasi_env)).unwrap(); } PluginInstruction::Input(pid, input_bytes) => { - let (instance, plugin_env) = plugin_map.get(&pid).unwrap(); - - let handle_key = - instance.exports.get_function("handle_key").unwrap(); - for key in input_bytes.keys() { - if let Ok(key) = key { - wasi_write_string( - &plugin_env.wasi_env, - &serde_json::to_string(&key).unwrap(), - ); - handle_key.call(&[]).unwrap(); + // FIXME: Set up an event subscription system, and timed callbacks + for (&id, (instance, plugin_env)) in &plugin_map { + let handler = if PaneId::Plugin(id) == pid { + "handle_key" + } else { + "handle_global_key" + }; + let handler = instance.exports.get_function(handler).unwrap(); + for key in input_bytes.keys() { + if let Ok(key) = key { + wasi_write_string( + &plugin_env.wasi_env, + &serde_json::to_string(&key).unwrap(), + ); + handler.call(&[]).unwrap(); + } } } @@ -473,23 +473,23 @@ impl Tab { } } pub fn write_to_active_terminal(&mut self, input_bytes: Vec<u8>) { - match self.get_active_pane_id() { - Some(PaneId::Terminal(active_terminal_id)) => { - let active_terminal = self.get_active_pane().unwrap(); - let mut adjusted_input = active_terminal.adjust_input_to_terminal(input_bytes); - self.os_api - .write_to_tty_stdin(active_terminal_id, &mut adjusted_input) - .expect("failed to write to terminal"); - self.os_api - .tcdrain(active_terminal_id) - .expect("failed to drain terminal"); - } - Some(PaneId::Plugin(pid)) => { - self.send_plugin_instructions - .send(PluginInstruction::Input(pid, input_bytes)) - .unwrap(); - } - _ => {} + let pid = self.get_active_pane_id(); + + if let Some(pid) = pid { + self.send_plugin_instructions + .send(PluginInstruction::Input(pid, input_bytes.clone())) + .unwrap(); + } + + if let Some(PaneId::Terminal(active_terminal_id)) = pid { + let active_terminal = self.get_active_pane().unwrap(); + let mut adjusted_input = active_terminal.adjust_input_to_terminal(input_bytes); + self.os_api + .write_to_tty_stdin(active_terminal_id, &mut adjusted_input) + .expect("failed to write to terminal"); + self.os_api + .tcdrain(active_terminal_id) + .expect("failed to drain terminal"); } } pub fn get_active_terminal_cursor_position(&self) -> Option<(usize, usize)> { diff --git a/src/wasm_vm.rs b/src/wasm_vm.rs index 51bd9375..5324ee19 100644 --- a/src/wasm_vm.rs +++ b/src/wasm_vm.rs @@ -2,13 +2,13 @@ use std::{path::PathBuf, sync::mpsc::Sender}; use wasmer::{imports, Function, ImportObject, Store, WasmerEnv}; use wasmer_wasi::WasiEnv; -use crate::{pty_bus::PtyInstruction, SenderWithContext}; +use crate::{panes::PaneId, pty_bus::PtyInstruction, SenderWithContext}; #[derive(Clone, Debug)] pub enum PluginInstruction { Load(Sender<u32>, PathBuf), Draw(Sender<String>, u32, usize, usize), // String buffer, plugin id, rows, cols - Input(u32, Vec<u8>), // plugin id, input bytes + Input(PaneId, Vec<u8>), // pane id, input bytes Unload(u32), Quit, } diff --git a/strider.wasm b/strider.wasm Binary files differindex e0062773..95156b66 100644 --- a/strider.wasm +++ b/strider.wasm |
