37 lines
No EOL
1.2 KiB
TypeScript
37 lines
No EOL
1.2 KiB
TypeScript
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: 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 + "<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(); |