Skip to content

fix(table): measure cell width in terminal cells, not characters - #558

Open
draarivpatel-ui wants to merge 2 commits into
python-poetry:mainfrom
draarivpatel-ui:fix-table-wide-char-width
Open

draarivpatel-ui wants to merge 2 commits into
python-poetry:mainfrom
draarivpatel-ui:fix-table-wide-char-width

Conversation

@draarivpatel-ui

Copy link
Copy Markdown

Table cells containing wide characters (CJK, emoji) render with misaligned borders:

+------+----+
| 你好世界 | x  |
| c    | dd |
+------+----+

Widths are measured with len(), counting every character as one column, while a wide character occupies two terminal cells. Rows with more wide characters push the right border further out than rows without them.

What changes

Measure cell and title width with the wcswidth() helper from cleo._utils instead of len(), falling back to the character count for control characters, which have no well-defined display width. Three measurement sites in table.py change; the padding arithmetic is unaffected because padding characters are one cell wide each, so the character-count targets passed to pad() still produce the correct number of padding characters.

With the fix:

+----------+----+
| 你好世界 | x  |
| c        | dd |
+----------+----+

Tests

  • test_render_cjk_and_wide_chars_align and test_render_wide_chars_in_headers_align cover CJK content in body cells and headers.
  • Pure-ASCII output is unchanged (wcswidth equals len there), so all existing golden tests pass unmodified.
  • pytest tests/ shows no failures (the pre-existing ERRORs in completion/progress tests are environmental and identical on unmodified master). ruff check and ruff format clean.

Table cells containing wide characters (CJK, emoji) rendered with
misaligned borders: widths were measured with len(), counting every
character as one column, while a wide character occupies two terminal
cells. Rows with more wide characters pushed the right border further
out than rows without them.

Measure with the wcswidth() helper from cleo._utils instead, falling
back to the character count for control characters, which have no
well-defined display width. The padding arithmetic is unaffected since
padding characters are one cell wide each.
Copilot AI balanced review requested due to automatic review settings November 26, 2026 01:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

This branch has not been deployed

No deployments
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.

2 participants