feat: WASM web app (browser LesS/KEY) backed by the hel core
Run the real hel core in the browser via WebAssembly, replacing the plain-JS ooke.github.io/sk reimplementation so the web and the CLI share one generator. - hel core: new storage module (native fs / wasm localStorage) backs init/source/dump/correct; the pipe and pb branches are gated out of wasm; the wasm editor is completed (EditorRef) and its password prompt no longer blocks the single JS thread (synchronous hel_get_password instead of a thread::sleep poll). - helwasm: hel_load_script for bulk import, a panic hook in hel_init, dropped the ok_add / web-sys leftovers; build.sh runs wasm-bindgen into a committed pkg/ so GitHub Pages can serve the static dir with no CI. - UI: rewritten index.html + style.css in the kaizenkodo.org style — responsive, masked-but-copyable passwords with click-to-reveal, a quick-generate card plus a full command console, localStorage persistence, and paste import/export.
This commit is contained in:
@@ -1,22 +1,42 @@
|
||||
use hel::lk::{LK, LKRef};
|
||||
use hel::repl::LKRead;
|
||||
use hel::utils::editor::Editor;
|
||||
use std::sync::Arc;
|
||||
use hel::parser::command_parser;
|
||||
use hel::repl::{LKEval, LKRead};
|
||||
use hel::structs::LKOut;
|
||||
use hel::utils::editor::{password, Editor};
|
||||
use parking_lot::ReentrantMutex;
|
||||
use std::cell::RefCell;
|
||||
use std::sync::Arc;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
lazy_static! {
|
||||
static ref STATE: LKRef = Arc::new(ReentrantMutex::new(RefCell::new(LK::new())));
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
/// Run a single hel command line and return its combined output.
|
||||
#[wasm_bindgen]
|
||||
pub fn hel_command(cmd: String) -> String {
|
||||
let editor = Editor::new();
|
||||
let mut lkread = LKRead::new(editor, "> ".to_string(), STATE.clone());
|
||||
lkread.input = Some(cmd.to_string());
|
||||
lkread.input = Some(cmd);
|
||||
let lkeval = lkread.read();
|
||||
let lkprint = lkeval.eval();
|
||||
lkprint.out.output().join("\n")
|
||||
}
|
||||
|
||||
/// Run a whole multi-line script (every `add …` line, `set …`, etc.) against the
|
||||
/// shared state in one call. Used to bulk-import a pasted catalog (e.g. the text
|
||||
/// of the Notion page) and to load the persisted catalog from localStorage.
|
||||
#[wasm_bindgen]
|
||||
pub fn hel_load_script(script: String) -> String {
|
||||
let out = LKOut::new();
|
||||
match command_parser::script(&script) {
|
||||
Ok(cmds) => {
|
||||
for cmd in cmds {
|
||||
let print = LKEval::new(Editor::new(), cmd, STATE.clone(), password).eval();
|
||||
print.out.copy(&out);
|
||||
}
|
||||
}
|
||||
Err(e) => out.e(format!("error: {}", e)),
|
||||
}
|
||||
out.output().join("\n")
|
||||
}
|
||||
|
||||
+3
-5
@@ -4,13 +4,11 @@ extern crate hel;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn ok_add(a: i32, b: i32) -> i32 {
|
||||
a + b + 1
|
||||
}
|
||||
|
||||
mod hel_state;
|
||||
|
||||
/// Call once at page load: routes Rust panics to the browser console with a
|
||||
/// readable message + stack instead of an opaque "unreachable" trap.
|
||||
#[wasm_bindgen]
|
||||
pub fn hel_init() {
|
||||
console_error_panic_hook::set_once();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user