Skip to content

Commit

Permalink
deploy: b05a556
Browse files Browse the repository at this point in the history
  • Loading branch information
Nanguage committed Dec 29, 2023
1 parent 7025b1a commit 634a75f
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,20 @@
}
})

app.addMenuItem({
// restart
label: "🔄 Restart",
async callback() {
await restart();
},
})

return app;
}

async function restart() {
const body = $("body");
for (const el of body.children()) {
el.remove();
}
$(".terminal")[0].remove();
await initConsole(false);
}

Expand Down Expand Up @@ -271,15 +277,12 @@
}
}

async function runFile(url, showCode = true, showSplit = true) {
async function runFile(url, showCode = true) {
const term = window.term;
const response = await fetch(url);
let text = await response.text();
text = text.replaceAll("\r\n", "\n");
text = "\n" + text;
if (showSplit) {
term.echo(`--- Running ${url} ---`)
}
term.exec(text, !showCode);
}

Expand Down Expand Up @@ -590,22 +593,26 @@
term.exec("import micropip; await micropip.install('imjoy-rpc')", true)
const currentUrl = new URL(window.location.href);
const libUrl = currentUrl.origin + currentUrl.pathname + "/imjoy_encode.py";
await runFile(libUrl, false, false)
await runFile(libUrl, false)
pyodide.globals.set("api", new ImjoyApiWrapper(window.app.imjoy));
}
term.resume();

$.terminal.syntax('python')

const showCode = toBool(urlParams.get("show_code"), true);
const code = urlParams.get("code");
if (code) {
term.echo("--- Running code ---")
$.terminal.syntax('python')
term.exec(code, !showCode);
}
const flie = urlParams.get("file");
if (flie) {
await runFile(flie, showCode);
} else {
const file = urlParams.get("file");
if (file) {
term.echo(`--- Running ${file} ---`)
$.terminal.syntax('python')
await runFile(file, showCode);
} else {
$.terminal.syntax('python')
}
}

}
Expand Down

0 comments on commit 634a75f

Please sign in to comment.