Skip to content

Commit a44c775

Browse files
Feat: Improve status on terminal for demo.
1 parent 8e6743c commit a44c775

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

demo/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ <h1 class="font-semibold">Edge Python Playground</h1>
6262
<header class="bg-[#1c1c1c] border-[#2d2d2d] flex justify-between items-center">
6363
<div class="text-[12px] tracking-tighter font-semibold text-zinc-500 flex items-center gap-1 w-full">
6464
<span class="px-3 py-2">
65-
<p aria-hidden="true">editor</p>
65+
<p aria-hidden="true">Editor</p>
6666
</span>
6767

6868
<span class="px-1.5 py-0.5 ml-auto">
@@ -94,8 +94,8 @@ <h1 class="font-semibold">Edge Python Playground</h1>
9494
<header class="bg-[#1c1c1c] border-b border-[#2d2d2d] px-3 py-2 flex justify-between items-center">
9595
<div class="text-[12px] tracking-tighter font-semibold text-zinc-500 flex items-center gap-1 w-full">
9696
<h2 class="sr-only">Terminal</h2>
97-
<p aria-hidden="true">terminal</p>
98-
<span id="status" role="status" class="ml-auto text-[#525252]">loading wasm…</span>
97+
<p aria-hidden="true">Terminal</p>
98+
<span id="status" role="status" class="ml-auto text-[#525252]">Loading WASM...</span>
9999
</div>
100100
</header>
101101

demo/main.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,37 @@ const instantiate = async (url) => {
2929
};
3030

3131
const loadWasm = async () => {
32-
setStatus('loading wasm…', CLS.ok);
32+
setStatus('Loading WASM...', CLS.ok);
3333
try {
3434
const [{ instance }, t] = await time(() => Promise.any(WASM_SOURCES.map(instantiate)));
3535
wasm = instance.exports;
3636
btn.disabled = false;
37-
setStatus(`ready (${t}${DEV ? ' · dev' : ''})`);
37+
setStatus(`Ready (${t}${DEV ? ' · Dev' : ''})`);
3838
} catch (err) {
39-
setStatus('load failed', CLS.err);
40-
term.textContent = `Could not load wasm.\n\n${err.errors.map(e => e.message).join(' | ')}`;
39+
setStatus('Load failed', CLS.err);
40+
term.textContent = `Could not load WASM.\n\n${err.errors.map(e => e.message).join(' | ')}`;
4141
}
4242
};
4343

4444
const runCode = async () => {
4545
if (!wasm) return;
4646
const srcBytes = new TextEncoder().encode(ed.value);
47-
if (srcBytes.length > SZ) return void (term.textContent = `error: source exceeds ${SZ} bytes`);
47+
if (srcBytes.length > SZ) return void (term.textContent = `Error: Source exceeds ${SZ} bytes`);
48+
49+
setStatus('Running...', CLS.ok);
50+
btn.disabled = true;
51+
52+
await new Promise(resolve => setTimeout(resolve, 10));
53+
4854
const [out, t] = await time(() => {
4955
new Uint8Array(wasm.memory.buffer).set(srcBytes, wasm.src_ptr());
5056
const len = wasm.run(srcBytes.length);
5157
return new TextDecoder().decode(new Uint8Array(wasm.memory.buffer, wasm.out_ptr(), len));
5258
});
59+
5360
term.textContent = out;
54-
setStatus(`ready (${t})`);
61+
setStatus(`Ready (${t})`);
62+
btn.disabled = false;
5563
};
5664

5765
const sync = () => {

0 commit comments

Comments
 (0)