24 lines
527 B
TypeScript
24 lines
527 B
TypeScript
|
import { Color, Display } from "./display.ts";
|
||
|
|
||
|
/**
|
||
|
* ANSI terminal display
|
||
|
*/
|
||
|
export class AnsiTerminalDisplay implements Display {
|
||
|
constructor(private writer: Deno.Writer = Deno.stdout) {
|
||
|
}
|
||
|
|
||
|
async setupPalette(colors: readonly Color[]): Promise<readonly Color[]> {
|
||
|
return colors;
|
||
|
}
|
||
|
|
||
|
async clear(): Promise<void> {
|
||
|
await this.writer.write(CLEAR);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function escape(sequence: string): Uint8Array {
|
||
|
return new Uint8Array([0x1B, ...new TextEncoder().encode(sequence)]);
|
||
|
}
|
||
|
|
||
|
const CLEAR = escape("[2J");
|