Repository navigation
Add striped rows to table and explore - #19575
Conversation
|
Hey, just a bot checking in! You edited files related to the configuration. |
c6291ba to
dc21020
Compare
|
This is cool. However, as fun as this PR is, not working on Windows will probably stop me from landing it. Nushell has to be as cross platform as possible. I also am not a fan of this: All other colors in color config follow the same convention. Having one different is a recipe for confusion and problems. I could probably live with this in the table config part but colors are meant for the color_config. So, I'm not quite sure. We could also split this into 2 lines. |
Ooh, microsoft/terminal#17729 says Windows can respond to OSC 11! There is a crate for handling those queries in a cross-platform way, so probably worth considering that.
Fair – so the only values for properties under |
dc21020 to
222e141
Compare
ok, good.
Maybe have a I'll also look at the security audit finding. |
<!-- Thanks for contributing to Nushell! Before submitting, please read the contributing guide: https://github.com/nushell/nushell/blob/main/CONTRIBUTING.md This template helps reviewers understand your changes and allows us to generate high-quality release notes. --> ## Description The `Security audit` job fails on every PR that touches `Cargo.toml` or `Cargo.lock` (for example #19575), and on main. The advisory database now flags `libz-sys` 1.1.31 for RUSTSEC-2026-0544 (CVE-2026-85091): its bundled zlib 1.3.2 can overflow a heap buffer in `gz_vacate()` when `gzprintf()` runs after a stalled non-blocking `gzwrite()`. `libz-sys` 1.1.33 bundles zlib 1.4 and fixes it. | Crate | Old | New | Advisory | Pulled in by | | --- | --- | --- | --- | --- | | `libz-sys` | 1.1.31 | 1.1.33 | RUSTSEC-2026-0544 | `libgit2-sys` (git2: `fff-search`, `nu_plugin_gstat`), `curl-sys` (`webpage`: `nu_plugin_query`) | `libz-sys` is transitive, so only `Cargo.lock` changes (`cargo update -p libz-sys --precise 1.1.33`). 1.1.33 has the same dependencies as 1.1.31, and nothing else in the lockfile moves. <!-- Explain what this PR does and why. This section is intentionally flexible: - Describe the problem - Explain your approach - Include technical details if relevant Good examples: - "In this PR, I fixed..." - "In this PR, I added support for..." - "This change improves X by..." Write as much or as little as needed for reviewers to understand your changes. --> ## User-facing changes (Release notes) <!-- This section is used (mostly as-is) for https://www.nushell.sh/blog/ Describe how Nushell behavior changes from a user's perspective. Do NOT describe internal Rust changes here. Write in a release note style, for example: - "Added support for..." - "Fixed an issue where..." - "Nushell now supports..." - "Improved performance of..." If your changes do NOT affect users (internal refactors, cleanup, etc.), just write: - "n/a" - "nan" - or similar This tells us the change should not appear in the changelog. Tips: - Focus on observable behavior - Include examples if helpful - Keep it concise You can: - Write a short paragraph (will appear as a bullet point), OR - Use headings (###) if your change needs more structure Avoid writing things like: - "In this PR, I refactored..." - "This updates internal code..." You may leave this blank until the PR is ready. --> ## Additional notes <!-- Optional. Examples: - fixes #123 - closes #456 - related #789 Anything else reviewers should know. Remove this section if not needed. -->
|
I landed this #19585, need to merge main to get the security fix. |
222e141 to
c1720ca
Compare
|
ping me when you're ready for a review. |
`$env.config.table.striped = true` draws the data rows on alternating backgrounds, inside the borders of the table. Off by default. `color_config.row_stripe` sets the two backgrounds: `bg` for the first row and every other one, `alt` for the rows between. Without `bg`, those rows keep the terminal's background. Without `alt`, it is made from `bg`, or from the terminal's background: white (on a dark background, by WCAG relative luminance) or black (on a light one) is blended into it at `table.stripe_blend`, 0.08 by default. The terminal is asked for its background with an OSC 11 query. The REPL asks before the prompt, the first time and whenever `$env.config` changed, so that no table drawn while the line editor reads the terminal has to; without a line editor it is asked when first needed. Nothing is made from the terminal when it does not answer, and asking is not implemented on Windows. Only the foreground process group can read the reply, so the terminal is not asked while something else holds it, like an external that a hook ran and that is not over yet. It is waited for briefly, then asked at the next prompt. Markup themes and `table --collapse` are not striped.
c1720ca to
6216f78
Compare
|
@fdncred ready to go – I've updated the config as discussed to |
There was a problem hiding this comment.
Review overview
🟡 Changes recommended
The stripes draw right in everything I tried: headers, footers, header_on_separator, wrapped and truncated cells, records, abbreviated_row_count, several themes, and nothing leaks with NO_COLOR. The terminal query needs work. After a config change it eats typed-ahead input and leaves the stripes off. Windows still needs a run in Windows Terminal and in a conhost window before this lands; I didn't run it there.
Findings: 1
Open (6)
Asking the terminal after a config change eats typed-ahead input Any$env.configassignment asks the terminal again Stripes inexplorereplace a cell's own background Zero left padding puts the stripe after the first cell's colortable -estripes every nested table toostripe_blenddoc says anyrow_stripe_bgis blended
Notes from my clanker, checked on 6216f78. Built the branch (debug) and ran each case on it and on main (651f0e4) with nu --no-config-file -c. The typeahead cases ran through a Python pty that answers OSC 11, DA1 and cursor position queries. The trial builds of the pending-input check and the explore widget test were reverted. Clippy and the tests are CI's on this head (all green); I didn't rerun them. Nothing was run on Windows.
6216f78 to
c26f451
Compare
- Put off asking the terminal for its background while typed-ahead input is waiting, so that none of it is lost. - Ask once while stripes are wanted instead of on every change of `$env.config`; turning `table.striped` off and on asks again. - `explore`: keep a cell's own background over the stripe. - `table`: start the stripe before a first cell without left padding. - `table --expand`: stripe the rows of the outer table only. - Reword the `stripe_blend` documentation.
c26f451 to
15bb72a
Compare
|
Thanks for the thorough review. All six are addressed in 15bb72a:
Each of 3, 4 and 5 has a new test. I ran your typed-ahead scenarios against a fake terminal on macOS: one query, the typed line ran, nothing leaked. I have not been able to test on Windows. If you or someone with Windows Terminal can try it, that would be great. |
There was a problem hiding this comment.
Review overview
🟡 Changes recommended
All six threads are fixed on 15bb72a and resolved. Two new problems, both in the terminal query: a table drawn before the first prompt still eats typed-ahead input, and on Windows the new pending check holds the query at every prompt.
Findings: 0
Open (2)
Notes from my clanker, checked on 15bb72a. Built the branch on macOS and reran the pty probes against a fake terminal that answers OSC 11 and DA1, recheck.sh for the table cases, and cargo test -p nu-explore --lib -- stripes (2 passed). On Windows I built 15bb72a with a print of the pending check and ran it over ssh. I didn't try Windows Terminal with a keyboard.
- Windows: look for a key press in the console queue instead of any event, so that the release of the Enter that ended the last line does not put off asking the terminal at every prompt. - Do not ask the terminal for a table drawn before the first prompt, by a config file or `--execute`: keys typed while nu starts were lost.
|
Thanks, both are addressed in ae5c69f:
|
cdfe8fc to
6c4ef56
Compare
|
@fdncred I've removed the automatic BG query from Rust. It's clearer and simpler if a user specifies it in their |
The reply to the query comes in with what is typed, and nothing outside the line editor can tell them apart reliably. Stripes now take their colors from `color_config` only: `row_stripe_alt`, or one blended from a "#rrggbb" `row_stripe_bg`. For stripes that follow the terminal, `std/config` gets `terminal-background` and `terminal-foreground`, which ask with `term query` and return "#rrggbb", or nothing from a terminal that does not report its colors. `doc_config.nu` shows how to set `row_stripe_bg` with it when nushell starts. This removes the `terminal-colorsaurus` dependency and the code at the prompt that went with it.
6c4ef56 to
5709c8a
Compare
|
Is there some other script we need to have to get the "right" contrasting row color once we have the background color or is that baked into the rust code? I haven't looked too deeply yet. |
There was a problem hiding this comment.
Review overview
🟡 Changes recommended
Both open threads were about the Rust terminal query, which 5709c8a removed, so I resolved them. The striping itself checks out on this head. I found six new problems in the std/config commands and docs that replace the query. One is medium: with the doc_config.nu lines, startup waits until Ctrl+C when nothing answers the query. The other five are low.
Findings: 0
Open (6)
Startup waits until Ctrl+C when nothing answers the cursor query On Windows over ssh the cursor reply comes back before the color The fallback color is painted on every other rowrgba:replies come back as nothing With stdout sent to a file, it waits until Ctrl+Cstripe_blenddoc comment still says the terminal background
Notes from my clanker, checked on 5709c8a. I built the branch on macOS and reran the earlier table cases. I ran terminal-background through a fake terminal in a pty: four reply shapes, no OSC 11, no answer at all, stdout sent to a file, and the doc_config.nu lines in config.nu. On Windows I copied the function as is and ran it with that machine's nu, whose term query matches this branch, over ssh against the same fake terminal. I didn't try Windows Terminal. CI is green on this head.
It still uses the WCAG 2 relative luminance from the PR description, so if you don't set the alt colour, it will be chosen for you. I imagine 99% of the usage will just do this, as it looks good. |
|
ok, thanks. just a few more minor things to fixup before we land this. |
- `terminal-background` and `terminal-foreground` return nothing at once when stdin or stdout is not a terminal, instead of waiting for an answer - Read `rgba:` replies as well as `rgb:` - The documented lines set `row_stripe_bg` only when the terminal reports its background, so a fallback color is not painted on the rows - Say where the commands wait until Ctrl+C or get nothing - Bring the doc comment of `stripe_blend` up to date
|
Thanks, all six are addressed in 403d937:
Not tried on Windows or in a real terminal emulator; the checks above ran against a fake terminal on macOS. |
|
Is this right? If I set these $env.config.table.striped = true
$env.config.color_config.row_stripe_bg = "blue"I get blue but the alt is not colored. not sure if that was intended or not |
The alternate color is only made from a "#rrggbb" `row_stripe_bg`.
77e6a2a to
32d26fe
Compare
Yes, that's intended. "blue" is one of the terminal's palette colours, and what it looks like is up to the terminal's theme, so we don't have an RGB value to blend the alternate colour from. The alternate colour is only worked out from a "#rrggbb" row_stripe_bg. With a named colour, you'd have to set row_stripe_alt as well. I updated |
|
Thanks |



Description
In this PR, I added striped rows to
tableandexplore: every other data row gets a different background, which makes wide tables easier to read across.Striping is turned on with
$env.config.table.striped, and its colors come fromcolor_config, as plain colors like the rest of it:row_stripe_bgfor the first row and every other one,row_stripe_altfor the rows between them. When onlyrow_stripe_bgis given, as"#rrggbb", the alternate color is worked out from it: its WCAG 2 relative luminance1 decides whether white or black is laid over it, composited at$env.config.table.stripe_blend(default0.08), so stripes are slightly lighter on a dark background and slightly darker on a light one. With neither color set there are no stripes.For stripes that follow the terminal,
std/configgets two commands,terminal-backgroundandterminal-foreground, in the way ofstd/clip paste52: they ask the terminal withterm queryand return the color as"#rrggbb", or nothing from a terminal that does not report its colors, or when stdin or stdout is not a terminal. The cursor position is asked for after the color, so a terminal that does not report its colors still answers and nothing waits. They are forconfig.nu, once, when nushell starts;doc_config.nuhas the lines for it.In
table, stripes are painted onto the rendered text between the outer borders, which leaves the existing color logic untouched, and the background is put back after any escape sequence in a cell that resets it. Withtable --expand, only the rows of the outer table are striped. Inexplore, the row backgrounds are set on the ratatui buffer, under cells that have no background of their own, and follow the rows while scrolling.User-facing changes (Release notes)
Striped table rows
tableandexplorecan now draw every other row on a different background. It is off by default, and takes a color to make the stripes from:The stripe is a little lighter than a dark
row_stripe_bgand a little darker than a light one.$env.config.table.stripe_blendsets how strong it is, from0.0to1.0(default0.08), or set its color yourself:To take
row_stripe_bgfrom the terminal when nushell starts:terminal-backgroundreturns nothing from a terminal that does not report its background, which leaves tables without stripes. Keys typed before the terminal answers are lost, so this belongs where nushell starts, not at each prompt.terminal-foregroundgives the color of the text the same way.Additional notes
nu-table,nu-explore, the config and its documentation, andstd/config.row_stripe_bgis painted on its rows, so setting it to the terminal's background shows on a terminal with a transparent background or a background image.row_stripe_altalone leaves those rows as they are.table --expandcell, the markdown and reStructuredText themes,table --collapse, and the transposed layout ofexplore.terminal-backgroundandterminal-foregroundhave no automated test, as they need a terminal. They were tried against a fake terminal (one that reports colors, asrgb:orrgba:, with channels of one, two and four digits and either string terminator; one that does not; stdout sent to a file; and no terminal at all), not in a real one.term queryhas no timeout: where nothing answers either query, as in a pty with no terminal behind it, the commands wait until Ctrl+C. Over ssh to Windows they return nothing, as the terminal's color reply does not get through.exploreis covered by widget tests, not run on a live terminal.typoswas not run locally.Footnotes
The brightness of a color as the eye perceives it, from 0 (black) to 1 (white): each sRGB channel is made linear, then they are summed as
0.2126 R + 0.7152 G + 0.0722 B, green counting most. Defined in WCAG 2.2. A background above 0.179, where black and white contrast with it equally, counts as light. ↩