let intervalTime = 150; let terminal:HTMLElement = document.getElementsByClassName("terminal")[0]; let historyContainer:HTMLElement = terminal.getElementsByClassName("history")[0]; let promptContainer:HTMLElement = terminal.getElementsByClassName("prompt")[0]; let dataIndex = 0; let stringPosition = 0; let printTask: number; 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 + "$ " + promptContainer.innerHTML + "
" + currentData["output"] + "

"; 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();