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 { #current {
color: lightgrey; color: lightgrey;
white-space: pre;
} }
#asciiArt { #asciiArt {

View File

@ -20,7 +20,15 @@ function cmd_clear() {
} }
function cmd_history() { 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) { function cmd_exec(input) {

View File

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