Add current draft version

This commit is contained in:
Dei Layborer
2024-10-09 15:43:18 -04:00
committed by GitHub
parent 0c9ed6daf1
commit 532c3884fb
4 changed files with 251 additions and 0 deletions

57
term.js Normal file
View File

@@ -0,0 +1,57 @@
document.addEventListener('DOMContentLoaded', init);
let term;
let input;
const history = [];
function init() {
term = document.getElementById('terminal');
input = document.getElementById('user-input');
term.addEventListener('click', () => input.focus());
input.addEventListener('keyup', inputHandler);
input.value = '';
input.focus();
}
function inputHandler(e) {
switch (e.key) {
case 'Enter':
runCommand();
break;
default:
break;
}
}
function printLine(line, fmt = 'regular') {
if (line.length == 0) { return; }
if (typeof line == 'string') {
const newLine = document.createElement('div');
newLine.textContent = line;
term.appendChild(newLine);
if (fmt == 'h1') {
const len = lines.length;
const addlLine = document.createElement('div');
addlLine.textContent = '='.repeat(len);
addlLine.setAttribute('style', 'margin-bottom: 1em;');
term.appendChild(addlLine);
}
}
}
function printLines(lines, lineBetween = false) {
for (let line of lines) {
printLine(line);
if (lineBetween) { printLine(' '); }
}
}