From 2e31cbeb70d93bb0f5512064f181990db189d1f6 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sun, 4 Oct 2026 20:02:15 +0200 Subject: Initial commit --- demo/colors16/color16.ha | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 demo/colors16/color16.ha (limited to 'demo/colors16') diff --git a/demo/colors16/color16.ha b/demo/colors16/color16.ha new file mode 100644 index 0000000..3121b93 --- /dev/null +++ b/demo/colors16/color16.ha @@ -0,0 +1,65 @@ +use fmt; +use tb = termbox2; + +fn paint_cell(x: size, y: size, c: tb::uattr) void = + tb::set_cell(x: int, y: int, ' ', tb::COLOR.DEFAULT, c)!; + +fn show_colors() size = { + let colors = [ + tb::COLOR.BLACK, + tb::COLOR.RED, + tb::COLOR.GREEN, + tb::COLOR.YELLOW, + tb::COLOR.BLUE, + tb::COLOR.MAGENTA, + tb::COLOR.CYAN, + tb::COLOR.WHITE, + ]; + + tb::print(0, 0, tb::COLOR.DEFAULT, tb::COLOR.DEFAULT, + "8 regular colors:")!; + tb::print(0, 2, tb::COLOR.DEFAULT, tb::COLOR.DEFAULT, + "8 bright colors:")!; + for (let i: size = 0; i < len(colors); i += 1) { + // 8 regular colors. + paint_cell(i, 1, colors[i]); + + // 8 bright colors. + paint_cell(i, 3, colors[i] | tb::ATTRIBUTE.BRIGHT); + }; + + return 4; +}; + +export fn main() int = { + let e = tb::init(); + if (e is tb::err) + fmt::fatalf(tb::strerror(e as tb::err)); + defer tb::shutdown()!; + + let w = tb::width()!; + let h = tb::height()!; + tb::print(0, (h - 1): int, tb::COLOR.DEFAULT, tb::COLOR.DEFAULT, + "Press any key to exit")!; + + show_colors(); + + for (true) { + let e = tb::present(); + if (e is tb::err) + fmt::fatalf(tb::strerror(e as tb::err)); + match (tb::poll_event()) { + case let e: tb::err => { + if (e == tb::ERR.NO_EVENT) + continue + else + tb::print(0, h:int -1, + tb::COLOR.DEFAULT, tb::COLOR.DEFAULT, + "Unexpected error {}!", tb::strerror(e))!; + }; + case tb::key_event => break; + case (tb::mouse_event | tb::resize_event) => continue; + }; + }; + return 0; +}; -- cgit v1.3