Skip to content

fix(table): align columns with WithWidth#980

Open
leno23 wants to merge 1 commit into
charmbracelet:mainfrom
leno23:fix/table-withwidth-column-resize-696
Open

fix(table): align columns with WithWidth#980
leno23 wants to merge 1 commit into
charmbracelet:mainfrom
leno23:fix/table-withwidth-column-resize-696

Conversation

@leno23
Copy link
Copy Markdown

@leno23 leno23 commented May 17, 2026

Summary

Fixes #696.

WithWidth previously only resized the viewport while headers and cells kept their configured column widths. That produced misaligned headers, wrapped cells, and trailing whitespace when the viewport was wider or narrower than the column sum.

This PR stores the requested table width and adjusts per-column content widths (accounting for header/cell padding) so the rendered header and rows match the target width.

Test plan

  • go test ./table/...
  • Added resize_test.go for expand/shrink width cases
  • Enabled previously skipped Width less than columns golden test
  • Updated golden files for width-related scenarios

Notes

Bordered cell/header styles that add extra frame size beyond padding are not fully addressed (existing TODO in tests).

Made with Cursor

WithWidth only changed the viewport width while headers and cells kept
their configured column widths, causing misaligned layout and trailing
padding (charmbracelet#696).

Distribute or shrink column content widths so the rendered table matches
the requested width, including default cell padding.

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

table.WithWidth doesn't work properly

1 participant