better formatting and history command

This commit is contained in:
Baipyrus 2023-01-13 13:05:59 +01:00
parent 841f0f60d2
commit 282d2556f2
3 changed files with 12 additions and 5 deletions

View File

@ -26,6 +26,7 @@ body {
#current {
color: lightgrey;
white-space: pre;
}
#asciiArt {

View File

@ -20,7 +20,15 @@ function cmd_clear() {
}
function cmd_history() {
return "";
let output = "";
const hl = history.list;
for (let i = 0; i < hl.length; i++) {
const lineBreak = (i !== hl.length - 1) ? "<br>" : "";
output += `${i+1} ${hl[i]}${lineBreak}`;
}
return output;
}
function cmd_exec(input) {

View File

@ -92,7 +92,6 @@ document.addEventListener("keydown", e => {
if (text !== "" || inputSet.has(" ") && inputSet.size === 1) {
history.list.push(text);
history.index = history.list.length;
console.log(history);
}
// Fix current input to page
@ -151,14 +150,13 @@ document.addEventListener("keydown", e => {
function createText(str, safe=true) {
const link = document.createElement("a");
link.style.color = "lightgrey";
link.style.whiteSpace = "pre";
// No "HTML injection"
if (safe)
link.textContent = str;
// "Anything goes" and keep formatting
else {
link.style.whiteSpace = "pre";
else
link.innerHTML = str;
}
return link;
}