diff options
| author | Brooks J Rady <b.j.rady@gmail.com> | 2021-03-23 19:52:59 +0000 |
|---|---|---|
| committer | Brooks J Rady <b.j.rady@gmail.com> | 2021-03-23 19:52:59 +0000 |
| commit | ac55e590475fb68f29071fc06ded8f6d6bf5db22 (patch) | |
| tree | 5cd73705a58232f10e9dd0943f2f503517356227 /src/common/mod.rs | |
| parent | Merge changes from main (diff) | |
| download | sl0ppij-ac55e590475fb68f29071fc06ded8f6d6bf5db22.tar.gz sl0ppij-ac55e590475fb68f29071fc06ded8f6d6bf5db22.tar.xz sl0ppij-ac55e590475fb68f29071fc06ded8f6d6bf5db22.zip | |
Initial implementation of the update callback + upstream termion
Diffstat (limited to 'src/common/mod.rs')
| -rw-r--r-- | src/common/mod.rs | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/src/common/mod.rs b/src/common/mod.rs index 675fe828..70edcea8 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -40,7 +40,7 @@ use wasm_vm::{ }; use wasmer::{ChainableNamedResolver, Instance, Module, Store, Value}; use wasmer_wasi::{Pipe, WasiState}; -use zellij_tile::data::InputMode; +use zellij_tile::data::{InputMode, Key}; #[derive(Serialize, Deserialize, Debug)] pub enum ApiCommand { @@ -456,6 +456,33 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) { .collect(); move || loop { + // FIXME: This 100% *must* be destroyed before this makes in into main!!!!!!!!!!! + fn cast_termion_key(event: termion::event::Key) -> Key { + match event { + termion::event::Key::Backspace => Key::Backspace, + termion::event::Key::Left => Key::Left, + termion::event::Key::Right => Key::Right, + termion::event::Key::Up => Key::Up, + termion::event::Key::Down => Key::Down, + termion::event::Key::Home => Key::Home, + termion::event::Key::End => Key::End, + termion::event::Key::PageUp => Key::PageUp, + termion::event::Key::PageDown => Key::PageDown, + termion::event::Key::BackTab => Key::BackTab, + termion::event::Key::Delete => Key::Delete, + termion::event::Key::Insert => Key::Insert, + termion::event::Key::F(n) => Key::F(n), + termion::event::Key::Char(c) => Key::Char(c), + termion::event::Key::Alt(c) => Key::Alt(c), + termion::event::Key::Ctrl(c) => Key::Ctrl(c), + termion::event::Key::Null => Key::Null, + termion::event::Key::Esc => Key::Esc, + _ => { + unimplemented!("Encountered an unknown key!") + } + } + } + let (event, mut err_ctx) = receive_plugin_instructions .recv() .expect("failed to receive event on channel"); @@ -522,6 +549,17 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) { pid_tx.send(plugin_id).unwrap(); plugin_id += 1; } + PluginInstruction::Update(event) => { + for (instance, plugin_env) in plugin_map.values() { + let update = instance.exports.get_function("update").unwrap(); + + wasi_write_string( + &plugin_env.wasi_env, + &serde_json::to_string(&event).unwrap(), + ); + update.call(&[]).unwrap(); + } + } PluginInstruction::Render(buf_tx, pid, rows, cols) => { let (instance, plugin_env) = plugin_map.get(&pid).unwrap(); @@ -555,6 +593,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) { let handle_key = instance.exports.get_function("handle_key").unwrap(); for key in input_bytes.keys().flatten() { + let key = cast_termion_key(key); wasi_write_string( &plugin_env.wasi_env, &serde_json::to_string(&key).unwrap(), @@ -572,6 +611,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) { .get_function(handler_map.get(&event).unwrap()) .unwrap(); for key in input_bytes.keys().flatten() { + let key = cast_termion_key(key); wasi_write_string( &plugin_env.wasi_env, &serde_json::to_string(&key).unwrap(), @@ -589,6 +629,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) { let handler = instance.exports.get_function("handle_global_key").unwrap(); for key in input_bytes.keys().flatten() { + let key = cast_termion_key(key); wasi_write_string( &plugin_env.wasi_env, &serde_json::to_string(&key).unwrap(), |
