textui/demo.ts

30 lines
664 B
TypeScript
Raw Normal View History

2021-06-24 22:41:34 +00:00
#!./run
2021-05-11 21:20:33 +00:00
import { AnsiTerminalDisplay } from "./ansi.ts";
2021-06-28 18:21:32 +00:00
import { UIConfig } from "./config.ts";
2021-05-13 22:04:47 +00:00
import { TextUI } from "./ui.ts";
2021-05-11 21:20:33 +00:00
const display = new AnsiTerminalDisplay();
2021-06-28 18:21:32 +00:00
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 },
],
2021-07-19 22:48:00 +00:00
onResize: draw,
2021-06-28 18:21:32 +00:00
onKeyStroke: (key) => {
ui.drawing.color(1, 0).text(key, { x, y: 7 });
x += key.length + 1;
},
};
const ui = new TextUI(display, config);
await ui.init();
2021-07-19 22:48:00 +00:00
draw();
2021-06-28 18:21:32 +00:00
await ui.loop();
2021-07-19 22:48:00 +00:00
function draw() {
ui.drawing.color(2, 0).text("hello", { x: 10, y: 3 });
ui.drawing.color(0, 1).text("world", { x: 10, y: 5 });
}