34 lines
812 B
TypeScript
Executable file
34 lines
812 B
TypeScript
Executable file
#!./run
|
|
|
|
import { AnsiTerminalDisplay } from "./ansi.ts";
|
|
import { UIConfig } from "./config.ts";
|
|
import { TextUI } from "./ui.ts";
|
|
|
|
const display = new AnsiTerminalDisplay();
|
|
let x = 0;
|
|
const config: Partial<UIConfig> = {
|
|
palette: [
|
|
{ r: 0, g: 0, b: 0 },
|
|
{ r: 1, g: 1, b: 1 },
|
|
{ r: 0, g: 1, b: 1 },
|
|
],
|
|
onResize: draw,
|
|
onKeyStroke: (key) => {
|
|
ui.drawing.color(1, 0).text(key, { x, y: 7 });
|
|
x += key.length + 1;
|
|
},
|
|
onMouseClick: (loc) => {
|
|
const text = `${loc.x}:${loc.y}`;
|
|
ui.drawing.color(1, 0).text(text, { x, y: 7 });
|
|
x += text.length + 1;
|
|
},
|
|
};
|
|
const ui = new TextUI(display, config);
|
|
await ui.init();
|
|
draw();
|
|
await ui.loop();
|
|
|
|
function draw() {
|
|
ui.drawing.color(2, 0).text("hello", { x: 10, y: 3 });
|
|
ui.drawing.color(0, 1).text("world", { x: 10, y: 5 });
|
|
}
|