better formatting and history command
This commit is contained in:
parent
841f0f60d2
commit
282d2556f2
@ -26,6 +26,7 @@ body {
|
||||
|
||||
#current {
|
||||
color: lightgrey;
|
||||
white-space: pre;
|
||||
}
|
||||
|
||||
#asciiArt {
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user