Repository navigation
fix(nu-term-grid): accept a grid that is exactly as wide as the limit - #19409
Conversation
There was a problem hiding this comment.
Review overview
🟡 Changes recommended
The <= fixes grids whose tallest layout is exactly the limit, so [aa bb cc] | grid --width 7 renders now instead of erroring. One path still throws away a layout that fits: [1 2 3 4 5] | grid --width 5 errors on the branch the same as on main.
Findings: 0
Open (3)
Notes from my clanker, checked on b5a396a. CI only ran triage on this head, so I built the branch and ran cargo test -p nu-term-grid (14 passed plus the doctest), cargo test -p nu-command --test tests -- commands::griddle (5 passed), clippy with CI's flags on nu-term-grid (clean), cargo fmt --all --check and typos (clean). Each grid case ran on the branch binary and on 0.116.2, plus a sweep of --width 1..40 over four lists. The fix in the first thread is from a trial patch on the branch, since reverted.
`width_dimensions` could fall through to `None` after the loop even though it had stored a fitting layout in `smallest_dimensions_yet`: every smaller `num_lines` aborts on the separator width. Return the stored layout instead, so `grid --width 5` (and 9/10/11) render instead of erroring. Update `huge_separator` for the single-column layout that now fits, keep `grid_errors_with_few_columns` on the error path with a cell wider than the limit, and add command-level exact-width cases to `crates/nu-command/tests/commands/griddle.rs`.
|
Thanks! Addressed all three threads in 3acea8c:
Tests:
|
|
please respond to each review finding so we can make sure nothing is missed |
|
Thanks |



Description
Grid::width_dimensionsrejected a layout that was exactly as wide as the limit (<instead of<=), and it could also fall through toNoneafter the loop even when it had already stored a fitting layout insmallest_dimensions_yet. That second path is hit when every smaller layout aborts on the separator width.Both show up through
gridwith the default│separator:aa │ ccis exactly 7 wide, and1 │ 4is exactly 5 wide (the two- and five-column layouts are too wide once the separators are counted). Widths 9, 10 and 11 fail the same way as width 5.The fix:
<=, so an exact fit is accepted;smallest_dimensions_yetinstead ofNone.Tests
multi_item_exact_widthincrates/nu-term-grid/src/grid.rspins the exact-width case.test_output_at_exact_widthincrates/nu-command/tests/commands/griddle.rscovers the command level for[aa bb cc] | grid --width 7and[1 2 3 4 5] | grid --width 5.huge_separatornow expects the single-column layout that fits, andgrid_errors_with_few_columnsuses[123456] | grid --width 5(a cell wider than the limit) so it still tests the error path.cargo test -p nu-term-gridpasses (14 tests plus the doctest) andcargo fmt --all -- --checkis clean. This machine has no MSVC linker, and the kitest harness links with 0 registered tests under MinGW, so the command-level cases were additionally checked by running a freshly builtnu:[aa bb cc] | grid --width 7printsaa │ cc/bb │,[1 2 3 4 5] | grid --width 5prints three rows, and[123456] | grid --width 5still errors.User-facing changes (Release notes)
gridnow uses layouts that fill the full width, so it no longer errors on a grid that fits exactly and can print fewer rows.