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
|
enum {
PAIR_NORMAL = 0,
};
char *g_line_buff;
void tui_line_buff_free(void) {
if (g_line_buff) {
free(g_line_buff);
}
g_line_buff = NULL;
}
void tui_line_buff_resize(void) {
tui_line_buff_free();
g_line_buff = calloc(COLS + 1, sizeof(char));
}
void tui_line(bool clear, int line, int color, int attr, const char *format, ...) {
assert(line >= 0);
assert(format);
if (line >= LINES) {
return;
}
if (clear) {
move(line, 0);
clrtoeol();
}
va_list args;
attron(COLOR_PAIR(color) | attr);
va_start(args, format);
vsnprintf(g_line_buff, COLS, format, args);
mvprintw(line, 1, "%s", g_line_buff);
va_end(args);
attroff(COLOR_PAIR(color) | attr);
}
void tui_clear_line(int l) {
tui_line(true, l, PAIR_NORMAL, A_NORMAL, "");
}
void tui_field(int line, int col, int color, int attr, const char *format, ...) {
assert(line >= 0);
assert(col >= 0);
assert(format);
if (line >= LINES || col >= COLS) {
return;
}
va_list args;
attron(COLOR_PAIR(color) | attr);
va_start(args, format);
vsnprintf(g_line_buff, COLS - col, format, args);
mvprintw(line, col, "%s", g_line_buff);
va_end(args);
attroff(COLOR_PAIR(color) | attr);
}
void tui_str_field(int l, const char *label, const char *value) {
assert(label);
assert(value);
tui_line(false, l, PAIR_NORMAL, A_NORMAL, "%s : %18s", label, value);
}
void tui_ulx_field(int l, const char *label, uint64_t value) {
assert(label);
tui_line(false, l, PAIR_NORMAL, A_NORMAL, "%-4s : %#18lx", label, value);
}
void tui_float_field(int l, const char *label, float value) {
assert(label);
tui_line(false, l, PAIR_NORMAL, A_NORMAL, "%-4s : %18.1f", label, value);
}
|