import sqs from '../utils/sqs' export class Terminal { private terminal: HTMLElement private cellHeight = 16 private cellWidth = 8 constructor() { this.terminal = sqs('#terminal') this.ResetCellSize() this.NewPage() this.AppendLine('idk./home/idk -> ') } NewPage() { this.terminal.innerHTML = '' } AppendLine(line: string) { const paragraph = document.createElement('p') paragraph.style.height = `${this.cellHeight}px` paragraph.style.lineHeight = `${this.cellHeight}px` line.split('').forEach((char) => { const span = document.createElement('span') span.textContent = char.replace(' ', '\u00A0') span.style.width = `${this.cellWidth}px` span.style.height = `${this.cellHeight}px` span.style.lineHeight = `${this.cellHeight}px` paragraph.appendChild(span) }) this.terminal.appendChild(paragraph) } ResetCellSize() { // dynamically determine cell size using dom const cell = document.createElement('span') cell.textContent = '\\' this.terminal.appendChild(cell) this.cellWidth = cell.scrollWidth this.cellHeight = cell.scrollHeight } GetHeightCells(): number { return this.terminal.clientHeight / this.cellHeight } GetWidthCells(): number { return this.terminal.clientWidth / this.cellWidth } }