import { BufferLocation, BufferSize, Char, Color } from "./base.ts"; import { Display } from "./display.ts"; /** * Base for all web-based terminal displays */ class WebDisplay implements Display { readonly document = (window as any).document; async getSize(): Promise { return { w: 40, h: 20 }; } async setupPalette(colors: readonly Color[]): Promise { return []; } async clear(): Promise { } async setCursorVisibility(visible: boolean): Promise { } async setChar(at: BufferLocation, char: Char): Promise { } async getKeyStrokes(): Promise { return []; } } /** * Basic terminal display using a single "pre" tag */ export class PreTerminalDisplay extends WebDisplay { element: any; async clear(): Promise { if (!this.element) { this.element = this.document.createElement("pre"); this.document.body.appendChild(this.element); } const { w, h } = await this.getSize(); const line = Array(w).fill(" ").join(""); this.element.textContent = Array(h).fill(line).join("\n"); } async setChar(at: BufferLocation, char: Char): Promise { const { w, h } = await this.getSize(); const offset = at.y * (w + 1) + at.x; const text = this.element.textContent; this.element.textContent = text.slice(0, offset) + char.ch + text.slice(offset + 1); } } /** * DOM terminal display, using one div per char */ export class DOMTerminalDisplay extends WebDisplay { }