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
|
#pragma once
#include "allocator.h"
#include <wchar.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <wctype.h>
enum {
TABULAR_ALIGN_LEFT,
TABULAR_ALIGN_CENTER,
TABULAR_ALIGN_RIGHT
};
enum {
TABULAR_TRUNC,
TABULAR_WRAP,
TABULAR_WRAP_WORDAWARE
};
enum {
TABULAR_ENTRY_HIDDEN,
TABULAR_ENTRY_STR_SET,
TABULAR_ENTRY_HIDDEN_SET,
};
struct tabular_user {
union {
void *ptr;
size_t id;
};
};
struct tabular_entry {
char *str;
uint32_t flags;
uint32_t ulen;
};
struct tabular_row {
struct tabular_user user;
struct tabular_entry *entries;
struct tabular_row *next;
};
struct tabular_col {
struct tabular_user user;
/* column name displayed in header */
const char *name;
/* create str entry to display from user objects */
char *(*to_str)(const struct tabular_user *user_row,
const struct tabular_user *user_col);
/* only show content if atleast one row is not 'hidden' */
bool (*is_hidden)(const struct tabular_user *user_row,
const struct tabular_user *user_col);
/* size restrictions */
size_t minwidth, maxwidth;
/* whitespace padding */
size_t lpad, rpad;
/* text alignment */
int align;
/* content packing strategy */
int strategy;
/* omiting column due to col contraints disallowed */
bool essential;
/* reducing length due to col contraints allowed */
bool squashable;
};
struct tabular_cfg {
struct tabular_user user;
const struct tabular_col *columns;
size_t column_count;
/* color mode: 1, 16, 256 */
int colors;
/* fit rows to output size */
bool fit_rows;
/* amount of available lines to skip */
size_t skip_lines;
/* output dimensions */
size_t outw, outh;
/* entry separators */
const char *hsep, *vsep, *xsep;
/* total lpad, rpad */
size_t lpad, rpad;
/* lazy load rows */
struct tabular_row *(*row_gen)(const struct tabular_user *user);
/* style printing hook for header, separators and content */
bool (*print_style)(FILE *file, const struct tabular_cfg *cfg,
const struct tabular_row *row, const struct tabular_col *col);
const struct allocator *allocator;
};
struct tabular_stats {
bool rows_truncated;
bool cols_truncated;
size_t rows_displayed;
size_t lines_used;
};
int tabular_format(FILE *file, const struct tabular_cfg *cfg,
struct tabular_stats *stat, struct tabular_row **rows);
void tabular_load_row_entry_hidden(const struct tabular_cfg *cfg,
struct tabular_row *row, size_t col);
void tabular_load_row_entry_str(const struct tabular_cfg *cfg,
struct tabular_row *row, size_t col);
struct tabular_row *tabular_alloc_row(const struct tabular_cfg *cfg,
int *error, struct tabular_user user);
int tabular_free_rows(const struct tabular_cfg *cfg, struct tabular_row *rows);
|