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/fullcolor/fullcolor.ha | 59 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 demo/fullcolor/fullcolor.ha (limited to 'demo/fullcolor') diff --git a/demo/fullcolor/fullcolor.ha b/demo/fullcolor/fullcolor.ha new file mode 100644 index 0000000..5d46c7c --- /dev/null +++ b/demo/fullcolor/fullcolor.ha @@ -0,0 +1,59 @@ +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(wmin: size, hmin: size, wmax: size, hmax: size) void = { + tb::set_output_mode(tb::OUTPUT.TRUECOLOR)!; + tb::print(wmin: int, hmin: int, tb::COLOR.DEFAULT, tb::COLOR.DEFAULT, + "Color palette sample:")!; + hmin = hmin + 1; + + let nsamples = (wmax - wmin +1) * (hmax - hmin + 1); + let step = 0xffffff / nsamples; + for (let y = hmin; y < hmax; y += 1) { + for (let x = wmin; x < wmax; x += 1) { + let c: tb::uattr = ((y - hmin) * wmax + (x - wmin)) * step; + paint_cell(x, y, c); + }; + }; +}; + +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")!; + + switch (tb::OPT_ATTR_W) { + case 64 => show_colors(0, 0, w, h-1); + case => tb::print(0, ((h+1)/2): int, tb::COLOR.DEFAULT, tb::COLOR.DEFAULT, + "This demo is only available with truecolor support, here " + "tb::OPT_ATTR_W is {}", tb::OPT_ATTR_W)!; + }; + + 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