Skip to content

Added column spanning support for table body rows (#24)#2020

Merged
patriksvensson merged 4 commits intospectreconsole:mainfrom
thomastv:feature/body-row-colspan
Feb 23, 2026
Merged

Added column spanning support for table body rows (#24)#2020
patriksvensson merged 4 commits intospectreconsole:mainfrom
thomastv:feature/body-row-colspan

Conversation

@thomastv
Copy link
Copy Markdown
Contributor

Fixes #24

  • I have read the Contribution Guidelines
  • I have checked that there isn't already another pull request that solves the above issue
  • All newly added code is adequately covered by tests
  • All existing tests are still running without errors

AI Disclosure: GitHub Copilot (Claude Opus 4.6) was used to assist with implementation, code review, and unit test creation. All changes were reviewed and validated by me. Copilot was used mainly to generate unit tests.

Changes

Adds column spanning support for table body rows, as requested in #24.

New API

A new TableCell class wraps cell content with a fluent .Span(int) API:

var table = new Table();
table.AddColumns("Item", "Qty", "Unit Price", "Total");
table.AddRow("Item A", "5", "20", "100");
table.AddRow(new IRenderable[] {
    new Markup("Item B"),
    new TableCell("Note: deliver after 5pm").Span(3)
});
table.AddRow("Item C", "3", "15", "45");

Scope

  • Column spanning only — row spanning is left for future work
  • Body rows only — spanning in headers/footers throws InvalidOperationException
  • Row separator lines (├──┼──┤) don't yet merge under spanned cells (cosmetic, can be addressed in a follow-up)

Files changed

  • New: TableCell.cs — IRenderable wrapper with ColumnSpan property and fluent Span() method
  • Modified: TableRenderer.cs — span-aware cell width calculation, correct separator/edge handling for spanned cells
  • Modified: TableMeasurer.cs — distributes spanned cell measurements proportionally across columns
  • Modified: TableRowCollection.cs — span-aware row validation (total span vs column count)
  • Modified: TableColumn.cs — rejects TableCell with span > 1 in Header/Footer property setters
  • Modified: TableRow.cs — rejects spanning cells in header/footer row constructors

Please upvote 👍 this pull request if you are interested in it.

@thomastv
Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@thomastv
Copy link
Copy Markdown
Contributor Author

Thanks @patriksvensson for taking the time to review and for the detailed feedback. I’ve addressed the requested changes — please let me know if anything else needs adjustment.

@patriksvensson patriksvensson merged commit 89b78f4 into spectreconsole:main Feb 23, 2026
3 checks passed
red-stronghold pushed a commit to red-stronghold/spectre.console that referenced this pull request Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow a single row or header to span multiple columns in tables

3 participants