website/ts/error.ts
2021-02-28 11:58:50 +01:00

39 lines
No EOL
1.2 KiB
TypeScript

import Timeout = NodeJS.Timeout;
let intervalTime = 150;
let terminal:HTMLElement = <HTMLElement> document.getElementsByClassName("terminal")[0];
let historyContainer:HTMLElement = <HTMLElement> terminal.getElementsByClassName("history")[0];
let promptContainer:HTMLElement = <HTMLElement> terminal.getElementsByClassName("prompt")[0];
let dataIndex = 0;
let stringPosition = 0;
let printTask: Timeout;
function writeOut() {
// @ts-ignore
let currentData: { [key: string]: string } = data[dataIndex];
let currentText: string = currentData["strings"];
promptContainer.innerText = promptContainer.innerText + currentText.charAt(stringPosition);
stringPosition++;
if(stringPosition > currentText.length){
stringPosition = 0
dataIndex++;
historyContainer.innerHTML = historyContainer.innerHTML + "$&nbsp;" + promptContainer.innerHTML + "<br><span class=\"gray\">" + currentData["output"] + "</span><br><br>";
promptContainer.innerHTML = "";
clearInterval(printTask);
// @ts-ignore
if(dataIndex < data.length){
// @ts-ignore
setTimeout(startNewTask, data[dataIndex - 1].postDelay);
}
}
}
function startNewTask() {
printTask = setInterval(writeOut, intervalTime);
}
startNewTask();