From de5f9379d9df64720d74c1f797c0bf1ea48cf05c Mon Sep 17 00:00:00 2001 From: Steve Dunham Date: Wed, 6 Nov 2024 20:51:57 -0800 Subject: [PATCH] playground improvements --- playground/.gitignore | 4 ++++ playground/src/main.ts | 10 +++++----- playground/src/worker.ts | 12 +++++++++--- playground/style.css | 9 ++++++--- 4 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 playground/.gitignore diff --git a/playground/.gitignore b/playground/.gitignore new file mode 100644 index 0000000..54fe35d --- /dev/null +++ b/playground/.gitignore @@ -0,0 +1,4 @@ +public +dist +.vite +node_modules diff --git a/playground/src/main.ts b/playground/src/main.ts index 87d63a2..f0e3605 100644 --- a/playground/src/main.ts +++ b/playground/src/main.ts @@ -15,7 +15,6 @@ function run(src: string) { } newtWorker.onmessage = (ev) => { - console.log("worker sent", ev.data); state.output.value = ev.data.output; state.javascript.value = ev.data.javascript; }; @@ -67,11 +66,12 @@ function Editor({ initialValue }: EditorProps) { state.editor.value = editor; editor.onDidChangeModelContent((ev) => { - console.log("mc", ev); - let value = editor.getValue(); clearTimeout(timeout); - timeout = setTimeout(() => run(value), 1000); - localStorage.code = value; + timeout = setTimeout(() => { + let value = editor.getValue() + run(value) + localStorage.code = value; + }, 1000); }); run(initialValue); }, []); diff --git a/playground/src/worker.ts b/playground/src/worker.ts index ef00ce0..c21760b 100644 --- a/playground/src/worker.ts +++ b/playground/src/worker.ts @@ -120,15 +120,21 @@ process.stdout.write = (s) => { }; onmessage = function (e) { - console.log('worker got', e.data) let {src} = e.data process.argv = ["", "", "src/Main.newt", "-o", "out.js"]; console.log("args", process.argv); files["src/Main.newt"] = src; + files['out.js'] = 'No JS output'; stdout = '' - newtMain(); + try { + newtMain(); + } catch (e) { + // make it clickable + console.error(e) + // make it visable + stdout += '\n' + String(e) + } let javascript = files['out.js'] let output = stdout - console.log('WORKER POSTS', {javascript, output}) postMessage({javascript, output}) } diff --git a/playground/style.css b/playground/style.css index 9435ea9..2d0be29 100644 --- a/playground/style.css +++ b/playground/style.css @@ -12,6 +12,7 @@ } .wrapper > div { flex: 1 1; + /* allow smaller than natural */ width: 100px; } .tabPanel { @@ -22,7 +23,7 @@ display:flex; flex-direction: row; gap: 10px; - margin: 10px 0; + margin: 10px 0 0 0; border-bottom: solid 1px black; } .tab { @@ -33,9 +34,11 @@ border: solid 1px black; border-bottom: 0px } - -#result, #javascript { +.tabBody { overflow: auto; + flex: 1 1; +} +#result, #javascript { font-family: 'Comic Code', monospace; font-size: 12px; white-space: pre;