Skip to content

fix(config): let the prompt indicators take a closure again - #19612

Merged
kronberger-droid merged 3 commits into
nushell:mainfrom
kronberger-droid:indicator-closures
Nov 22, 2026
Merged

kronberger-droid merged 3 commits into
nushell:mainfrom
kronberger-droid:indicator-closures

Conversation

@kronberger-droid

Copy link
Copy Markdown
Contributor

Description

#18734 moved the prompt into $env.config.prompt, but the indicator keys only took a string.
$env.PROMPT_INDICATOR and the other indicator variables always took a closure too, thus migrating an indicator that changes with $env.LAST_EXIT_CODE to the new keys was not possible.

This was never a decision.
The indicators moved first, typed as String, before left and right joined the PR.
When those followed it turned out config can hold closures after all (Hooks already does), but the indicator keys were never widened.

The indicators now go through the same path as left and right:

  • config: the transient keys parse with update_prompt_source, the live keys with an update_indicator that differs only by rejecting null, since every edit mode draws an indicator.
  • resolution: every segment resolves through resolve_prompt_source, vi_visual (no variable) through render directly.
  • removed: update_optional_string, resolve_indicator and resolve_transient_indicator, which only existed to carry the narrower type.

A closure that fails to render reports its error and falls back to the built-in indicator.
input --reedline renders the keys the same way.

Scrutinize: crates/nu-cli/src/prompt_update.rs, the evaluation order of the segments is kept since any of them may have side effects now.
Skim: the test updates in crates/nu-protocol/src/config/prompt.rs, mostly "x".into() to Value::test_string("x").

Tests: nu-protocol config::prompt 15/15, nu-cli prompt 28/28 including a new configured_indicators_accept_closures that parses and renders real closures, nu-command reedline_prompt 1/1.
Clippy with CI flags clean on the touched crates.

User-facing changes (Release notes)

$env.config.prompt.indicator, vi_insert, vi_normal, vi_visual and multiline, plus their transient counterparts, now accept a closure as well as a string, the same as $env.PROMPT_INDICATOR and friends always did.

$env.config.prompt.indicator = {||
    if $env.LAST_EXIT_CODE == 0 { "> " } else { $"(ansi red)> (ansi reset)" }
}

Additional notes

Follow-up to #18734.

AI:W WRITE

The indicator keys in `$env.config.prompt` were typed as strings since
nushell#18734 moved them before `left` and `right`, when config was not yet
thought to hold closures. Moving `left` and `right` later showed it
can, but the indicators kept their type, thus `$env.PROMPT_INDICATOR`
and friends took a closure while the keys replacing them did not. An
indicator colored by the last exit code had no way across.

A live indicator still rejects `null`, since every edit mode draws one.
A closure that fails to render falls back to the built-in indicator.

`input --reedline` evaluates the keys too, so a closure works there as
well.
@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.

@kronberger-droid
kronberger-droid marked this pull request as ready for review November 20, 2026 00:15

@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 closure keys work in the REPL. An exit-code indicator flips to ERR> after ^false and back, a failing closure reports its error and falls back to > , and a transient closure replaces the live indicator. What's left is in input --reedline and one test gap.

Findings: 0 High severity · 0 Medium severity · 3 Low severity

Open (3)

Notes from my clanker, checked on e6a9872. Built the branch and ran each case in a real REPL under a pty, on the branch binary and on main (651f0e4): closure indicators, a failing closure, a transient closure, and input --reedline with vi and multiline closures. CI's root and lint jobs already ran the workspace tests, fmt and clippy on this head, and typos passed, so I didn't rerun them.

Comment thread crates/nu-cli/src/prompt_update.rs Resolved
@kronberger-droid
kronberger-droid merged commit 3b03653 into nushell:main Nov 22, 2026
15 checks passed
@github-actions github-actions Bot added this to the v0.118.0 milestone Nov 22, 2026
@fdncred fdncred added notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants