Skip to content

prompt: default prompt colors to the terminal foreground - #1046

Open
iniw wants to merge 1 commit into
nushell:mainfrom
iniw:reset-prompt
Open

prompt: default prompt colors to the terminal foreground#1046
iniw wants to merge 1 commit into
nushell:mainfrom
iniw:reset-prompt

Conversation

@iniw

@iniw iniw commented Apr 8, 2026

Copy link
Copy Markdown

#992 reset stale sgr state before each repaint, which fixed prompt color bleed from previous command output. it did not fix the starship case reported in starship/starship#6560 and nushell/nushell#16384 because reedline still applied its own default prompt colors immediately before printing the prompt.

that meant a prompt implementation that returned ansi text without overriding get_prompt_color() still inherited reedline's defaults. for starship, style = "none" emits no color sequence at all, so the first visible character inherited reedline's green prompt color instead of the terminal's foreground color.

this patch changes the default prompt, multiline, indicator, and right-prompt colors to the terminal defaults. prompts that want explicit colors can still override the color methods, but unstyled prompts now stay unstyled and no longer need an extra reset sequence to avoid the green first character.

@fdncred

fdncred commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

We've covered this in the past. If we set these to none then there are no colors for the prompt at all for reedline users unless you're using something else to color your prompt.

@iniw

iniw commented Apr 8, 2026

Copy link
Copy Markdown
Author

i don't think you're right (but i'm not fully sure either!). AFAIK emitting text without a color (which is the case in this patch) will just default to the terminal's foreground color, right? so the actual color of the prompt will depend on the user's terminal emulator

what i mean is that there will be colors, it just won't be controlled by reedline

@fdncred

fdncred commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

This is what I'm talking about. I really don't want to lose the default coloring in reedline.

Before this PR

image

After this PR

image

@iniw

iniw commented Apr 8, 2026

Copy link
Copy Markdown
Author

i understand where you're coming from but i see it the other way around:

users of reedline (including the examples) should override the get_*_color family of functions in the Prompt trait to achieve their desired styling.
reedline, by default, shouldn't impose a particular style on the prompt. it's too low-level for that.

this is just my personal opinion, of course :)

do you think me making the examples colorful again (by overriding the colors) but keeping the default color-less would be a good middle ground?

@fdncred

fdncred commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

do you think me making the examples colorful again (by overriding the colors) but keeping the default color-less would be a good middle ground?

maybe. i also wonder if we'd need to do this too in nushell when running nu -n

pr nushell#992 reset stale sgr state before each repaint, which fixed prompt
color bleed from previous command output. it did not fix the starship
case reported in starship#6560 and nushell#16384 because reedline still
applied its own default prompt colors immediately before printing the
prompt.

that meant a prompt implementation that returned ansi text without
overriding `get_prompt_color()` still inherited reedline's defaults.
for starship, `style = "none"` emits no color sequence at all, so the
first visible character inherited reedline's green prompt color instead
of the terminal's foreground color.

this patch changes the default prompt, multiline, indicator, and right-prompt
colors to the terminal defaults. prompts that want explicit colors can
still override the color methods, but unstyled prompts now stay
unstyled and no longer need an extra reset sequence to avoid the green
first character.
@iniw

iniw commented Apr 9, 2026

Copy link
Copy Markdown
Author

okay, I've made the DefaultPrompt impl use the old styles. lmk if this is more acceptable now

@fdncred

fdncred commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

I think it's good. Can you look into what changes are needed in nushell to support this?

@iniw

iniw commented Apr 30, 2026

Copy link
Copy Markdown
Author

Can you look into what changes are needed in nushell to support this?

I implemented this for nushell and have conflicting thoughts about it now. The more I wrote the more I thought that this fix was happening in the wrong place. Regardless of whether or not reedline has a default prompt color, nushell will still have one, so this fix by itself ends up being pointless.

What I ended up doing was checking whether or not a custom prompt string was set or not (which is easy since nushell represents these as Option<String> values), but I don't think this is particularly good since it doesn't sound intuitive for the user to have your prompt colors change based on whether or not you have a custom prompt.

After thinking about it for a bit I think this should be fixed on starship's side.

What do you think? I assume you agree, but I'll wait to read your thoughts before closing this and submitting the starship PR.

@fdncred

fdncred commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

I think you should be able to use nushell, oh-my-posh, starship, others to change your prompt and reedline should care that you do that.

@iniw

iniw commented Apr 30, 2026

Copy link
Copy Markdown
Author

So you think it's ok to change the prompt color based on whether you have a custom prompt or not? If that's alright then I'm happy to implement that.

@kronberger-droid kronberger-droid added A-Display Area: Correctness of the display output and additional features needed there A-Prompt Area: Prompt features and styling labels Jun 1, 2026
@kronberger-droid

Copy link
Copy Markdown
Collaborator

Hey there, what's the state on this?
I am not quite sure what you decided while reading through it @fdncred.

My understanding:
the green lives in the trait defaults, so every Prompt impl inherits it invisibly.
NushellPrompt doesn't override the color methods, which is why starship's unstyled text gets painted green.

This PR moves the opinion to the right layer.
The trait default becomes neutral, DefaultPrompt keeps the green, so demos and quickstarts look the same.

In nushell we then just implement the green colors in NushellPrompt to keep our defaults.
But then to fix the bug, we have to override all colors if a prompt is set.
Essentially saying, the prompt is now responsible for coloring.
Otherwise we would reintroduce the same bug one layer up.

What do you think about that?

@fdncred

fdncred commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

@kronberger-droid i'll defer to what you think is appropriate. i just would like to see the same defaults in nushell.

@iniw

iniw commented Jul 6, 2026

Copy link
Copy Markdown
Author

I personally see a few ways forward:

  • Nushell could simply not have a default prompt color and fallback to the terminal emulator's default foreground color.
    This is a breaking change and potentially not very nice for newcomers' first impressions.
  • Nushell could remove the default prompt color if a custom prompt is set.
    This may be unintuitive. A minor modification to the prompt would have major effects on how it looks? Doesn't sound very nice. Perhaps documenting it would be enough. Hard to say.
  • We leave everything as is and instead fix it in starship by forcing it to override the currently active color.

@kronberger-droid

Copy link
Copy Markdown
Collaborator

@iniw
As @fdncred already mentioned twice we don't want to change the default prompt coloring for nushell.

Option 2 is the most sensible to me: Reedline provides clean defaults, nushell impl uses nushell default coloring and the contract for custom prompt is essentially: "You want to customize the prompt, it's all up to you how it looks now."
Which is actually more intuitive than a default prompt being a mixture of the nushell defaults and the configured custom prompt.
Otherwise the starship bug would not be considered a bug, but a feature.

@iniw I can take care of the nushell side if you want. Do you think this PR already reflects that sentiment?

@iniw

iniw commented Jul 6, 2026

Copy link
Copy Markdown
Author

Nice to finally have direction on this :)

@iniw I can take care of the nushell side if you want.

Sounds great to me! I didn't think my solution on the nushell side was good, hence why I never PR'd it.

Do you think this PR already reflects that sentiment?

Yup, I think this PR makes sense.

@kronberger-droid

Copy link
Copy Markdown
Collaborator

Great,while I search for a good solution in nushell I will review this and then land in them in sequence.

@kronberger-droid

Copy link
Copy Markdown
Collaborator

Check out my nushell PR nushell/nushell#18686.
As described we check if a custom prompt is defined, if so it will remove the coloring and it is now fully handled by the custom prompt.

We can either land this one for reedline also, or just keep it. I am fine with both, probably landing it makes it cleaner.
@fdncred what do you think?

@fdncred

fdncred commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

What I don't understand is why we're not using nu_ansi_term for Color. I don't think we should be using any coloring, even crossterm, with nushell or reedline.

@kronberger-droid

Copy link
Copy Markdown
Collaborator

Good point, might be that i just lazily copy how this PR or how the reedline defautl impl did it.
I did this one before my vacation so i don't know exactly right now.
I will take a look at it today.

@kronberger-droid

Copy link
Copy Markdown
Collaborator

Oh sorry, now I see it. The trait is defined really weird.
You are right to question it, but i would investigate it in a follow-up and see if there are any regressions introduced when changing to nu_ansi_term.
You agree, or would you block those, because of it? @fdncred

@fdncred

fdncred commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

I'd block it now. I don't want to introduce non-nu-ansi-term coloring. Maybe that's a mistake? Maybe crossterm colors already exist all over the place? I haven't looked. We specifically forked ansi-term for this purpose that's why I object to it. Hopefully crossterm color hasn't gone too far.

@kronberger-droid

Copy link
Copy Markdown
Collaborator

We did definitely not introduce it.
This was in the Prompt trait before we touched anything.
So definitely an existing problem.
I have it now changed in reedline and will test how it behaves in nushell.
I will post them soon.

@fdncred

fdncred commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Thanks. Glad you're fixing this. Sorry to be a stickler on this. Wish I would've noticed it when it original creeped in.

@kronberger-droid

Copy link
Copy Markdown
Collaborator

All good no problem. Its not that big of a deal to fix now.

@kronberger-droid

Copy link
Copy Markdown
Collaborator

One thing that i noticed is that a non VT console like Windows legacy console would have used a winapi fallback provided by the crossterm::Color. We loose that.
But everything else already does it the same, so it would just have saved a small part of the prompt.
And if someone encounters this problem they can just set use_ansi_coloring: false

kronberger-droid added a commit to kronberger-droid/reedline that referenced this pull request Jul 22, 2026
Covers the SGR bytes emitted for prompt, indicator and right prompt on
both buffer paths: the trait defaults, Color::Default emitting an
explicit SGR 39 (nushell#1046), the use_ansi_coloring guards, and that
crossterm's Green/Cyan were the bright palette entries.
@fdncred

fdncred commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

ok, i'm fine with that. we can land this when you're ready.

kronberger-droid added a commit to kronberger-droid/reedline that referenced this pull request Jul 22, 2026
Covers the SGR bytes emitted for prompt, indicator and right prompt on
both buffer paths: the trait defaults, Color::Default emitting an
explicit SGR 39 (nushell#1046), the use_ansi_coloring guards, and that
crossterm's Green/Cyan were the bright palette entries.
kronberger-droid added a commit that referenced this pull request Jul 22, 2026
…1128)

Prompt's color methods and the reedline::Color re-export now use
nu_ansi_term::Color; the painter writes SGR via Color::prefix() instead
of crossterm's SetForegroundColor.

Defaults become LightGreen/LightCyan. crossterm's Green/Cyan are palette
10/14 (it spells the dark ones DarkGreen/DarkCyan) while nu-ansi-term's
are 2/6, so a name-for-name translation would have darkened the prompt.

Tests pin the emitted SGR bytes on both buffer paths, that Color::Default
emits an explicit SGR 39 (#1046), and that the use_ansi_coloring guards
hold.

BREAKING CHANGE: Prompt::get_prompt_color, get_indicator_color and
get_prompt_right_color now return nu_ansi_term::Color. Implementors porting
crossterm color names need the Light* variants.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Display Area: Correctness of the display output and additional features needed there A-Prompt Area: Prompt features and styling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants