2021-02-28 11:01:35 +01:00
|
|
|
import Timeout = NodeJS.Timeout;
|
|
|
|
|
2021-01-20 23:22:18 +01:00
|
|
|
let intervalTime = 150;
|
|
|
|
|
|
|
|
let dataIndex = 0;
|
|
|
|
let stringPosition = 0;
|
2021-02-28 11:01:35 +01:00
|
|
|
let printTask: Timeout;
|
2021-01-20 23:22:18 +01:00
|
|
|
|
2021-02-28 14:09:57 +01:00
|
|
|
let terminal:HTMLElement;
|
|
|
|
let historyContainer:HTMLElement;
|
|
|
|
let promptContainer:HTMLElement;
|
|
|
|
|
2021-01-20 23:22:18 +01:00
|
|
|
function writeOut() {
|
2021-01-20 23:26:02 +01:00
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
let currentData: { [key: string]: string } = data[dataIndex];
|
2021-01-20 23:22:18 +01:00
|
|
|
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);
|
2021-01-20 23:26:02 +01:00
|
|
|
// @ts-ignore
|
2021-01-20 23:22:18 +01:00
|
|
|
if(dataIndex < data.length){
|
2021-01-20 23:26:02 +01:00
|
|
|
// @ts-ignore
|
2021-01-20 23:22:18 +01:00
|
|
|
setTimeout(startNewTask, data[dataIndex - 1].postDelay);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function startNewTask() {
|
|
|
|
|
2021-02-28 14:09:57 +01:00
|
|
|
terminal = <HTMLElement> document.getElementsByClassName("terminal")[0];
|
|
|
|
historyContainer = <HTMLElement> terminal.getElementsByClassName("history")[0];
|
|
|
|
promptContainer = <HTMLElement> terminal.getElementsByClassName("prompt")[0];
|
|
|
|
printTask = setInterval(writeOut, intervalTime);
|
|
|
|
}
|