mirror of
https://github.com/remko/waforth
synced 2025-02-06 20:46:25 +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();
|
flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function unoutput(isInput) {
|
function unoutput(isInput) {
|
||||||
if (
|
if (
|
||||||
currentConsoleElIsInput !== isInput ||
|
currentConsoleElIsInput !== isInput ||
|
||||||
|
@ -57,6 +58,7 @@ function unoutput(isInput) {
|
||||||
}
|
}
|
||||||
currentConsoleEl.lastChild.remove();
|
currentConsoleEl.lastChild.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
function startConsole() {
|
function startConsole() {
|
||||||
let inputbuffer = [];
|
let inputbuffer = [];
|
||||||
document.addEventListener("keydown", (ev) => {
|
document.addEventListener("keydown", (ev) => {
|
||||||
|
@ -102,6 +104,7 @@ function startConsole() {
|
||||||
inputbuffer = newInputBuffer;
|
inputbuffer = newInputBuffer;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearConsole() {
|
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">`;
|
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");
|
inputEl = document.querySelector("input");
|
||||||
|
@ -119,6 +122,27 @@ forth.load().then(
|
||||||
() => {
|
() => {
|
||||||
clearConsole();
|
clearConsole();
|
||||||
startConsole();
|
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) => {
|
(e) => {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
|
Loading…
Add table
Reference in a new issue