aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorXe Iaso <me@christine.website>2022-12-09 10:44:28 -0500
committerXe Iaso <me@christine.website>2022-12-09 10:44:28 -0500
commitcf1f4577b5baf3936e26b67a35cdcba621757b58 (patch)
treeea7366a994154fea709fd245cf349c10b93853ea /src
parent2bedc77d8ea4b9f102e0105fe7d3d47f0d352a16 (diff)
downloadxesite-cf1f4577b5baf3936e26b67a35cdcba621757b58.tar.xz
xesite-cf1f4577b5baf3936e26b67a35cdcba621757b58.zip
src/frontend: start work on wasiterm
Signed-off-by: Xe Iaso <me@christine.website>
Diffstat (limited to 'src')
-rwxr-xr-xsrc/frontend/build.sh5
-rw-r--r--src/frontend/deno.lock (renamed from src/frontend/lock.json)0
-rw-r--r--src/frontend/deps.ts10
-rw-r--r--src/frontend/wasiterm.tsx50
4 files changed, 60 insertions, 5 deletions
diff --git a/src/frontend/build.sh b/src/frontend/build.sh
index 0f5859a..33577ae 100755
--- a/src/frontend/build.sh
+++ b/src/frontend/build.sh
@@ -1,11 +1,12 @@
#!/usr/bin/env bash
denobuild() {
- deno cache --import-map=./import_map.json --lock lock.json --lock-write *.tsx deps.ts
- deno bundle --import-map=./import_map.json --lock lock.json $1 $2
+ deno cache --import-map=./import_map.json --lock deno.lock --lock-write *.tsx deps.ts
+ deno bundle --import-map=./import_map.json --lock deno.lock $1 $2
}
set -e
export RUST_LOG=info
denobuild ./mastodon_share_button.tsx ../../static/js/mastodon_share_button.js
+denobuild ./wasiterm.tsx ../../static/js/wasiterm.js
diff --git a/src/frontend/lock.json b/src/frontend/deno.lock
index 01f35a5..01f35a5 100644
--- a/src/frontend/lock.json
+++ b/src/frontend/deno.lock
diff --git a/src/frontend/deps.ts b/src/frontend/deps.ts
index db03865..d885509 100644
--- a/src/frontend/deps.ts
+++ b/src/frontend/deps.ts
@@ -1,6 +1,10 @@
import * as wasi from "https://deno.land/x/wasm@v1.2.2/wasi.ts";
-import * as xeact from "xeact";
+//import * as xterm from "https://esm.sh/xterm@5.0.0";
-await wasi.init();
+import * as xeact from "xeact";
-export { wasi, xeact };
+export {
+ wasi,
+ xeact,
+ //xterm
+};
diff --git a/src/frontend/wasiterm.tsx b/src/frontend/wasiterm.tsx
new file mode 100644
index 0000000..352d03c
--- /dev/null
+++ b/src/frontend/wasiterm.tsx
@@ -0,0 +1,50 @@
+import { wasi as wasiMod, xeact } from "./deps.ts";
+
+const { x, t } = xeact;
+//const { Terminal } = xterm;
+const { WASI } = wasiMod;
+
+const init = async (rootElem: Element, wasmURL: string) => {
+ const termElem = <code></code>;
+
+ //const term = new Terminal();
+ //term.open(termElem);
+
+ const runProgram = async () => {
+ await wasiMod.init(new URL("https://cdn.xeiaso.net/file/christine-static/wasm/5410143de81b20061e9750d1cf80aceef56d2938ab949e30dd7b13fa699307ad.wasm"));
+
+ termElem.appendChild(t(`loading ${wasmURL}`));
+
+ const wasi = new WASI({
+ env: {
+ "HOSTNAME": "pyra",
+ },
+ })
+
+ const moduleBytes = fetch(wasmURL);
+ const module = await WebAssembly.compileStreaming(moduleBytes);
+ await wasi.instantiate(module, {});
+ //term.writeln("executing");
+ termElem.appendChild(t("executing"));
+ let exitCode = wasi.start();
+ let stdout = wasi.getStdoutString();
+ console.log(`${stdout}\n\n(exit code: ${exitCode})`);
+ termElem.appendChild(t(`${stdout}\n\n(exit code: ${exitCode})`));
+ };
+
+ const runButton = <button onclick={runProgram}>Run</button>;
+
+ const root = <div>
+ <link rel="stylesheet" href="https://cdn.xeiaso.net/file/christine-static/wasm/xterm/xterm-a36f07105014cc9220cae423d97c30d1a59fdb0230da8e53bb74bb0faade4310.css" type="text/css" />
+ {runButton}
+ <pre>{termElem}</pre>
+ </div>;
+
+ x(rootElem);
+ rootElem.appendChild(root);
+
+ //term.writeln(`loading ${wasmURL}`);
+ //term.writeln(`${stdout}\n\n(exit code: ${exitCode})`);
+}
+
+export { init };