Working input response!
This commit is contained in:
parent
6e19401200
commit
54f6e09511
1 changed files with 72 additions and 65 deletions
25
src/main.rs
25
src/main.rs
|
|
@ -16,6 +16,7 @@ mod utils;
|
||||||
mod wasm_vm;
|
mod wasm_vm;
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::os::unix::net::UnixStream;
|
use std::os::unix::net::UnixStream;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
@ -26,10 +27,13 @@ use panes::PaneId;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
use termion::input::TermRead;
|
use termion::input::TermRead;
|
||||||
use wasm_vm::PluginInstruction;
|
use wasmer::{ChainableNamedResolver, Instance, Module, Store, Value};
|
||||||
|
use wasmer_wasi::{Pipe, WasiState};
|
||||||
|
|
||||||
use crate::command_is_executing::CommandIsExecuting;
|
use crate::command_is_executing::CommandIsExecuting;
|
||||||
use crate::errors::{AppContext, ContextType, ErrorContext, PtyContext, ScreenContext};
|
use crate::errors::{
|
||||||
|
AppContext, ContextType, ErrorContext, PluginContext, PtyContext, ScreenContext,
|
||||||
|
};
|
||||||
use crate::input::input_loop;
|
use crate::input::input_loop;
|
||||||
use crate::layout::Layout;
|
use crate::layout::Layout;
|
||||||
use crate::os_input_output::{get_os_input, OsApi};
|
use crate::os_input_output::{get_os_input, OsApi};
|
||||||
|
|
@ -39,6 +43,7 @@ use crate::utils::{
|
||||||
consts::{MOSAIC_IPC_PIPE, MOSAIC_TMP_DIR, MOSAIC_TMP_LOG_DIR},
|
consts::{MOSAIC_IPC_PIPE, MOSAIC_TMP_DIR, MOSAIC_TMP_LOG_DIR},
|
||||||
logging::*,
|
logging::*,
|
||||||
};
|
};
|
||||||
|
use crate::wasm_vm::{mosaic_imports, wasi_stdout, wasi_write_string, PluginInstruction};
|
||||||
|
|
||||||
thread_local!(static OPENCALLS: RefCell<ErrorContext> = RefCell::default());
|
thread_local!(static OPENCALLS: RefCell<ErrorContext> = RefCell::default());
|
||||||
|
|
||||||
|
|
@ -403,13 +408,10 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: Opt) {
|
||||||
active_threads.push(
|
active_threads.push(
|
||||||
thread::Builder::new()
|
thread::Builder::new()
|
||||||
.name("wasm".to_string())
|
.name("wasm".to_string())
|
||||||
.spawn(move || {
|
.spawn({
|
||||||
use crate::errors::PluginContext;
|
let mut send_screen_instructions = send_screen_instructions.clone();
|
||||||
use crate::wasm_vm::{mosaic_imports, wasi_stdout};
|
|
||||||
use std::collections::HashMap;
|
|
||||||
use wasmer::{ChainableNamedResolver, Instance, Module, Store, Value};
|
|
||||||
use wasmer_wasi::{Pipe, WasiState};
|
|
||||||
|
|
||||||
|
move || {
|
||||||
let store = Store::default();
|
let store = Store::default();
|
||||||
|
|
||||||
let mut plugin_id = 0;
|
let mut plugin_id = 0;
|
||||||
|
|
@ -420,6 +422,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: Opt) {
|
||||||
.recv()
|
.recv()
|
||||||
.expect("failed to receive event on channel");
|
.expect("failed to receive event on channel");
|
||||||
err_ctx.add_call(ContextType::Plugin(PluginContext::from(&event)));
|
err_ctx.add_call(ContextType::Plugin(PluginContext::from(&event)));
|
||||||
|
send_screen_instructions.update(err_ctx);
|
||||||
match event {
|
match event {
|
||||||
PluginInstruction::Load(pid_tx, path) => {
|
PluginInstruction::Load(pid_tx, path) => {
|
||||||
// FIXME: Cache this compiled module on disk. I could use `(de)serialize_to_file()` for that
|
// FIXME: Cache this compiled module on disk. I could use `(de)serialize_to_file()` for that
|
||||||
|
|
@ -469,15 +472,19 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: Opt) {
|
||||||
let handle_key = instance.exports.get_function("handle_key").unwrap();
|
let handle_key = instance.exports.get_function("handle_key").unwrap();
|
||||||
for key in input_bytes.keys() {
|
for key in input_bytes.keys() {
|
||||||
if let Ok(key) = key {
|
if let Ok(key) = key {
|
||||||
dbg!(serde_json::to_string(&key));
|
wasi_write_string(wasi_env, &serde_json::to_string(&key).unwrap());
|
||||||
|
handle_key.call(&[]).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
send_screen_instructions.send(ScreenInstruction::Render).unwrap();
|
||||||
}
|
}
|
||||||
PluginInstruction::Quit => break,
|
PluginInstruction::Quit => break,
|
||||||
i => panic!("Yo, dawg, nice job calling the wasm thread!\n {:?} is defo not implemented yet...", i),
|
i => panic!("Yo, dawg, nice job calling the wasm thread!\n {:?} is defo not implemented yet...", i),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
).unwrap(),
|
).unwrap(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue