playground improvements

This commit is contained in:
2024-11-06 20:51:57 -08:00
parent d82c224bc3
commit de5f9379d9
4 changed files with 24 additions and 11 deletions

4
playground/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
public
dist
.vite
node_modules

View File

@@ -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);
timeout = setTimeout(() => {
let value = editor.getValue()
run(value)
localStorage.code = value;
}, 1000);
});
run(initialValue);
}, []);

View File

@@ -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 = ''
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})
}

View File

@@ -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;