Skip to content

Pretty-printed table output with auto-detected TTY #156

@vmvarela

Description

@vmvarela

Description

When stdout is a TTY, format output as an aligned table with borders. When piped, stay CSV (preserving scriptability).

Examples

$ sql-pipe sales.csv 'SELECT region, SUM(amount) as total FROM orders GROUP BY region ORDER BY 2 DESC'
┌─────────┬───────────┐
│ region  │ total     │
├─────────┼───────────┤
│ AMER    │ 203100.75 │
│ EMEA    │ 142350.00 │
│ APAC    │  98210.50 │
└─────────┴───────────┘

# Piped output stays CSV — no behavior change for scripts
$ sql-pipe sales.csv 'SELECT ...' | grep AMER
AMER,203100.75

Acceptance Criteria

  • When stdout is a TTY, output is formatted as an aligned table with borders
  • When stdout is piped, output remains CSV (no behavior change)
  • Table includes column headers
  • Columns are properly aligned
  • Numeric values are right-aligned
  • Text values are left-aligned
  • Add --table / --no-table flags for explicit control
  • Handle wide tables gracefully (truncation or horizontal scrolling)
  • All existing tests pass
  • New tests cover TTY detection, table formatting, and piped output

Notes

  • Implementation: ~200-300 lines
  • Auto-detect TTY (already done for "Loaded N rows" message)
  • Buffer all rows, compute column widths, print table
  • Consider row limit for table mode (e.g., first 1000 rows, then switch to CSV with warning)
  • Negligible binary size impact (just string formatting)

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority:highMust be in the next sprintsize:lLarge — 1 to 2 daystype:featureNew functionality

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions