diff options
| author | Louis Burda <quent.burda@gmail.com> | 2023-06-07 04:59:02 +0200 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2023-06-07 04:59:06 +0200 |
| commit | 5ecf4f581ef42a7c6320b29f3e7173944c3cabf6 (patch) | |
| tree | b602b4256b81cecd412e31a2f0ef36a1f186fb74 | |
| parent | 07a9d50336cb2ecf8c282fbfc293130eef9a6eab (diff) | |
| download | tabular-5ecf4f581ef42a7c6320b29f3e7173944c3cabf6.tar.gz tabular-5ecf4f581ef42a7c6320b29f3e7173944c3cabf6.zip | |
Add squashable flag and update libtabular
| m--------- | lib/libtabular | 0 | ||||
| -rw-r--r-- | main.c | 26 |
2 files changed, 19 insertions, 7 deletions
diff --git a/lib/libtabular b/lib/libtabular -Subproject cf78bbc8205688626487cb15f83aa351a6f0786 +Subproject 466a4dcdf8adc4a08c93080e59a7c401779462d @@ -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); } |
