Skip to content

fix(prompt): don't tint a supplied prompt with the default colors - #18686

Merged
kronberger-droid merged 2 commits into
nushell:mainfrom
kronberger-droid:fix-custom-prompt-color-reset
Nov 14, 2026
Merged

kronberger-droid merged 2 commits into
nushell:mainfrom
kronberger-droid:fix-custom-prompt-color-reset

Conversation

@kronberger-droid

@kronberger-droid kronberger-droid commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Description

reedline prints a foreground color in front of the left and the right prompt, and NushellPrompt never overrode it.
Thus every unstyled piece of a custom prompt, like a starship module with style = "none", came out light green or purple instead of in the terminal's own foreground.

NushellPrompt now answers Color::Default for a side that was supplied, and keeps reedline's colors for a side that falls back to the built-in prompt.
The two sides are judged separately.

The indicators keep their default colors.
They are nushell's own rather than the prompt generator's, and styling one means putting the escapes into the indicator value.

User-facing changes (Release notes)

Fixed unstyled text in a custom prompt being tinted light green (left) or purple (right).
It now uses the terminal's default foreground, as in other shells.
A prompt that sets its own colors looks the same as before.

Additional notes

fixes #16384

Based on main, since the PromptState rewrite it needed is already there.
It conflicts with #18734 in one hunk, both append tests to crates/nu-cli/src/prompt.rs, so whichever lands second needs that merge.

Comment thread crates/nu-cli/src/prompt.rs Outdated
@@ -1,3 +1,4 @@
use crossterm::style::Color;

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.

Is there a reason we're not using nu_ansi_term here? All coloring in nushell and reedline should be nu_ansi_term iirc.

@kronberger-droid

kronberger-droid commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor Author

@fdncred

Wow the prompt indicator situation is a mess. It seems it was made pretty early and was never updated.
It essentially when entering the REPL define the indicators as env variables.
Then every render the env var is read.
There is no way to define it in config, and some overrides which never fire, etc...

Is there any reason why these would be plain env variables and not handled by the config?

Without changing this we can only use the default color easily for everything but the prompt indicator, which would be white, since it will be handled as customized.

Should I try to clean this up in here, or in a follow-up?
And are you fine with removing the env variable for configuration?
I have not found any justification for it, it seems it was because the config could not do Hooks at the time.

@fdncred

fdncred commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Is there any reason why these would be plain env variables and not handled by the config?

I'm not sure really. They've just always been that way.

Should I try to clean this up in here, or in a follow-up?

Probably separate but before we land this one.

And are you fine with removing the env variable for configuration?

We should probably talk about it, maybe in our meeting today. It'll be a breaking change though. Seems like it should be part of the config.nu to me too.

@kronberger-droid

Copy link
Copy Markdown
Contributor Author

Sure lets talk tonight.

@fdncred

fdncred commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Also worth nothing, the entire config is in $env so I'm not sure if there's a ton of difference between $env.config.PROMPT_INDICATOR and $env.PROMPT_INDICATOR.

@kronberger-droid kronberger-droid changed the title fix: don't thint unstyled prompts with default colors fix: don't tint unstyled prompts with default colors Jul 22, 2026
@kronberger-droid
kronberger-droid force-pushed the fix-custom-prompt-color-reset branch from 1cc2a5d to 46226e4 Compare July 25, 2026 16:17
NushellPrompt forced nushell's default foregrounds on every prompt
piece, so an unstyled custom prompt, like starship with `style = ""`,
inherited them instead of the terminal foreground. The left and right
prompt now return `Color::Default` when the user supplies them, and
keep the built-in color only for the fallbacks.

The indicators stay tinted. They are nushell's own rather than output
of the user's prompt generator, since reedline picks one from the
current edit mode, which `$env.PROMPT_COMMAND` cannot see. Styling one
means putting the escapes in the indicator value.

Their colors are stated explicitly rather than inherited from the
`Prompt` trait defaults, so nushell's appearance does not follow
reedline's. The constants come from reedline's `DEFAULT_*` statics,
since the prompt colors moved to `nu_ansi_term::Color` there in
83c17a2.

Fixes nushell#16384
@kronberger-droid
kronberger-droid force-pushed the fix-custom-prompt-color-reset branch from 46226e4 to 15742cb Compare July 26, 2026 12:56
@kronberger-droid
kronberger-droid marked this pull request as ready for review August 7, 2026 10:38
@fdncred

fdncred commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

I don't remember what we decided here? Or maybe this PR is dependent on the prompt indicators PR?

@kronberger-droid

Copy link
Copy Markdown
Contributor Author

Yeah exactly. We decided to first land the prompt PR. And then land this one, with default colors, with no custom prompt and with custom prompt we just do a color reset.

…olor-reset

`NushellPrompt` no longer owns its segments since nushell#19236, thus the
colors ask the shared `PromptState` whether a side was supplied.
@kronberger-droid kronberger-droid changed the title fix: don't tint unstyled prompts with default colors fix(prompt): don't tint a supplied prompt with the default colors Nov 13, 2026
@kronberger-droid
kronberger-droid merged commit f861a79 into nushell:main Nov 14, 2026
14 checks passed
@kronberger-droid
kronberger-droid deleted the fix-custom-prompt-color-reset branch November 14, 2026 12:59
@github-actions github-actions Bot added this to the v0.118.0 milestone Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Text has ANSI styling (no reset) before prompt is printed

2 participants