-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathitb_ui_testing.c
95 lines (80 loc) · 2.63 KB
/
itb_ui_testing.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <unistd.h>
#define ITB_UI_IMPLEMENTATION
//#define ITB_UI_UNICODE 0
#include "itb_ui.h"
int main(int argc, char **argv) {
(void)argv;
itb_ui_context ctx;
int ret;
if ((ret = itb_ui_start(&ctx))) {
perror("start");
printf("%d\n", ret);
return 1;
}
itb_ui_hide(&ctx);
if (argc == 1) {
itb_color_mode mode1, mode2;
itb_ui_stash sh[10];
for (int n = 0; n < 10; ++n) {
itb_ui_stash_init(&ctx, sh + n);
}
for (int n = 0; n < 10; ++n) {
for (int i = 0; i < 100000; ++i) {
mode1.set.fg = i % 6 + 1;
mode1.set.bg = (mode1.set.fg + 1 + n) % 7 + 1;
itb_ui_color(&ctx, &mode1);
itb_ui_strcpy(&ctx, i % ctx.rows + 1, i % ctx.cols + 1, ITB_T("$"), 1);
itb_ui_flip(&ctx);
}
itb_ui_stash_copy(&ctx, sh + n);
mode1.set.fg = ITB_WHITE;
mode1.set.bg = ITB_BLACK;
mode2.set.fg = ITB_WHITE;
mode2.set.bg = ITB_MAGENTA;
for (int i = n; i < 1000; i += 10) {
size_t r = (i % (ctx.rows - 11) + 1), c = (i % (ctx.cols - 11) + 1);
itb_ui_color(&ctx, &mode2);
itb_ui_box(&ctx, r, c, 11, 11);
itb_ui_color(&ctx, &mode1);
itb_ui_printf(&ctx, r + 5, c + 4, ITB_T("<%d>"), i);
itb_ui_flip(&ctx);
}
//itb_ui_clear(&ctx);
itb_ui_flip(&ctx);
mode1.set.fg = ITB_BLACK;
mode1.set.bg = ITB_RED;
itb_ui_color(&ctx, &mode1);
for (size_t r = 0; r < ctx.rows; r += 10) {
for (size_t c = 0; c < ctx.cols; c += 10) {
//itb_ui_box(&ctx, r + 1, c + 1, 9, 9);
itb_ui_printf(&ctx, r + 4, c + 3, ITB_T("r:%d"), r + 4);
itb_ui_printf(&ctx, r + 6, c + 3, ITB_T("c:%d"), c + 3);
}
}
itb_ui_flip(&ctx);
}
for (int n = 9; n >= 0; --n) {
itb_ui_stash_paste(&ctx, sh + n);
itb_ui_flip(&ctx);
}
for (int n = 0; n < 10; ++n) {
itb_ui_stash_close(sh + n);
}
} else {
int32_t c = '\0';
while (c != 'q') {
c = itb_ui_char();
if (c == '\0') {
continue;
}
if (c == ITB_K_CTRL('q')) {
break;
}
itb_ui_printf(&ctx, 1, 1, ITB_T("d:%d h:%x"), c, c);
itb_ui_flip(&ctx);
}
}
itb_ui_show(&ctx);
itb_ui_end(&ctx);
return 0;
}