Skip to content

cli: draw tables with box-drawing characters (scripts parsing table output should use --format json) - #2476

Merged
bplatz merged 4 commits into
mainfrom
feat/cli-box-tables
Nov 22, 2026
Merged

bplatz merged 4 commits into
mainfrom
feat/cli-box-tables

Conversation

@FlureeKevin

@FlureeKevin FlureeKevin commented Nov 20, 2026 •

Copy link
Copy Markdown

What

Every table the CLI prints now uses box-drawing characters instead of comfy-table's default ASCII_FULL style. Under the old style, the header rule (+=====+) had no column junctions, so tables looked broken, most visibly in the README hero GIF.

All comfy-table call sites (query --format table, list, branch, graph, remote, track, bm25, history, token, upstream, iceberg) now go through a shared output::new_table() helper, so the tables all match. The style is comfy-table's UTF8_FULL_CONDENSED with solid column rules (│ instead of ┆) and a single-line ├─┼─┤ header rule (instead of ╞═╪╡).

Before / after

Same binary and ledger, fluree query --format table --sparql -e 'SELECT ?name ?age …':

Before:

+-----+-------+
| age | name  |
+=============+
| 42  | Alice |
|-----+-------|
| 27  | Bob   |
+-----+-------+

After:

┌─────┬───────┐
│ age │ name  │
├─────┼───────┤
│ 42  │ Alice │
│ 27  │ Bob   │
└─────┴───────┘

fluree list after:

┌───┬────────┬────────┬───┐
│   │ LEDGER │ BRANCH │ T │
├───┼────────┼────────┼───┤
│ * │ demo   │ main   │ 1 │
└───┴────────┴────────┴───┘

Other changes

  • history_* regression test: it asserted !contains("| ? |"), which would have passed trivially under the new border. It now asserts on │ ? │ and first checks that the output is box-drawn, so a later style change can't make it pass vacuously again.
  • New unit tests in output.rs pin the exact rendering and check that the SPARQL table path uses the shared style. Both fail when the preset is removed.
  • scripts/glue-local/check.sh and selftest.sh parsed the first | N | row. Both now read it through one table_count in env.sh that accepts either border, so they can still grade older binaries.
  • fluree-db-cli/clippy.toml refuses comfy_table::Table::new, so a new table can't bypass new_table().
  • docs/cli/bm25.md: the sample output is redrawn.

For scripts

This changes the text of every table the CLI prints, piped or not, and fluree query prints a table by default. A script that parses that text should use --format json (or csv / tsv where the target allows it).

Not changed

  • Column order: still alphabetical. The sort in format_sparql_table_from_result is deliberate; its comment says it matches the SPARQL JSON head-vars behavior.
  • No ASCII fallback: the CLI's only existing switch is --no-color / NO_COLOR, which controls color, not glyphs, so I didn't add a new flag.

Verification

  • cargo fmt --all: no changes
  • cargo clippy -p fluree-db-cli --all-targets --no-deps: clean
  • cargo test -p fluree-db-cli: all pass (580 tests)

Follow-up, outside this PR: the README's 60-second tour sample and the hero GIF (scripts/readme/render-tour.sh) can be regenerated after this merges.

🤖 Generated with Claude Code

Every comfy-table the CLI prints (query --format table, list, branch,
graph, remote, track, bm25, history, token, upstream, iceberg) now goes
through a shared output::new_table() helper that applies one box-drawing
style instead of comfy-table's default ASCII_FULL, whose `+=====+` header
rule had no column junctions and read as broken.

The style is UTF8_FULL_CONDENSED with solid column rules and a single-line
`├─┼─┤` header rule. The history regression test asserted on `| ? |`, which
would have gone vacuous under the new border; it now asserts on `│ ? │` and
checks the output is box-drawn. scripts/glue-local/check.sh parsed the
first `| N |` row; it now accepts either border so it still grades older
binaries.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@FlureeKevin FlureeKevin added the area:cli fluree CLI UX, rdf toolkit, publish/export/insert flows label Nov 20, 2026

@aaj3f aaj3f left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FlureeKevin this is a nice cleanup, and I think the docs were already asking for it: docs/cli/query.md, history.md, remote.md, upstream.md, the tutorial and the time-travel cookbook all show exactly these box-drawn tables, which the CLI never printed. The one must is below: scripts/glue-local/selftest.sh greps the same | N | row check.sh did, and it wasn't updated.

My reading is that this changes every table the CLI prints, piped or not, and fluree query defaults to table output, so any script parsing it breaks. I think that's right, since the docs already show this style, but I'd like your confirmation it's intended, plus a line in the PR body steering scripts to --format json so the release notes carry it.

On sequencing, your #2474 shows the ASCII tables this replaces in its hero GIF and tour sample, so I'd land this one first and re-render there.

Full review below:


✅ Approving to unblock: please get the selftest.sh regex in before merging. The shared new_table() is the right altitude, the exact-render test pins the preset, and Claude confirmed all three changed tests go red when the preset is removed.

Before merging:

  1. scripts/glue-local/selftest.sh:36: same border-agnostic regex as check.sh (or both scripts on --format json).

Notes:

  • This is the second time rendered table text has broken as a machine interface: history_shows_changes (137eb8ff2, made padding-proof in 4c39d62d2, glyph-proof here) and the glue-local scripts (9529658a4). The structural direction is that machine consumers read --format json; for this PR that means the two scripts and the steering line in the body, nothing more.
  • #2474 and this PR touch no common file (git merge-tree is clean), but they disagree on what a table looks like. Landing this first lets #2474's tour sample and GIF show what the CLI prints, matching the rest of the docs.
  • Claude checked the edges the body didn't: piped output and NO_COLOR=1 are box-drawn too (glyphs aren't styling), and the CLI already prints ✓, ✗, — and › in 37 places, so a non-UTF-8 Windows console isn't a new concern. docs/cli/bm25.md was the only ASCII sample in the docs.
Adherence: patterns ✔ · performance ✔ · deployment ✔ · testing ✔ · conventions ⚠️ · verification
  • Patterns/abstractions: ✔ one constructor in output.rs, every comfy-table call site routed through it; a clippy disallowed-methods entry would make that enforced rather than conventional.
  • Performance (speed first, memory second): ✔ rendering only; no query or engine path touched. No performance-degradation risk.
  • Deployment targets: ✔ n/a: fluree-db-cli only; nothing reaches the embedded library, the server or wasm32.
  • Testing: ✔ two unit tests plus the guarded integration test, all non-vacuous under mutation; 580 fluree-db-cli tests pass.
  • Conventions: ⚠️ multi-line commit, fmt and clippy clean; one script consumer missed, and the CLI output change has no release-notes line yet.

Verified at df4b6b00b: CI run 44804533712 green (nextest 16567 passed, including the three changed tests); on a c7i.4xlarge box Claude ran cargo test -p fluree-db-cli (580 passed), removed the preset (both unit tests and history_shows_changes fail), rendered multi-line and wrapped cells in both styles, ran the README tour and the glue-local regexes against the built binary (selftest regex extracts nothing, check.sh's extracts the count), and tried the clippy guard in fluree-db-cli/clippy.toml (clean as written; fails on one bypass).

Approving so you can merge once selftest.sh is in, but maybe worth considering the lint guard and the release-notes line first.

Comment thread scripts/glue-local/check.sh Outdated
out="$("$FLUREE" query "$name" "$query" 2>&1)" # table format: graph-source targets refuse csv
if grep -qi '^error' <<<"$out"; then echo "ERR: $(grep -im1 '^error' <<<"$out" | cut -c1-160)"; return; fi
local n; n="$(grep -oE '^\| *[0-9]+ *\|' <<<"$out" | head -1 | tr -dc '0-9')"
local n; n="$(grep -oE '^(\||│) *[0-9]+ *(\||│)' <<<"$out" | head -1 | tr -dc '0-9')"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking: selftest.sh greps the same | N | row and wasn't updated, so every selftest check fails against this binary.

selftest.sh:36 still extracts the count with grep -oE '^\| *[0-9]+ *\|'. With the box-drawn border that matches nothing, n comes back empty, and each of the four run checks prints FAIL … expected 50 got <first error line>. The glue-local README tells people to "expect 4/4 pass" before trusting check.sh, so the harness would now fail its own self-check.

Claude reproduced it on a box with this PR's binary and GNU grep 3.8: a piped SELECT (COUNT(?m) AS ?n) … printed │ 2 │, selftest.sh's regex extracted '' and check.sh's new one extracted 2.

The minimal fix is the same regex as here:

n="$(grep -oE '^(\||│) *[0-9]+ *(\||│)' <<<"$out" | head -1 | tr -dc '0-9')"

This is more of a suggestion than a must, but both scripts parse the table only because fluree query refuses --format csv/tsv for graph-source targets (commands/query.rs:1986-1993), so moving both to --format json and reading the count with $PY would take them off the border glyphs for good. If you agree that's right, I'd rather see it in this PR than lost in the backlog.

Commenting here because scripts/glue-local/selftest.sh is not in this diff.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in cf9c0ea. Both scripts now read the count through one table_count in env.sh.

/// A new [`Table`] with the CLI's shared box-drawing style applied.
///
/// Use this instead of `Table::new()` so every table the CLI prints matches.
pub fn new_table() -> Table {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: we could make "every table goes through new_table()" a lint rather than a convention.

Right now nothing stops the next command from calling Table::new(), and sparql_table_uses_shared_style covers one of the eighteen call sites. fluree-db-cli/clippy.toml already uses disallowed-methods for exactly this kind of convention (fluree_graph_turtle::parse_to_json), and CI runs clippy with -D warnings, so one more entry turns a bypass into a CI failure:

    { path = "comfy_table::Table::new", reason = "use crate::output::new_table() so every CLI table shares one style" },
pub fn new_table() -> Table {
    #[expect(clippy::disallowed_methods, reason = "the one sanctioned constructor")]
    let mut table = Table::new();

Claude tried it on a box: cargo clippy -p fluree-db-cli --all-targets --no-deps -- -D warnings is clean with the entry, and fails with "use of a disallowed method comfy_table::Table::new" when one call site in remote.rs goes back to comfy_table::Table::new(). (It has to go in the crate's own clippy.toml; clippy doesn't read the workspace-root one for this crate.) I recognize this is minor and non-blocking, but if you agree it's right, I'd rather see it folded in now than lost in the backlog.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in e2a86be

/// Characters follow comfy-table's preset order: left/right border, top/bottom
/// border, header rule (left, line, middle, right), column rule, row rule
/// (line, middle, left, right; blank = none), top/bottom junctions, corners.
const TABLE_STYLE: &str = "││──├─┼┤│ ┬┴┌┐└┘";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: this is more of a question than a suggestion. With no rules between body rows, a row boundary only shows through the leftmost column.

UTF8_FULL_CONDENSED drops ASCII_FULL's |---+---| row rules. That reads much better for one-line rows, which is most output. But when a cell wraps (dynamic arrangement in a narrow terminal) or holds a newline, the continuation lines show blank cells in the other columns, and if the first column is itself empty the continuation reads as a new row. The --at 1 frame in #2474's GIF is that shape: genre sorts first and is unbound. Claude rendered both styles on a box with a two-line literal and a long IRI at width 44; the box-drawn one is fine as long as column one is populated.

I don't think this needs to change, but I wanted to flag it in case you'd prefer row rules when some cell spans more than one line (comfy-table won't decide that itself, so it would take a small render step that picks the preset once the rows are in). Not a big deal either way.

let stdout = String::from_utf8(assert.get_output().stdout.clone()).unwrap();
// Guard against this check going vacuous if the table style changes again.
assert!(
stdout.contains('│'),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Praise: the contains('│') guard is exactly right. It makes the │ ? │ check fail loudly on the next style change instead of passing vacuously, which is how this assertion went wrong before (4c39d62d2). Claude confirmed it: with the preset removed, history_shows_changes fails with "expected box-drawn table output".

@bplatz bplatz added the enhancement New feature or request label Nov 22, 2026
@bplatz bplatz changed the title cli: draw tables with box-drawing characters cli: draw tables with box-drawing characters (scripts parsing table output should use --format json) Nov 22, 2026
@bplatz
bplatz merged commit 9fa4e62 into main Nov 22, 2026
21 checks passed
@bplatz
bplatz deleted the feat/cli-box-tables branch November 22, 2026 02:20
bplatz added a commit that referenced this pull request Nov 22, 2026
Brings #2476 (every CLI table is box-drawn through output::new_table(),
clippy refuses comfy_table::Table::new in the CLI crate, and the
glue-local scripts read either border through one table_count).

No conflicts. next's `fluree dropped` list, which main does not have,
moves to the shared style in the next commit.
bplatz added a commit that referenced this pull request Nov 22, 2026
next's `fluree dropped list`, which main does not have, built its table with comfy_table::Table::new, which #2476 now refuses in the CLI crate, and printed the old ASCII border. It takes output::new_table() like every other table, and docs/cli/dropped.md shows the box-drawn list.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:cli fluree CLI UX, rdf toolkit, publish/export/insert flows enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants