import { BufferLocation, BufferSize, Char, Color } from "./base.ts"; import { Display } from "./display.ts"; /** * ANSI terminal display */ export class AnsiTerminalDisplay implements Display { constructor( private writer: Deno.Writer = Deno.stdout, private reader: Deno.Reader = Deno.stdin, ) { } async getSize(): Promise { const size = Deno.consoleSize(Deno.stdout.rid); return { w: size.columns, h: size.rows, }; } async setupPalette(colors: readonly Color[]): Promise { return colors; } async clear(): Promise { await this.writer.write(CLEAR); } async setChar(at: BufferLocation, char: Char): Promise { // TODO colors await this.writer.write(escape(`[${at.y};${at.x}H${char.ch}`)); } } function escape(sequence: string): Uint8Array { return new Uint8Array([0x1B, ...new TextEncoder().encode(sequence)]); } const CLEAR = escape("[2J");