diff options
| author | Brooks J Rady <b.j.rady@gmail.com> | 2021-01-07 09:39:16 +0000 |
|---|---|---|
| committer | Brooks J Rady <b.j.rady@gmail.com> | 2021-01-07 09:39:16 +0000 |
| commit | 01eaedcd3746e9de30fe867340667c65d8eb2733 (patch) | |
| tree | d4a2ce89265d1a38ac8a4041821058336d43d1a6 /src | |
| parent | Merge branch 'main' into wasm-launchable (diff) | |
| download | sl0ppij-01eaedcd3746e9de30fe867340667c65d8eb2733.tar.gz sl0ppij-01eaedcd3746e9de30fe867340667c65d8eb2733.tar.xz sl0ppij-01eaedcd3746e9de30fe867340667c65d8eb2733.zip | |
Parse bytes into keys with Termion
Diffstat (limited to 'src')
| -rw-r--r-- | src/errors.rs | 2 | ||||
| -rw-r--r-- | src/main.rs | 9 | ||||
| -rw-r--r-- | src/tab.rs | 26 | ||||
| -rw-r--r-- | src/tests/fixtures/layouts/panes-with-plugins.yaml | 2 | ||||
| -rw-r--r-- | src/wasm_vm.rs | 4 |
5 files changed, 31 insertions, 12 deletions
diff --git a/src/errors.rs b/src/errors.rs index 04c25ee0..e53bbc30 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -243,6 +243,7 @@ use crate::wasm_vm::PluginInstruction; pub enum PluginContext { Load, Draw, + Input, Unload, Quit, } @@ -252,6 +253,7 @@ impl From<&PluginInstruction> for PluginContext { match *plugin_instruction { PluginInstruction::Load(..) => PluginContext::Load, PluginInstruction::Draw(..) => PluginContext::Draw, + PluginInstruction::Input(..) => PluginContext::Input, PluginInstruction::Unload(_) => PluginContext::Unload, PluginInstruction::Quit => PluginContext::Quit, } diff --git a/src/main.rs b/src/main.rs index 01d0f232..1cbfac45 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,6 +15,7 @@ mod utils; mod wasm_vm; +use std::cell::RefCell; use std::io::Write; use std::os::unix::net::UnixStream; use std::path::PathBuf; @@ -24,6 +25,7 @@ use std::thread; use panes::PaneId; use serde::{Deserialize, Serialize}; use structopt::StructOpt; +use termion::input::TermRead; use wasm_vm::PluginInstruction; use crate::command_is_executing::CommandIsExecuting; @@ -37,7 +39,6 @@ use crate::utils::{ consts::{MOSAIC_IPC_PIPE, MOSAIC_TMP_DIR, MOSAIC_TMP_LOG_DIR}, logging::*, }; -use std::cell::RefCell; thread_local!(static OPENCALLS: RefCell<ErrorContext> = RefCell::default()); @@ -462,6 +463,12 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: Opt) { buf_tx.send(wasi_stdout(&wasi_env)).unwrap(); } + PluginInstruction::Input(pid, input_bytes) => { + let (instance, wasi_env) = plugin_map.get(&pid).unwrap(); + + let handle_key = instance.exports.get_function("handle_key").unwrap(); + dbg!(input_bytes.keys().collect::<Vec<_>>()); + } PluginInstruction::Quit => break, i => panic!("Yo, dawg, nice job calling the wasm thread!\n {:?} is defo not implemented yet...", i), } @@ -472,15 +472,23 @@ impl Tab { } } pub fn write_to_active_terminal(&mut self, input_bytes: Vec<u8>) { - if let Some(active_terminal_id) = &self.get_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"); + 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(); + } + _ => {} } } pub fn get_active_terminal_cursor_position(&self) -> Option<(usize, usize)> { diff --git a/src/tests/fixtures/layouts/panes-with-plugins.yaml b/src/tests/fixtures/layouts/panes-with-plugins.yaml index d64114b5..fe8e7ca4 100644 --- a/src/tests/fixtures/layouts/panes-with-plugins.yaml +++ b/src/tests/fixtures/layouts/panes-with-plugins.yaml @@ -15,4 +15,4 @@ parts: - direction: Vertical split_size: Percent: 20 - #plugin: strider.wasm + plugin: strider.wasm diff --git a/src/wasm_vm.rs b/src/wasm_vm.rs index a81c4fba..6d2d4a19 100644 --- a/src/wasm_vm.rs +++ b/src/wasm_vm.rs @@ -10,6 +10,7 @@ use wasmer_wasi::WasiEnv; 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 Unload(u32), Quit, } @@ -24,6 +25,7 @@ pub fn mosaic_imports(store: &Store, wasi_env: &WasiEnv) -> ImportObject { } } +// FIXME: Bundle up all of the channels! Pair that with WasiEnv? fn host_open_file(wasi_env: &WasiEnv) { Command::new("xdg-open") .arg(format!( @@ -46,7 +48,7 @@ pub fn wasi_stdout(wasi_env: &WasiEnv) -> String { buf } -pub fn _wasi_write_string(wasi_env: &WasiEnv, buf: &str) { +pub fn wasi_write_string(wasi_env: &WasiEnv, buf: &str) { let mut state = wasi_env.state(); let wasi_file = state.fs.stdin_mut().unwrap().as_mut().unwrap(); writeln!(wasi_file, "{}\r", buf).unwrap(); |
