aboutsummaryrefslogtreecommitdiff
path: root/demo/colors16
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2026-10-04 20:02:15 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2026-10-04 20:02:15 +0200
commit2e31cbeb70d93bb0f5512064f181990db189d1f6 (patch)
tree049f137715b692bcac0fd402fcbf04ef703523f0 /demo/colors16
downloadhare-termbox2-2e31cbeb70d93bb0f5512064f181990db189d1f6.tar.gz
hare-termbox2-2e31cbeb70d93bb0f5512064f181990db189d1f6.zip
Initial commit
Diffstat (limited to '')
-rw-r--r--demo/colors16/color16.ha65
1 files changed, 65 insertions, 0 deletions
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 @@
1use fmt;
2use tb = termbox2;
3
4fn paint_cell(x: size, y: size, c: tb::uattr) void =
5 tb::set_cell(x: int, y: int, ' ', tb::COLOR.DEFAULT, c)!;
6
7fn show_colors() size = {
8 let colors = [
9 tb::COLOR.BLACK,
10 tb::COLOR.RED,
11 tb::COLOR.GREEN,
12 tb::COLOR.YELLOW,
13 tb::COLOR.BLUE,
14 tb::COLOR.MAGENTA,
15 tb::COLOR.CYAN,
16 tb::COLOR.WHITE,
17 ];
18
19 tb::print(0, 0, tb::COLOR.DEFAULT, tb::COLOR.DEFAULT,
20 "8 regular colors:")!;
21 tb::print(0, 2, tb::COLOR.DEFAULT, tb::COLOR.DEFAULT,
22 "8 bright colors:")!;
23 for (let i: size = 0; i < len(colors); i += 1) {
24 // 8 regular colors.
25 paint_cell(i, 1, colors[i]);
26
27 // 8 bright colors.
28 paint_cell(i, 3, colors[i] | tb::ATTRIBUTE.BRIGHT);
29 };
30
31 return 4;
32};
33
34export fn main() int = {
35 let e = tb::init();
36 if (e is tb::err)
37 fmt::fatalf(tb::strerror(e as tb::err));
38 defer tb::shutdown()!;
39
40 let w = tb::width()!;
41 let h = tb::height()!;
42 tb::print(0, (h - 1): int, tb::COLOR.DEFAULT, tb::COLOR.DEFAULT,
43 "Press any key to exit")!;
44
45 show_colors();
46
47 for (true) {
48 let e = tb::present();
49 if (e is tb::err)
50 fmt::fatalf(tb::strerror(e as tb::err));
51 match (tb::poll_event()) {
52 case let e: tb::err => {
53 if (e == tb::ERR.NO_EVENT)
54 continue
55 else
56 tb::print(0, h:int -1,
57 tb::COLOR.DEFAULT, tb::COLOR.DEFAULT,
58 "Unexpected error {}!", tb::strerror(e))!;
59 };
60 case tb::key_event => break;
61 case (tb::mouse_event | tb::resize_event) => continue;
62 };
63 };
64 return 0;
65};

Generated with cgit - Back to sebastiano.tronto.net