mirror of
https://github.com/remko/waforth
synced 2024-12-26 09:59:09 +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 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) {
|
||||
currentConsoleEl = document.createElement("span");
|
||||
currentConsoleEl.className = isInput ? "in" : "out";
|
||||
currentConsoleElIsInput = isInput;
|
||||
consoleEl.insertBefore(currentConsoleEl, cursorEl);
|
||||
}
|
||||
currentConsoleEl.appendChild(document.createTextNode(s));
|
||||
document.querySelector(".cursor").scrollIntoView(false);
|
||||
outputBuffer.push(s);
|
||||
if (forceFlush || isInput || s.endsWith("\n")) {
|
||||
flush();
|
||||
}
|
||||
}
|
||||
function unoutput(isInput) {
|
||||
if (
|
||||
|
@ -99,7 +113,7 @@ forth.onEmit = (c) => {
|
|||
|
||||
clearConsole();
|
||||
|
||||
output("Loading core ... ", false);
|
||||
output("Loading core ... ", false, true);
|
||||
forth.load().then(
|
||||
() => {
|
||||
clearConsole();
|
||||
|
|
Loading…
Reference in a new issue