tabular

Flexible input tabulator
git clone https://git.sinitax.com/sinitax/tabular
Log | Files | Refs | Submodules | sfeed.txt

commit 5ecf4f581ef42a7c6320b29f3e7173944c3cabf6
parent 07a9d50336cb2ecf8c282fbfc293130eef9a6eab
Author: Louis Burda <quent.burda@gmail.com>
Date:   Wed,  7 Jun 2023 04:59:02 +0200

Add squashable flag and update libtabular

Diffstat:
Mmain.c | 26+++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/main.c b/main.c @@ -66,7 +66,7 @@ static struct tabular_cfg cfg = { .row_gen = row_gen, .print_style = print_style, - .skip_lines = 3, + .skip_lines = 4, .allocator = &stdlib_heap_allocator }; @@ -208,6 +208,7 @@ col_hidden(const struct tabular_user *user, const struct tabular_user *user_col) return true; off = dvec_at(&entries, user_col->id); + return !strcmp(line.data + *off, ""); } @@ -257,6 +258,10 @@ parse(int argc, const char **argv) if (!*++arg) die("missing args"); cfg.rpad = strtoul(*arg, &end, 10); if (end && *end) die("bad %s", arg[-1]); + } else if (!strcmp(*arg, "--skip-lines")) { + if (!*++arg) die("missing args"); + cfg.skip_lines = strtoul(*arg, &end, 10); + if (end && *end) die("bad %s", arg[-1]); } else if (!strcmp(*arg, "--fit-rows")) { if (!*++arg) die("missing args"); cfg.fit_rows = bool_arg(*arg, "--fit-rows"); @@ -329,14 +334,15 @@ parse(int argc, const char **argv) col->name = *arg; col->align = TABULAR_ALIGN_LEFT; - col->essential = false; + col->essential = true; col->is_hidden = col_hidden; col->to_str = col_str; col->lpad = 0; col->rpad = 0; col->minwidth = strlen(col->name); col->maxwidth = cfg.outw; - col->strategy = TABULAR_SQUASH_WORDAWARE; + col->strategy = TABULAR_WRAP_WORDAWARE; + col->squashable = false; col->user.id = colcnt++; rc = hmap_add(&colmap, (struct hmap_key) { .p = upper }, @@ -383,6 +389,9 @@ parse(int argc, const char **argv) } else { die("bad %s", arg[-1]); } + } else if (!strcmp(*arg + n, "squashable")) { + if (!*++arg) die("missing args"); + col->squashable = bool_arg(*arg, arg[-1]); } else if (!strcmp(*arg + n, "essential")) { if (!*++arg) die("missing args"); col->essential = bool_arg(*arg, arg[-1]); @@ -399,9 +408,9 @@ parse(int argc, const char **argv) } else if (!strcmp(*arg + n, "strategy")) { if (!*++arg) die("missing args"); if (!strcmp(*arg, "word-aware")) { - col->strategy = TABULAR_SQUASH_WORDAWARE; - } else if (!strcmp(*arg, "squash")) { - col->strategy = TABULAR_SQUASH; + col->strategy = TABULAR_WRAP_WORDAWARE; + } else if (!strcmp(*arg, "wrap")) { + col->strategy = TABULAR_WRAP; } else if (!strcmp(*arg, "trunc")) { col->strategy = TABULAR_TRUNC; } else { @@ -446,8 +455,11 @@ main(int argc, const char **argv) rc = tabular_format(stdout, &cfg, &stats, &rows); if (rc) errx(1, "tabular_format (%i)", rc); - printf("\n%lu lines, %lu rows\n", + printf("\n%lu lines, %lu rows", stats.lines_used, stats.rows_displayed); + if (stats.rows_truncated) printf(" (rows truncated)"); + if (stats.cols_truncated) printf(" (cols truncated)"); + printf("\n"); tabular_free_rows(&cfg, rows); }