feat: pretty-printed table output with auto-detected TTY#163
Merged
Conversation
10 tasks
When stdout is a TTY, format query results as an aligned table with Unicode box-drawing borders. When piped, output stays CSV (preserving scriptability). Numeric columns are right-aligned, text left-aligned. - Add src/table.zig: buffers rows, computes column widths, detects numeric columns, prints formatted table with ┌─┬─┐ borders - Add --table / --no-table flags for explicit control (TableMode enum) - Auto-detect stdout TTY in main() to resolve table mode - Table mode disabled when --output writes to a file - --table is incompatible with non-CSV/TSV output formats (error) - Update README.md with table output examples and flag docs - Add 7 integration tests covering table output, piped CSV, error paths, numeric alignment, empty results, and --output interaction Closes #156
c70563f to
aed8f0b
Compare
- Implement two-pass streaming with sqlite3_reset to reduce memory from O(rows×cols) to O(cols) - Add visualWidth() helper for proper CJK character alignment (width 2) - Check sqlite3_step return codes and propagate errors - Batch write operations for better performance - Show NULL explicitly instead of blank cells - Fix Z023 parameter order (std.Io before other params) - Add unit tests for isNumericString and visualWidth
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements #156 — when stdout is a TTY, query results are automatically formatted as an aligned table with Unicode box-drawing borders. When piped, output stays CSV (no behavior change for scripts).
Changes
src/table.zig(new): Table formatting module with two-pass streaming architectureisNumericStringandvisualWidthsrc/args.zig: AddedTableModeenum (auto/always/never) and--table/--no-tableCLI flags.--tableis validated as incompatible with non-CSV/TSV output formats.src/main.zig: Added stdout TTY detection to resolve table mode. Auto-detection restricted to CSV/TSV output formats. Table output disabled when--outputwrites to a file.README.md: Added table output example in the usage section, documented--table/--no-tablein the flags table.build.zig: Added 7 integration tests covering table output, piped CSV, error paths, numeric alignment, empty results, and--outputinteraction.Example
Unicode support (CJK characters align correctly):
Acceptance Criteria
--table/--no-tableflags for explicit controlCode Review Improvements
After initial implementation, code review identified and fixed:
.automode now restricted to CSV/TSV output (prevents tables for JSON/XML)sqlite3_steperrors now checked and propagated