2021-01-20 23:22:18 +01:00
|
|
|
let intervalTime = 150;
|
|
|
|
|
|
|
|
let dataIndex = 0;
|
|
|
|
let stringPosition = 0;
|
2021-03-24 22:18:55 +01:00
|
|
|
let printTask;
|
2021-01-20 23:22:18 +01:00
|
|
|
|
2021-03-24 22:18:55 +01:00
|
|
|
let terminal;
|
|
|
|
let historyContainer;
|
|
|
|
let promptContainer;
|
2021-02-28 14:09:57 +01:00
|
|
|
|
2021-01-20 23:22:18 +01:00
|
|
|
function writeOut() {
|
2021-01-20 23:26:02 +01:00
|
|
|
|
2021-03-24 22:18:55 +01:00
|
|
|
let currentData = data[dataIndex];
|
|
|
|
let currentText = currentData["strings"];
|
2021-01-20 23:22:18 +01:00
|
|
|
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-03-24 22:18:55 +01:00
|
|
|
terminal = document.getElementsByClassName("terminal")[0];
|
|
|
|
historyContainer = terminal.getElementsByClassName("history")[0];
|
|
|
|
promptContainer = terminal.getElementsByClassName("prompt")[0];
|
2021-02-28 14:09:57 +01:00
|
|
|
printTask = setInterval(writeOut, intervalTime);
|
|
|
|
}
|