Public: anyone can read this; the crew can change it.

The terminal workspace shows a .csv or .tsv file as an aligned table with a header row, and `s` flips to its source #7401

opened this

Merged 38d 14h ago, live in production

A .csv or .tsv tab in the terminal workspace now opens as an aligned table, and s flips it to the source and back. bun x tsc --noEmit and bun scripts/design-lint.ts are clean. I ran test/text-csv.test.ts and test/tui-workspace.test.ts (31 pass), not the whole suite.

Notes

opened this

A .csv or .tsv tab in the terminal workspace now opens as an aligned table, and s flips it to the source and back. bun x tsc --noEmit and bun scripts/design-lint.ts are clean. I ran test/text-csv.test.ts and test/tui-workspace.test.ts (31 pass), not the whole suite.

What changed

  • src/text/csv.ts: parseCsv(text, { maxRows = 1000, delimiter? }) returns { header, rows, more, delimiter, error? }. It handles quoted fields, "", newlines inside quotes, CRLF, a BOM and blank lines. The delimiter (, ; or tab) is sniffed from the first line, ignoring quoted text. Rows past the cap are counted in more and never built. sniffDelimiter is exported, so #7334 can reuse the module for the web table.
  • src/tui/ui/grid.ts: layoutTable pads each column to its widest cell, capped at 32 columns with ….
  • Table view in src/tui/screens/workspace.ts:
    • Opening a CSV draws the table with the header bold and pinned on the top row while the data scrolls under it.
    • h/l scroll sideways, and / and n search the data rows.
    • The status line shows N rows, or N rows, first 1000 shown when the cap cuts it off.
  • s:
    • It toggles table and source, and appears in the key hints only on table files.
    • Editing a CSV shows the source until you press s again, as markdown does with v.
    • A file that doesn't parse opens as source, with not a table: line N, <reason> in the status line.
    • Pressing s on a broken file shows the same message as a toast.
  • Tests:
    • test/text-csv.test.ts covers each parsing case above, the cap, the error lines and the column layout.
    • A new test in test/tui-workspace.test.ts opens a CSV, checks the aligned columns and the pinned header after G, flips to the source and back, and opens a broken CSV to see the source and the error line.

Left out

  • Ragged rows are padded, not reported as errors.
  • There are no row numbers or per-column alignment for numbers.
  • Only a quote in the wrong place or an unclosed quote counts as a parse error.
  • Cells with newlines are flattened to one line in the table, and the source keeps them.
  • The web table (#7334) is untouched.

Try it: open a repository in the terminal, open a .csv through the t finder, then press s. The s flip exists only on .csv and .tsv tabs.

🤖 Generated with Claude Code

Closes #7344

4 earlier comments
commented

A .csv or .tsv tab in the terminal workspace now opens as an aligned table, and s flips it to the source and back. bun x tsc --noEmit and bun scripts/design-lint.ts are clean. I ran test/text-csv.test.ts and test/tui-workspace.test.ts (31 pass), not the whole suite.

What changed

  • src/text/csv.ts: parseCsv(text, { maxRows = 1000, delimiter? }) returns { header, rows, more, delimiter, error? }. It handles quoted fields, "", newlines inside quotes, CRLF, a BOM and blank lines. The delimiter (, ; or tab) is sniffed from the first line, ignoring quoted text. Rows past the cap are counted in more and never built. sniffDelimiter is exported, so #7334 can reuse the module for the web table.
  • src/tui/ui/grid.ts: layoutTable pads each column to its widest cell, capped at 32 columns with ….
  • Table view in src/tui/screens/workspace.ts:
    • Opening a CSV draws the table with the header bold and pinned on the top row while the data scrolls under it.
    • h/l scroll sideways, and / and n search the data rows.
    • The status line shows N rows, or N rows, first 1000 shown when the cap cuts it off.
  • s:
    • It toggles table and source, and appears in the key hints only on table files.
    • Editing a CSV shows the source until you press s again, as markdown does with v.
    • A file that doesn't parse opens as source, with not a table: line N, <reason> in the status line.
    • Pressing s on a broken file shows the same message as a toast.
  • Tests:
    • test/text-csv.test.ts covers each parsing case above, the cap, the error lines and the column layout.
    • A new test in test/tui-workspace.test.ts opens a CSV, checks the aligned columns and the pinned header after G, flips to the source and back, and opens a broken CSV to see the source and the error line.

Left out

  • Ragged rows are padded, not reported as errors.
  • There are no row numbers or per-column alignment for numbers.
  • Only a quote in the wrong place or an unclosed quote counts as a parse error.
  • Cells with newlines are flattened to one line in the table, and the source keeps them.
  • The web table (#7334) is untouched.

Try it: open a repository in the terminal, open a .csv through the t finder, then press s. The s flip exists only on .csv and .tsv tabs.

🤖 Generated with Claude Code

commented

All four findings are fixed and pushed to the same branch. bun x tsc --noEmit, bun scripts/design-lint.ts and the two test files I touched pass (33 tests); I didn't run the full suite.

  1. Wide CSV (high): parseCsv now keeps at most 64 fields per record (MAX_COLUMNS). Extra fields are counted in a new Table.columns and never stored, so layoutTable works on 64 columns at most.
    • Status line: it shows N more columns when the file is wider than the cap.
    • Test: a file with 100,000 commas on the header line plus 1,000 rows parses and lays out in under 500 ms, with 64 columns and 100,001 counted.
    • Not capped: I did not add a cap on total kept bytes. Rows (1,000) × columns (64) bound the cell count, and a single cell can still be as large as the file.
  2. .tsv (high): rebuild now parses the decoded source, not the tab-expanded plain, and passes { delimiter: "\t" } for .tsv paths. That also fixes a TSV header containing a comma. The workspace test opens a .tsv whose header contains a comma and checks that it shows name, full │ qty.
  3. README: I added a paragraph on the table view, s, the row and column caps, and not a table: line N.
  4. Control characters: I did not check whether drawShifted or the surface strips ESC. Instead flat in grid.ts now replaces C0, DEL and C1 characters with a space before layout, and a test with \x1b[2J in a cell confirms none reach the grid.
commented

I've addressed all seven points except #4, which I'm declining; the fixes are pushed to the same branch. bun x tsc --noEmit and bun scripts/design-lint.ts are clean, and test/text-csv.test.ts and test/tui-workspace.test.ts pass (35 tests). I did not run the full suite.

  1. Timer: removed from the wide-file test. The structural assertions stay (64 header columns, columns === 100_001, 64 columns in the grid header).
  2. Tests: a new workspace test covers each behaviour you listed:
    • Search: / on a CSV finds a row that was off-screen.
    • Edit: e then esc leaves the source showing, and s brings the table back.
    • Caps: the status line shows 1100 rows, first 1000 shown and 6 more columns.
    • Semicolons: a ;-separated .csv renders as a table.
    • Broken file: s on it shows not a table: line 2.
  3. s toast: it is now a silent no-op on non-table files. In edit mode s never reaches it, because the editor owns the keys.
  4. Dead assignment: declined. The t.asTable = true near line 724 is in loadTab, the common load path for every text tab, not an image-only branch. It resets the table view when a tab is re-read with r or a ref switch, the same way t.rendered = true does just above it.
  5. Simplifications:
    • Delimiter: delimiter is a plain const now, and CsvOptions.delimiter accepts | undefined so exactOptionalPropertyTypes is satisfied.
    • Status line: the table part moved into tableStatus(table) next to tableProblem, and the read only tail appears once.
    • eslint comment: removed, since the repo has no eslint config.
  6. README: the paragraph now sits after the terminal history paragraph, and it says cells wider than 32 columns are cut with … while the source view shows them whole. There is no dedicated workspace section in the README, so that is the closest fit.
  7. Bare \r: inside a quoted field it now counts as a line, with a unit test.
commented

The full gate on land was red; the pull is open again. Red tests:

  • GET /apps/open names its phases and answers within its budget

The gate's log: /api/v1/repos/trevato/forge/gates/1793134062410-56faf0a92af6/log

Red on top of #7328, #7393, #7395, #7389, #7397, #7396, #7405, which landed first from the same merge-queue candidate: red on its own on that base, or only together with them. Bring this pull up to date with the base and push.

commented

I merged the current origin/main into the branch and pushed it. The merge was clean, with no conflicts and no code changes from me.

I didn't reproduce the GET /apps/open names its phases… failure. That test lives in one of the timing test files and doesn't touch the terminal workspace. My test selection matched 105 files, and all 220 tests pass on the merged branch. They include test/text-csv.test.ts and test/tui-workspace.test.ts, and bun x tsc --noEmit is clean. If the gate goes red on that test again, it is a timing flake or an interaction among the pulls that landed before this one (#7328, #7393, #7395, #7389, #7397, #7396, #7405), not this change.

I did not do juniper's two non-blocking follow-ups:

  • Per-cell byte cap: one cell can still be as large as the file, because only rows and columns are capped.
  • Web table reuse: parseCsv and layoutTable are not yet reused for the web table in #7334.
Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs