aboutsummaryrefslogtreecommitdiff
path: root/docs/repl.js
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2020-08-21 19:49:07 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2020-08-21 21:39:30 -0400
commite1ccb8beb37a2134890e8a5c2a26a1439657bd02 (patch)
treeefff0068ca87287c1b60f72565df258596098770 /docs/repl.js
parent5ec6d2eaffc3664eff1311c463848b48f8ebfa60 (diff)
Make all REPL execution asynchronous and clear output while running
Diffstat (limited to 'docs/repl.js')
-rw-r--r--docs/repl.js23
1 files changed, 13 insertions, 10 deletions
diff --git a/docs/repl.js b/docs/repl.js
index d67bd47f..2de1b1fb 100644
--- a/docs/repl.js
+++ b/docs/repl.js
@@ -2,15 +2,18 @@ let body = document.body;
let doc={}; // html elements with a class
body.querySelectorAll('[class]').forEach(e=>doc[e.classList[0]]=e);
let repl = ()=>{
- try {
- let s=doc.code.value;
- doc.rslt.classList.remove('err');
- doc.rslt.textContent=fmt(bqn(s));
- } catch(e) {
- //if (console&&console.error) console.error(e.stack);
- doc.rslt.classList.add('err');
- doc.rslt.textContent=e;
- }
+ let s=doc.code.value;
+ doc.rslt.classList.remove('err');
+ doc.rslt.textContent=' ';
+ setTimeout(() => {
+ try {
+ doc.rslt.textContent=fmt(bqn(s));
+ } catch(e) {
+ //if (console&&console.error) console.error(e.stack);
+ doc.rslt.classList.add('err');
+ doc.rslt.textContent=e;
+ }
+ }, 0);
}
if (doc.run) doc.run.onclick = repl;
@@ -82,7 +85,7 @@ if (doc.demo) doc.demo.onclick = () => {
,'⌈˝ (≠ ↕ 0‿0⊸∾) 1‿2‿5‿4‿0‿2‿1'
];
++demo; if (demo===demos.length) demo=0;
- doc.code.value = demos[demo]; setTimeout(repl, 0);
+ doc.code.value = demos[demo]; repl();
}
if (location.hash) {