mirror of
https://github.com/remko/waforth
synced 2025-01-29 08:34:33 +01:00
shell: Support passing program in query
This commit is contained in:
parent
46a82d83fd
commit
6b2db1edd4
1 changed files with 24 additions and 0 deletions
|
@ -47,6 +47,7 @@ function output(s, isInput, forceFlush = false) {
|
|||
flush();
|
||||
}
|
||||
}
|
||||
|
||||
function unoutput(isInput) {
|
||||
if (
|
||||
currentConsoleElIsInput !== isInput ||
|
||||
|
@ -57,6 +58,7 @@ function unoutput(isInput) {
|
|||
}
|
||||
currentConsoleEl.lastChild.remove();
|
||||
}
|
||||
|
||||
function startConsole() {
|
||||
let inputbuffer = [];
|
||||
document.addEventListener("keydown", (ev) => {
|
||||
|
@ -102,6 +104,7 @@ function startConsole() {
|
|||
inputbuffer = newInputBuffer;
|
||||
});
|
||||
}
|
||||
|
||||
function clearConsole() {
|
||||
consoleEl.innerHTML = `<span class='header'><a target='_blank' href='https://github.com/remko/waforth'>WAForth (${version})</a>\n</span><span class="cursor"> </span><input type="text">`;
|
||||
inputEl = document.querySelector("input");
|
||||
|
@ -119,6 +122,27 @@ forth.load().then(
|
|||
() => {
|
||||
clearConsole();
|
||||
startConsole();
|
||||
|
||||
// Parse query string
|
||||
const qs = {};
|
||||
for (const p of window.location.search
|
||||
.substring(window.location.search.indexOf("?") + 1)
|
||||
.replace(/\+/, " ")
|
||||
.split("&")) {
|
||||
const j = p.indexOf("=");
|
||||
if (j > 0) {
|
||||
qs[decodeURIComponent(p.substring(0, j))] = decodeURIComponent(
|
||||
p.substring(j + 1)
|
||||
);
|
||||
}
|
||||
}
|
||||
if (qs.p != null) {
|
||||
for (const command of qs.p.split("\n")) {
|
||||
output(command, true);
|
||||
output(" ", true);
|
||||
forth.interpret(command);
|
||||
}
|
||||
}
|
||||
},
|
||||
(e) => {
|
||||
console.error(e);
|
||||
|
|
Loading…
Add table
Reference in a new issue