Skip to content

Add striped rows to table and explore - #19575

Merged
fdncred merged 6 commits into
nushell:mainfrom
stuartcarnie:table_row_striping
Nov 22, 2026
Merged

fdncred merged 6 commits into
nushell:mainfrom
stuartcarnie:table_row_striping

Conversation

@stuartcarnie

@stuartcarnie stuartcarnie commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Description

In this PR, I added striped rows to table and explore: 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 from color_config, as plain colors like the rest of it: row_stripe_bg for the first row and every other one, row_stripe_alt for the rows between them. When only row_stripe_bg is 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 (default 0.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/config gets two commands, terminal-background and terminal-foreground, in the way of std/clip paste52: they ask the terminal with term query and 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 for config.nu, once, when nushell starts; doc_config.nu has 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. With table --expand, only the rows of the outer table are striped. In explore, 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

table and explore can now draw every other row on a different background. It is off by default, and takes a color to make the stripes from:

$env.config.table.striped = true
$env.config.color_config.row_stripe_bg = "#282c34"   # the background of your terminal

The stripe is a little lighter than a dark row_stripe_bg and a little darker than a light one. $env.config.table.stripe_blend sets how strong it is, from 0.0 to 1.0 (default 0.08), or set its color yourself:

$env.config.color_config.row_stripe_alt = "#393d44"  # the rows between

To take row_stripe_bg from the terminal when nushell starts:

use std/config terminal-background
if $nu.is-interactive and $env.config.table.striped {
    let background = terminal-background
    if $background != null { $env.config.color_config.row_stripe_bg = $background }
}

terminal-background returns 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-foreground gives the color of the text the same way.

Additional notes

  • No new dependency, and nothing that differs between platforms: the PR touches nu-table, nu-explore, the config and its documentation, and std/config.
  • row_stripe_bg is 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_alt alone leaves those rows as they are.
  • Not striped: tables nested in a table --expand cell, the markdown and reStructuredText themes, table --collapse, and the transposed layout of explore.
  • terminal-background and terminal-foreground have no automated test, as they need a terminal. They were tried against a fake terminal (one that reports colors, as rgb: or rgba:, 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 query has 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. explore is covered by widget tests, not run on a live terminal. typos was not run locally.

Footnotes

  1. 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. ↩

@github-actions

Copy link
Copy Markdown

Hey, just a bot checking in! You edited files related to the configuration.
If you changed any of the default values or added a new config option, don't forget to update the doc_config.nu which documents the options for our users including the defaults provided by the Rust implementation.
If you didn't make a change here, you can just ignore me.

@fdncred

fdncred commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

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:

$env.config.color_config.row_stripe = { bg: "#282c34", alt: "#393d44" }

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.

@stuartcarnie

Copy link
Copy Markdown
Contributor Author

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.

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.

I also am not a fan of this:

$env.config.color_config.row_stripe = { bg: "#282c34", alt: "#393d44" }

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.

Fair – so the only values for properties under color_config are colour values. I'd rather not break convention either.

@fdncred

fdncred commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Ooh, microsoft/terminal#17729 says Windows can respond to OSC 11!

ok, good.

Fair – so the only values for properties under color_config are colour values.

Maybe have a $env.config.color_config.row_stripe_bg = "#282c34" and a $env.config.color_config.row_stripe_alt = "#393d44" so we don't invent yet another way to parse colors.

I'll also look at the security audit finding.

fdncred added a commit that referenced this pull request Nov 17, 2026
<!--
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.
-->
@fdncred

fdncred commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

I landed this #19585, need to merge main to get the security fix.

@fdncred

fdncred commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

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.
@stuartcarnie

Copy link
Copy Markdown
Contributor Author

@fdncred ready to go – I've updated the config as discussed to row_stripe_(bg|alt)

@fdncred fdncred left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 High severity · 0 Medium severity · 5 Low severity

Open (6)

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.

Comment thread crates/nu-cli/src/repl.rs Resolved
Comment thread crates/nu-cli/src/repl.rs Resolved
Comment thread crates/nu-table/src/table.rs Resolved
Comment thread crates/nu-table/src/common.rs Resolved
- 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.
@stuartcarnie

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review. All six are addressed in 15bb72a:

  1. Typed-ahead input eaten: the query is now skipped while input is waiting and asked at a later prompt. The pending check runs in raw mode, as you suggested, so a line not yet ended with Enter counts too.
  2. Every $env.config assignment re-asks: I went a bit further than suggested. The terminal is asked once and the answer is kept while stripes are wanted. To ask again after the terminal's colors change, set table.striped to false, then to true at the next prompt. This is in doc_config.nu.
  3. explore replaces a cell's own background: the stripe is only set on cells that have no background of their own.
  4. Zero left padding: the stripe now starts right after the left border, before the first cell's color.
  5. table -e nested tables: only the rows of the outer table are striped.
  6. stripe_blend doc: your wording applied.

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.

@fdncred fdncred left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 High severity · 2 Medium severity · 0 Low severity

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.

Comment thread crates/nu-cli/src/repl.rs Resolved
- 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.
@stuartcarnie

Copy link
Copy Markdown
Contributor Author

Thanks, both are addressed in ae5c69f:

  1. Windows pending check: on Windows the console queue is now looked at with PeekConsoleInputW and only a key press counts, as you suggested. Other platforms keep the raw-mode check. I have no Windows machine: it compiles in CI (the Windows lint job passes), but it has not been run. Could you try it again over ssh, and in Windows Terminal with a keyboard if you get the chance?
  2. Table drawn before the first prompt: run_repl now holds the query before setup_config, so only the prompt asks, behind the pending check. A table that a config file or --execute draws gets no automatic stripe; a row_stripe_alt still works there. I reran your scenario on the fake terminal (table in the startup command, line typed while nu starts), 3 of 3: one query, the typed line ran, later tables striped.

@stuartcarnie

stuartcarnie commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

@fdncred I've removed the automatic BG query from Rust. It's clearer and simpler if a user specifies it in their config.nu. It still derives the alt colour from the bg, when alt is unspecified.

Comment thread crates/nu-std/std/config/mod.nu Resolved
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.
@fdncred

fdncred commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

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.

@fdncred fdncred left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 High severity · 1 Medium severity · 5 Low severity

Open (6)

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.

Comment thread crates/nu-std/std/config/mod.nu Resolved
Comment thread crates/nu-std/std/config/mod.nu Resolved
Comment thread crates/nu-std/std/config/mod.nu Resolved
Comment thread crates/nu-std/std/config/mod.nu Resolved
Comment thread crates/nu-protocol/src/config/table.rs Resolved
@stuartcarnie

Copy link
Copy Markdown
Contributor Author

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.

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.

@fdncred

fdncred commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

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
@stuartcarnie

Copy link
Copy Markdown
Contributor Author

Thanks, all six are addressed in 403d937:

  1. Wait until Ctrl+C when nothing answers: kept this PR to std/config and said so in the docs of both commands and in doc_config.nu. A timeout on term query would be the real fix, as a change of its own.
  2. Windows over ssh: the docs now say nothing comes back there.
  3. Fallback color painted on the rows: the doc_config.nu lines and the @example now set row_stripe_bg only when a color comes back, so a terminal that does not report gets no stripes.
  4. rgba: replies: took the suggestion. Through a fake terminal, rgba:2828/2c2c/3434/ffff now gives #282c34.
  5. stdout sent to a file: took the is-terminal check. nu -c "use std/config terminal-background; terminal-background | to nuon" > out.txt returns at once and the file holds only null.
  6. stripe_blend doc comment: took the suggestion.

Not tried on Windows or in a real terminal emulator; the checks above ran against a fake terminal on macOS.

@fdncred

fdncred commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

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`.
@stuartcarnie

Copy link
Copy Markdown
Contributor Author

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

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 doc_config.nu to make it clearer:

@fdncred fdncred added notes:ready Indicates Ready for Release notes notes:additions Noted in "Additions" section labels Nov 22, 2026
@fdncred
fdncred merged commit 86d3396 into nushell:main Nov 22, 2026
15 checks passed
@fdncred

fdncred commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Thanks

@github-actions github-actions Bot added this to the v0.118.0 milestone Nov 22, 2026
@stuartcarnie
stuartcarnie deleted the table_row_striping branch November 23, 2026 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:additions Noted in "Additions" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants