Repository navigation
Expand file tree
/
Copy pathterm_table.c
More file actions
606 lines (564 loc) · 20.8 KB
/
Copy pathterm_table.c
File metadata and controls
606 lines (564 loc) · 20.8 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
/**
* @file term_table.c
* @brief 在终端输出表格的工具
* @author Ellu (ellu.grif@gmail.com)
* @version 1.0
* @date 2024-01-10
*
* THINK DIFFERENTLY
*/
#include "term_table.h"
#include <stdarg.h>
#include <string.h>
#include "uni_io.h"
#define _INTERNAL static inline
#define _EXTERNAL
#define tt_printf(...) printf(__VA_ARGS__)
#define tt_putchar(c) putchar(c)
#define tt_puts(s) puts(s)
#define tt_alloc(size) m_alloc(size)
#define tt_realloc(ptr, size) m_realloc(ptr, size)
#define tt_free(ptr) m_free(ptr)
static const char* line_break = "\033[K\r\n"; // 换行并清除本行剩余部分
static const int16_t WIDTH_UNKNOWN = -1; // 未知宽度
static const int16_t WIDTH_DISABLED = -2; // 禁用该宽度功能
static uint16_t lastFmt1 = TT_FMT1_NONE;
static uint16_t lastFmt2 = TT_FMT2_NONE;
_INTERNAL void tt_reset_fmt(void) {
lastFmt1 = TT_FMT1_NONE;
lastFmt2 = TT_FMT2_NONE;
tt_puts("\033[0m");
}
_INTERNAL void tt_check_fmt(TT_FMT1 fmt1, TT_FMT2 fmt2) {
if (fmt1 == TT_FMT1_KEEP)
fmt1 = lastFmt1;
if (fmt2 == TT_FMT2_KEEP)
fmt2 = lastFmt2;
if (fmt1 == lastFmt1 && fmt2 == lastFmt2)
return;
if (fmt2 != TT_FMT2_NONE) {
tt_printf("\033[0;%d;%dm", fmt1, fmt2);
} else {
tt_printf("\033[0;%dm", fmt1);
}
lastFmt1 = fmt1;
lastFmt2 = fmt2;
}
_INTERNAL void tt_print_str_sep(TT_STR str, int16_t minWidth, char sep) {
tt_check_fmt(str->fmt1, str->fmt2);
int16_t width = str->width;
if (width < minWidth) {
switch (str->align) {
case TT_ALIGN_LEFT:
break;
case TT_ALIGN_CENTER:
for (int16_t i = 0; i < (minWidth - width) / 2; i++)
tt_putchar(sep);
break;
case TT_ALIGN_RIGHT:
for (int16_t i = 0; i < minWidth - width; i++)
tt_putchar(sep);
break;
}
}
tt_puts(str->str);
if (width < minWidth) {
switch (str->align) {
case TT_ALIGN_LEFT:
for (int16_t i = 0; i < minWidth - width; i++)
tt_putchar(sep);
break;
case TT_ALIGN_CENTER:
for (int16_t i = 0; i < (minWidth - width + 1) / 2; i++)
tt_putchar(sep);
break;
case TT_ALIGN_RIGHT:
break;
}
}
}
_INTERNAL void tt_print_str(TT_STR str, int16_t minWidth) {
tt_print_str_sep(str, minWidth, ' ');
}
_EXTERNAL TT_STR TT_Str(TT_ALIGN align, TT_FMT1 fmt1, TT_FMT2 fmt2,
const char* str) {
TT_STR ret = (TT_STR)tt_alloc(sizeof(term_table_str_t));
ret->str = (char*)str;
ret->allocated = false;
ret->width = strlen(str);
ret->align = align;
ret->fmt1 = fmt1;
ret->fmt2 = fmt2;
return ret;
}
_EXTERNAL TT_STR TT_FmtStr(TT_ALIGN align, TT_FMT1 fmt1, TT_FMT2 fmt2,
const char* fmt, ...) {
TT_STR ret = (TT_STR)tt_alloc(sizeof(term_table_str_t));
va_list args;
va_start(args, fmt);
int16_t len = vsnprintf(NULL, 0, fmt, args) + 1;
va_end(args);
ret->str = (char*)tt_alloc(len);
ret->allocated = true;
va_start(args, fmt);
len = vsnprintf((char*)ret->str, len, fmt, args);
va_end(args);
ret->width = len;
ret->align = align;
ret->fmt1 = fmt1;
ret->fmt2 = fmt2;
return ret;
}
_EXTERNAL void TT_FmtStr_Update(TT_STR str, const char* fmt, ...) {
va_list args;
va_start(args, fmt);
int16_t len = vsnprintf(NULL, 0, fmt, args) + 1;
va_end(args);
if (str->allocated) {
str->str = (char*)tt_realloc(str->str, len);
} else {
str->str = (char*)tt_alloc(len);
str->allocated = true;
}
va_start(args, fmt);
len = vsnprintf((char*)str->str, len, fmt, args);
va_end(args);
str->width = len;
}
_INTERNAL void tt_free_str(TT_STR str) {
if (str->allocated)
tt_free(str->str);
str->allocated = false;
tt_free(str);
}
_EXTERNAL TT TT_NewTable(int16_t tableMinWidth) {
TT ret = (TT)tt_alloc(sizeof(term_table_t));
ret->items = ulist_new(sizeof(term_table_item_t), 0, NULL, NULL);
ret->tableMinWidth = tableMinWidth > 0 ? tableMinWidth : WIDTH_DISABLED;
ret->tablePrintedHeight = 0;
ret->tablePrintedWidth = 0;
return ret;
}
_EXTERNAL void TT_FreeTable(TT tt) {
// 需要遍历删除所有的子项
ulist_foreach(tt->items, term_table_item_t, item) {
switch (item->type) {
case TT_ITEM_TYPE_TITLE:
tt_free_str(((TT_ITEM_TITLE)item->content)->str);
break;
case TT_ITEM_TYPE_STRING:
tt_free_str(((TT_ITEM_STRING)item->content)->str);
break;
case TT_ITEM_TYPE_KVPAIR:
ulist_foreach(((TT_ITEM_KVPAIR)item->content)->items,
term_table_item_kvpair_item_t, kvpair_item) {
tt_free_str(kvpair_item->key);
tt_free_str(kvpair_item->value);
tt_free_str(kvpair_item->separator);
}
ulist_free(((TT_ITEM_KVPAIR)item->content)->items);
break;
case TT_ITEM_TYPE_GRID:
ulist_foreach(((TT_ITEM_GRID)item->content)->lines,
term_table_item_grid_line_t, grid_line) {
ulist_foreach(grid_line->items, term_table_item_grid_item_t,
grid_item) {
tt_free_str(grid_item->str);
}
ulist_free(grid_line->items);
tt_free_str(grid_line->separator);
}
ulist_free(((TT_ITEM_GRID)item->content)->lines);
ulist_free(((TT_ITEM_GRID)item->content)->widths);
break;
case TT_ITEM_TYPE_PROGRESS:
if (((TT_ITEM_PROGRESS)item->content)->_percentStr) {
tt_free_str(((TT_ITEM_PROGRESS)item->content)->_percentStr);
}
break;
case TT_ITEM_TYPE_SEPARATOR:
case TT_ITEM_TYPE_LINEBREAK:
break;
}
tt_free(item->content);
}
ulist_free(tt->items);
tt_free(tt);
}
_INTERNAL TT_ITEM tt_new_item(TT tt, TT_ITEM_TYPE type) {
TT_ITEM ret = (TT_ITEM)ulist_append(tt->items);
ret->type = type;
switch (type) {
case TT_ITEM_TYPE_TITLE:
ret->content = tt_alloc(sizeof(term_table_item_title_t));
break;
case TT_ITEM_TYPE_STRING:
ret->content = tt_alloc(sizeof(term_table_item_string_t));
break;
case TT_ITEM_TYPE_KVPAIR:
ret->content = tt_alloc(sizeof(term_table_item_kvpair_t));
break;
case TT_ITEM_TYPE_GRID:
ret->content = tt_alloc(sizeof(term_table_item_grid_t));
break;
case TT_ITEM_TYPE_SEPARATOR:
ret->content = tt_alloc(sizeof(term_table_item_separator_t));
break;
case TT_ITEM_TYPE_LINEBREAK:
ret->content = tt_alloc(sizeof(term_table_item_linebreak_t));
break;
case TT_ITEM_TYPE_PROGRESS:
ret->content = tt_alloc(sizeof(term_table_item_progress_t));
break;
}
return ret;
}
_EXTERNAL TT_ITEM_TITLE TT_AddTitle(TT tt, TT_STR str, char separator) {
TT_ITEM item = tt_new_item(tt, TT_ITEM_TYPE_TITLE);
TT_ITEM_TITLE content = (TT_ITEM_TITLE)item->content;
content->str = str;
content->separator = separator;
return content;
}
_EXTERNAL TT_ITEM_STRING TT_AddString(TT tt, TT_STR str, int16_t width) {
TT_ITEM item = tt_new_item(tt, TT_ITEM_TYPE_STRING);
TT_ITEM_STRING content = (TT_ITEM_STRING)item->content;
content->str = str;
content->width = width >= 0 ? width : WIDTH_DISABLED;
return content;
}
_EXTERNAL TT_ITEM_KVPAIR TT_AddKVPair(TT tt, int16_t keyMinWidth) {
TT_ITEM item = tt_new_item(tt, TT_ITEM_TYPE_KVPAIR);
TT_ITEM_KVPAIR content = (TT_ITEM_KVPAIR)item->content;
content->items =
ulist_new(sizeof(term_table_item_kvpair_item_t), 0, NULL, NULL);
content->keyMinWidth = keyMinWidth > 0 ? keyMinWidth : WIDTH_DISABLED;
content->keyWidth = WIDTH_UNKNOWN;
content->valueWidth = WIDTH_UNKNOWN;
content->separatorWidth = WIDTH_UNKNOWN;
return content;
}
_EXTERNAL TT_ITEM_KVPAIR_ITEM TT_KVPair_AddItem(TT_ITEM_KVPAIR kvpair,
int16_t intent, TT_STR key,
TT_STR value,
TT_STR separator) {
TT_ITEM_KVPAIR_ITEM item = (TT_ITEM_KVPAIR_ITEM)ulist_append(kvpair->items);
item->key = key;
item->value = value;
item->separator = separator;
item->intent = intent >= 0 ? intent : 0;
return item;
}
_EXTERNAL TT_ITEM_GRID TT_AddGrid(TT tt, int16_t margin) {
TT_ITEM item = tt_new_item(tt, TT_ITEM_TYPE_GRID);
TT_ITEM_GRID content = (TT_ITEM_GRID)item->content;
content->lines =
ulist_new(sizeof(term_table_item_grid_line_t), 0, NULL, NULL);
content->widths = ulist_new(sizeof(int16_t), 0, NULL, NULL);
content->margin = margin >= 0 ? margin : 0;
content->separatorWidth = WIDTH_UNKNOWN;
return content;
}
_EXTERNAL TT_ITEM_GRID_LINE TT_Grid_AddLine(TT_ITEM_GRID grid,
TT_STR separator) {
TT_ITEM_GRID_LINE line = (TT_ITEM_GRID_LINE)ulist_append(grid->lines);
line->items = ulist_new(sizeof(term_table_item_grid_item_t), 0, NULL, NULL);
line->separator = separator;
return line;
}
_EXTERNAL TT_ITEM_GRID_LINE_ITEM TT_GridLine_AddItem(TT_ITEM_GRID_LINE line,
TT_STR str) {
TT_ITEM_GRID_LINE_ITEM item =
(TT_ITEM_GRID_LINE_ITEM)ulist_append(line->items);
item->str = str;
return item;
}
_EXTERNAL TT_ITEM_SEPARATOR TT_AddSeparator(TT tt, TT_FMT1 fmt1, TT_FMT2 fmt2,
char separator) {
TT_ITEM item = tt_new_item(tt, TT_ITEM_TYPE_SEPARATOR);
TT_ITEM_SEPARATOR content = (TT_ITEM_SEPARATOR)item->content;
content->separator = separator;
content->fmt1 = fmt1;
content->fmt2 = fmt2;
return content;
}
_EXTERNAL TT_ITEM_LINEBREAK TT_AddLineBreak(TT tt, uint16_t lineCount) {
TT_ITEM item = tt_new_item(tt, TT_ITEM_TYPE_LINEBREAK);
TT_ITEM_LINEBREAK content = (TT_ITEM_LINEBREAK)item->content;
content->lineCount = lineCount;
return content;
}
_EXTERNAL TT_ITEM_PROGRESS TT_AddProgress(TT tt, int16_t intent, TT_FMT1 fmt1,
TT_FMT2 fmt2, float percent,
bool showPercent) {
TT_ITEM item = tt_new_item(tt, TT_ITEM_TYPE_PROGRESS);
TT_ITEM_PROGRESS content = (TT_ITEM_PROGRESS)item->content;
content->percent = percent;
content->showPercent = showPercent;
content->intent = intent >= 0 ? intent : 0;
content->fmt1 = fmt1;
content->fmt2 = fmt2;
content->_percentStr = NULL;
return content;
}
_INTERNAL int16_t tt_calc_title_width(TT_ITEM_TITLE title) {
return title->str->width;
}
_INTERNAL int16_t tt_calc_string_width(TT_ITEM_STRING string) {
return string->width == 0 ? string->str->width : string->width;
}
_INTERNAL int16_t tt_calc_kvpair_width(TT_ITEM_KVPAIR kvpair) {
int16_t maxIntent = 0;
ulist_foreach(kvpair->items, term_table_item_kvpair_item_t, kvpair_item) {
if (kvpair_item->key->width > kvpair->keyWidth)
kvpair->keyWidth = kvpair_item->key->width;
if (kvpair_item->value->width > kvpair->valueWidth)
kvpair->valueWidth = kvpair_item->value->width;
if (kvpair_item->separator->width > kvpair->separatorWidth)
kvpair->separatorWidth = kvpair_item->separator->width;
if (kvpair_item->intent > maxIntent)
maxIntent = kvpair_item->intent;
}
if (kvpair->keyMinWidth != WIDTH_DISABLED &&
kvpair->keyWidth < kvpair->keyMinWidth)
kvpair->keyWidth = kvpair->keyMinWidth;
return kvpair->keyWidth + kvpair->valueWidth + kvpair->separatorWidth +
maxIntent;
}
_INTERNAL int16_t tt_calc_grid_width(TT_ITEM_GRID grid, int16_t minWidth) {
int16_t max_line_item = 0;
ulist_foreach(grid->lines, term_table_item_grid_line_t, grid_line) {
if (ulist_len(grid_line->items) > max_line_item)
max_line_item = ulist_len(grid_line->items);
if (grid_line->separator->width > grid->separatorWidth)
grid->separatorWidth = grid_line->separator->width;
}
ulist_append_multi(grid->widths, max_line_item);
ulist_foreach(grid->widths, int16_t, width) {
*width = WIDTH_UNKNOWN;
}
ulist_foreach(grid->lines, term_table_item_grid_line_t, grid_line) {
int16_t* width = (int16_t*)ulist_get(grid->widths, 0);
ulist_foreach(grid_line->items, term_table_item_grid_item_t,
grid_item) {
if (grid_item->str->width > *width)
*width = grid_item->str->width;
width++;
}
}
int16_t sum = 0;
ulist_foreach(grid->widths, int16_t, width) {
sum += *width;
sum += grid->separatorWidth;
}
sum -= grid->separatorWidth;
sum += 2 * grid->margin;
return sum;
}
_INTERNAL int16_t tt_calc_max_width(TT tt) {
int16_t maxWidth = 0;
ulist_foreach(tt->items, term_table_item_t, item) {
int16_t itemWidth = WIDTH_UNKNOWN;
switch (item->type) {
case TT_ITEM_TYPE_TITLE:
itemWidth = tt_calc_title_width((TT_ITEM_TITLE)item->content);
break;
case TT_ITEM_TYPE_STRING:
itemWidth = tt_calc_string_width((TT_ITEM_STRING)item->content);
break;
case TT_ITEM_TYPE_KVPAIR:
itemWidth = tt_calc_kvpair_width((TT_ITEM_KVPAIR)item->content);
break;
case TT_ITEM_TYPE_GRID:
itemWidth = tt_calc_grid_width((TT_ITEM_GRID)item->content,
tt->tableMinWidth);
break;
case TT_ITEM_TYPE_PROGRESS:
if (((TT_ITEM_PROGRESS)item->content)->showPercent) {
itemWidth = 7;
}
itemWidth += ((TT_ITEM_PROGRESS)item->content)->intent * 2;
case TT_ITEM_TYPE_SEPARATOR:
case TT_ITEM_TYPE_LINEBREAK:
break;
}
if (itemWidth > maxWidth)
maxWidth = itemWidth;
}
return maxWidth;
}
_INTERNAL void tt_print_separator(TT tt, TT_ITEM_SEPARATOR separator,
int16_t width) {
tt_check_fmt(separator->fmt1, separator->fmt2);
for (int16_t i = 0; i < width; i++)
tt_putchar(separator->separator);
tt_puts(line_break);
tt->tablePrintedHeight++;
}
_INTERNAL void tt_print_string(TT tt, TT_ITEM_STRING string, int16_t minWidth) {
// 遍历字符串,如果遇到换行符(\n)则换行,如果width不为WIDTH_DISABLED且当前行宽度超过width则前向查找空格,在空格处换行,并为每一行计算对齐
if (string->width < 0)
minWidth += string->width;
char* str_copy = tt_alloc(string->str->width + 1);
memcpy(str_copy, string->str->str, string->str->width + 1);
str_copy[string->str->width] = '\0';
term_table_str_t temp = {
.align = string->str->align,
.fmt1 = string->str->fmt1,
.fmt2 = string->str->fmt2,
};
char* p = str_copy;
char* last_p = str_copy;
char* last_space = NULL;
while (*p != '\0') {
if (*p == '\n') {
*p = '\0';
temp.str = last_p;
temp.width = p - last_p;
tt_print_str(&temp, minWidth);
tt_puts(line_break);
tt->tablePrintedHeight++;
last_p = p + 1;
last_space = NULL;
p++;
}
if (p - last_p >= minWidth) {
if (last_space == NULL) {
last_space = p;
}
*last_space = '\0';
temp.str = last_p;
temp.width = last_space - last_p;
tt_print_str(&temp, minWidth);
tt_puts(line_break);
tt->tablePrintedHeight++;
last_p = last_space + 1;
p = last_p;
last_space = NULL;
} else if (*p == ' ') {
last_space = p;
}
p++;
}
if (p != last_p) {
temp.str = last_p;
temp.width = p - last_p;
tt_print_str(&temp, minWidth);
tt_puts(line_break);
tt->tablePrintedHeight++;
}
tt_free(str_copy);
}
_INTERNAL void tt_print_kvpair(TT tt, TT_ITEM_KVPAIR kvpair, int16_t minWidth) {
ulist_foreach(kvpair->items, term_table_item_kvpair_item_t, kvpair_item) {
if (kvpair_item->intent) {
for (int16_t i = 0; i < kvpair_item->intent; i++)
tt_putchar(' ');
}
tt_print_str(kvpair_item->key, kvpair->keyWidth);
tt_print_str(kvpair_item->separator, kvpair->separatorWidth);
tt_print_str(kvpair_item->value, kvpair->valueWidth);
tt_puts(line_break);
tt->tablePrintedHeight++;
}
}
_INTERNAL void tt_print_grid(TT tt, TT_ITEM_GRID grid, int16_t minWidth) {
ulist_foreach(grid->lines, term_table_item_grid_line_t, grid_line) {
if (grid->margin) {
for (int16_t i = 0; i < grid->margin; i++)
tt_putchar(' ');
}
int16_t* width = (int16_t*)ulist_get(grid->widths, 0);
ulist_foreach(grid_line->items, term_table_item_grid_item_t,
grid_item) {
tt_print_str(grid_item->str, *width++);
if (grid_item + 1 != grid_item_end) {
tt_print_str(grid_line->separator, grid->separatorWidth);
}
}
tt_puts(line_break);
tt->tablePrintedHeight++;
}
}
_INTERNAL void tt_print_progress(TT tt, TT_ITEM_PROGRESS progress,
int16_t minWidth) {
int16_t width = minWidth - 2 - 2 * progress->intent; // [ ]
if (progress->percent > 1.0f)
progress->percent = 1.0f;
if (progress->percent < 0.0f)
progress->percent = 0.0f;
if (progress->showPercent) {
if (progress->_percentStr) {
tt_free_str(progress->_percentStr);
}
progress->_percentStr =
TT_FmtStr(TT_ALIGN_LEFT, TT_FMT1_KEEP, TT_FMT2_KEEP, "%.1f%%",
progress->percent * 100.0f);
width -= progress->_percentStr->width; // [ ...100.0% ...]
}
for (int16_t i = 0; i < progress->intent; i++)
tt_putchar(' ');
tt_puts("[");
int16_t filled = progress->percent * width;
int16_t empty = width - filled;
for (int16_t i = 0; i < filled; i++)
tt_putchar('#');
for (int16_t i = 0; i < empty; i++)
tt_putchar(' ');
if (progress->showPercent) {
tt_print_str(progress->_percentStr, progress->_percentStr->width);
}
tt_puts("]");
tt_puts(line_break);
tt->tablePrintedHeight++;
}
_EXTERNAL void TT_LineBreak(TT tt, uint16_t lineCount) {
for (uint16_t i = 0; i < lineCount; i++)
tt_puts(line_break);
tt->tablePrintedHeight += lineCount;
}
_EXTERNAL void TT_CursorBack(TT tt) {
for (uint16_t i = 0; i < tt->tablePrintedHeight; i++) {
tt_puts("\033[F");
}
tt->tablePrintedHeight = 0;
tt->tablePrintedWidth = 0;
}
_EXTERNAL void TT_Print(TT tt) {
tt_puts("\033[1G\033[K"); // 清除本行
int16_t maxWidth = tt_calc_max_width(tt);
if (tt->tableMinWidth != WIDTH_DISABLED && maxWidth < tt->tableMinWidth)
maxWidth = tt->tableMinWidth;
tt_reset_fmt();
ulist_foreach(tt->items, term_table_item_t, item) {
switch (item->type) {
case TT_ITEM_TYPE_TITLE:
tt_print_str_sep(((TT_ITEM_TITLE)item->content)->str, maxWidth,
((TT_ITEM_TITLE)item->content)->separator);
tt_puts(line_break);
tt->tablePrintedHeight++;
break;
case TT_ITEM_TYPE_STRING:
tt_print_string(tt, (TT_ITEM_STRING)item->content, maxWidth);
break;
case TT_ITEM_TYPE_KVPAIR:
tt_print_kvpair(tt, (TT_ITEM_KVPAIR)item->content, maxWidth);
break;
case TT_ITEM_TYPE_GRID:
tt_print_grid(tt, (TT_ITEM_GRID)item->content, maxWidth);
break;
case TT_ITEM_TYPE_SEPARATOR:
tt_print_separator(tt, (TT_ITEM_SEPARATOR)item->content,
maxWidth);
break;
case TT_ITEM_TYPE_LINEBREAK:
TT_LineBreak(tt, ((TT_ITEM_LINEBREAK)item->content)->lineCount);
break;
case TT_ITEM_TYPE_PROGRESS:
tt_print_progress(tt, (TT_ITEM_PROGRESS)item->content,
maxWidth);
break;
}
}
tt_reset_fmt();
}