Skip to content

Fix table column alignment for wide characters - #576

Closed
mahirhir wants to merge 1 commit into
ihabunek:masterfrom
mahirhir:fix-table-wide-char-align
Closed

mahirhir wants to merge 1 commit into
ihabunek:masterfrom
mahirhir:fix-table-wide-char-align

Conversation

@mahirhir

Copy link
Copy Markdown
Contributor

Summary

print_table (used by toot lists) sized its columns with len(cell) and padded them with str.ljust(width). Both count code points, not terminal cells, so wide characters break the layout: CJK and emoji take two cells but were counted as one, which pushes every following column out of alignment.

The fix measures widths with wcswidth() and pads with wcstring.pad(), the wide-character aware helper already in the codebase. wcswidth() is also what status_lines uses to align the status header, so this just brings the table in line with the rest of the module. ASCII tables are unchanged.

Before (a list whose title contains CJK)

ID  Title    Replies
--  -------  --------
1   Hello    list
2   日本語のリスト  followed

After

ID  Title           Replies
--  --------------  --------
1   Hello           list
2   日本語のリスト  followed

Tests

Added tests/test_output.py, which renders a table mixing ASCII and CJK rows and asserts every row ends up the same display width. It fails on the old code and passes with the fix. pytest, flake8 and vermin all pass locally.

print_table measured column widths with len() and padded cells with
str.ljust(). Both count code points rather than terminal cells, so a
table containing wide characters (CJK, emoji) lost its alignment:
such characters occupy two cells but were counted as one. This is
reachable through `toot lists`, where a list title may use any
script.

Measure widths with wcswidth() and pad with wcstring.pad() instead.
wcswidth() is already used for alignment elsewhere in this module,
and pad() is the existing wide-character aware helper. ASCII tables
render exactly as before.
@mahirhir

mahirhir commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

Closing this to clean up my open PRs. It's a small change and not really worth taking up your review time. Sorry for the noise.

@mahirhir mahirhir closed this Jul 4, 2026
@ihabunek

ihabunek commented Jul 4, 2026

Copy link
Copy Markdown
Owner

You're an impatient one. :) I merged your contribution: 25b0057
Thanks, this is useful.

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