Skip to content

fix: reset ANSI styling before printing prompt#992

Merged
fdncred merged 2 commits into
nushell:mainfrom
majiayu000:fix/ansi-reset-before-prompt
Dec 29, 2025
Merged

fix: reset ANSI styling before printing prompt#992
fdncred merged 2 commits into
nushell:mainfrom
majiayu000:fix/ansi-reset-before-prompt

Conversation

@majiayu000

Copy link
Copy Markdown
Contributor

Summary

Reset any ANSI styling that may have been left by external commands before printing the prompt. This ensures the prompt is not affected by previous output styling that was not properly reset.

Problem

When external commands output text with ANSI styling but don't include a reset sequence, the styling continues to affect the prompt display. This was reported in nushell/nushell#16384.

Solution

Added ANSI reset (SetAttribute(Attribute::Reset) and ResetColor) at the beginning of repaint_buffer() function to ensure any leftover styling is cleared before the prompt is rendered.

Test Plan

  • All existing tests pass
  • Manual testing: run commands that output styled text without reset, verify prompt displays correctly

Fixes nushell/nushell#16384

Reset any ANSI styling that may have been left by external commands
before printing the prompt. This ensures the prompt is not affected
by previous output styling that was not properly reset.

Fixes nushell/nushell#16384

Signed-off-by: majiayu000 <1835304752@qq.com>
Comment thread src/painting/painter.rs Outdated
@majiayu000

Copy link
Copy Markdown
Contributor Author

You're right, removed. SGR 0 resets everything including colors.

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

Seems to work better for me. Thanks

@Ecorous Ecorous left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good!

@fdncred
fdncred merged commit 4cce77d into nushell:main Dec 29, 2025
6 checks passed
@fdncred

fdncred commented Dec 29, 2025

Copy link
Copy Markdown
Contributor

Thanks!

@majiayu000
majiayu000 deleted the fix/ansi-reset-before-prompt branch December 29, 2025 17:34
iniw added a commit to iniw/reedline that referenced this pull request Apr 8, 2026
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.

change 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 added a commit to iniw/reedline that referenced this pull request Apr 8, 2026
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.
kronberger-droid pushed a commit to skull-squadron/reedline that referenced this pull request Jun 1, 2026
* fix: reset ANSI styling before printing prompt

Reset any ANSI styling that may have been left by external commands
before printing the prompt. This ensures the prompt is not affected
by previous output styling that was not properly reset.

Fixes nushell/nushell#16384

Signed-off-by: majiayu000 <1835304752@qq.com>

* refactor: remove redundant ResetColor since SGR 0 resets all

---------

Signed-off-by: majiayu000 <1835304752@qq.com>
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

4 participants