| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
…idths Fixes #354 When the header text width exactly matches the maxcolwidths limit, the existing code added min_padding (2 spaces) on top of the header width to compute the minimum column width. This inflated every cell in that column by 2 extra trailing spaces — visible as unexpectedly wide columns when the caller had calculated maxcolwidths from the terminal width. Root cause ---------- minwidths was computed as: minwidths = [width_fn(h) + min_padding for h in headers] then passed as the lower bound to _align_column. When the maximum data width (after wrapping to maxcolwidths) equals the header width, the column ended up being maxcolwidths + min_padding wide instead of the requested maxcolwidths. Fix --- After computing minwidths, for each column that has an explicit maxcolwidths entry: if the header width is >= the column limit, strip the +min_padding so the column is exactly max(header_width, maxcolwidth) wide. When the header is shorter than maxcolwidths the data (wrapped to maxcolwidth chars) is wider, and the existing behaviour is preserved — only the case where header_width >= maxcolwidth incorrectly inflated the column. Updated tests ------------- test_wrap_none_value and test_wrap_none_value_with_missingval: these tests used maxcolwidths=5 with a 5-char header ("Value"); their expected output encoded the buggy +2 behaviour and have been corrected. New test -------- test_maxcolwidth_no_extra_padding_when_header_equals_limit: directly reproduces the issue example from the bug report.
|
Closing this PR — found that PR #424 already addresses this issue. Apologies for the duplicate. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary
Fixes #354
When the header text width exactly matches the maxcolwidths limit, every cell in that column was rendered 2 chars wider than requested.
Example (from issue)
Before fix — Header#3 column cells are 12 chars wide (1 pad + 10 content + 1 pad):
After fix — 10 chars wide (1 pad + 8 content + 1 pad):
Root Cause
minwidths was computed as width_fn(header) + min_padding. When header_width >= maxcolwidths, this forced the column to be maxcolwidths + min_padding wide instead of maxcolwidths.
Fix
After computing minwidths, for each column with an explicit maxcolwidths entry, if header_width >= maxcolwidth, the spurious +min_padding is removed. When the header is shorter than maxcolwidths, data wrapping already limits width and the existing behaviour is preserved.
Tests