mirror of
https://github.com/remko/waforth
synced 2024-12-27 09:59:29 +01:00
shell: Buffer output
This commit is contained in:
parent
c79c2f647e
commit
48219d1dd0
1 changed files with 18 additions and 4 deletions
|
@ -23,15 +23,29 @@ consoleEl.addEventListener("click", () => {
|
||||||
|
|
||||||
let currentConsoleEl;
|
let currentConsoleEl;
|
||||||
let currentConsoleElIsInput = false;
|
let currentConsoleElIsInput = false;
|
||||||
function output(s, isInput) {
|
let outputBuffer = [];
|
||||||
|
function flush() {
|
||||||
|
if (outputBuffer.length == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
currentConsoleEl.appendChild(document.createTextNode(outputBuffer.join("")));
|
||||||
|
outputBuffer = [];
|
||||||
|
document.querySelector(".cursor").scrollIntoView(false);
|
||||||
|
}
|
||||||
|
function output(s, isInput, forceFlush = false) {
|
||||||
|
if (currentConsoleEl != null && currentConsoleElIsInput !== isInput) {
|
||||||
|
flush();
|
||||||
|
}
|
||||||
if (currentConsoleEl == null || currentConsoleElIsInput !== isInput) {
|
if (currentConsoleEl == null || currentConsoleElIsInput !== isInput) {
|
||||||
currentConsoleEl = document.createElement("span");
|
currentConsoleEl = document.createElement("span");
|
||||||
currentConsoleEl.className = isInput ? "in" : "out";
|
currentConsoleEl.className = isInput ? "in" : "out";
|
||||||
currentConsoleElIsInput = isInput;
|
currentConsoleElIsInput = isInput;
|
||||||
consoleEl.insertBefore(currentConsoleEl, cursorEl);
|
consoleEl.insertBefore(currentConsoleEl, cursorEl);
|
||||||
}
|
}
|
||||||
currentConsoleEl.appendChild(document.createTextNode(s));
|
outputBuffer.push(s);
|
||||||
document.querySelector(".cursor").scrollIntoView(false);
|
if (forceFlush || isInput || s.endsWith("\n")) {
|
||||||
|
flush();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
function unoutput(isInput) {
|
function unoutput(isInput) {
|
||||||
if (
|
if (
|
||||||
|
@ -99,7 +113,7 @@ forth.onEmit = (c) => {
|
||||||
|
|
||||||
clearConsole();
|
clearConsole();
|
||||||
|
|
||||||
output("Loading core ... ", false);
|
output("Loading core ... ", false, true);
|
||||||
forth.load().then(
|
forth.load().then(
|
||||||
() => {
|
() => {
|
||||||
clearConsole();
|
clearConsole();
|
||||||
|
|
Loading…
Reference in a new issue