samples: fix function that redirects stdout to DOM

Fix #920
This commit is contained in:
Alexey Andreev 2024-05-12 16:16:27 +02:00
parent 1b412073b9
commit 236700ea58

View File

@ -1,18 +1,20 @@
let $rt_stdoutBuffer = "";
function $rt_putStdoutCustom(str) {
function $rt_putStdoutCustom(msg) {
let index = 0;
while (true) {
let next = msg.indexOf('\n', index);
if (next < 0) {
break;
}
let line = buffer + msg.substring(index, next);
let line = $rt_stdoutBuffer + msg.substring(index, next);
let lineElem = document.createElement("div");
let stdoutElem = document.getElementById("stdout");
lineElem.appendChild(document.createTextNode(line));
stdoutElem.appendChild(lineElem);
buffer = "";
stdoutElem.scrollTop = stdoutElem.scrollHeight;
$rt_stdoutBuffer = "";
index = next + 1;
}
$rt_stdoutBuffer += msg.substring(index);
}
this.$rt_putStdoutCustom = $rt_putStdoutCustom;