Repository navigation
fix(config): let the prompt indicators take a closure again - #19612
Conversation
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.
|
Hey, just a bot checking in! You edited files related to the configuration. |
There was a problem hiding this comment.
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
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.



Description
#18734 moved the prompt into
$env.config.prompt, but the indicator keys only took a string.$env.PROMPT_INDICATORand the other indicator variables always took a closure too, thus migrating an indicator that changes with$env.LAST_EXIT_CODEto the new keys was not possible.This was never a decision.
The indicators moved first, typed as
String, beforeleftandrightjoined the PR.When those followed it turned out config can hold closures after all (
Hooksalready does), but the indicator keys were never widened.The indicators now go through the same path as
leftandright:update_prompt_source, the live keys with anupdate_indicatorthat differs only by rejectingnull, since every edit mode draws an indicator.resolve_prompt_source,vi_visual(no variable) throughrenderdirectly.update_optional_string,resolve_indicatorandresolve_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 --reedlinerenders 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()toValue::test_string("x").Tests:
nu-protocolconfig::prompt15/15,nu-cliprompt28/28 including a newconfigured_indicators_accept_closuresthat parses and renders real closures,nu-commandreedline_prompt1/1.Clippy with CI flags clean on the touched crates.
User-facing changes (Release notes)
$env.config.prompt.indicator,vi_insert,vi_normal,vi_visualandmultiline, plus theirtransientcounterparts, now accept a closure as well as a string, the same as$env.PROMPT_INDICATORand friends always did.Additional notes
Follow-up to #18734.