Skip to content

fix(themes/powerline): ensure prompt starts on a new line#2385

Open
seefood wants to merge 5 commits into
Bash-it:masterfrom
seefood:fix/2372-powerline-missing-newline
Open

fix(themes/powerline): ensure prompt starts on a new line#2385
seefood wants to merge 5 commits into
Bash-it:masterfrom
seefood:fix/2372-powerline-missing-newline

Conversation

@seefood

@seefood seefood commented Apr 18, 2026

Copy link
Copy Markdown
Contributor

Summary

When a command produces output without a trailing newline (e.g. echo -n foo), the existing \e[G (move to column 1) in PS1 overwrites that output with the prompt. This adds a missing-newline handler at the top of __powerline_prompt_command:

printf '%b' '\e[7m%\e[0m\r\e[K'

How it works:

  • \e[7m%\e[0m — prints a reversed-video % at the current cursor position. If the previous command left the cursor mid-line, this character is briefly visible as a "missing newline" indicator (same convention as zsh's PROMPT_SP)
  • \r — carriage return to column 1 of the current line
  • \e[K — clear from column 1 to end of line

Result:

  • Previous command ended with newline: cursor was already at column 1 on a blank line → % is printed and immediately cleared → no visible change
  • Previous command had no trailing newline: % appears at the end of the partial output, then \r\e[K clears the entire line → prompt renders cleanly on what is now an empty line

The existing \e[G in PS1 is kept as-is (it becomes a harmless no-op since we are already at column 1 after the printf).

Note: powerline-multiline uses \e[B (cursor down) instead of \e[G and has different behaviour; that theme is out of scope for this fix.

Test plan

  • echo -n foo — verify % appears briefly then prompt renders on a clean new line, foo is not overwritten
  • Normal commands (echo foo, ls) — verify no extra blank line is inserted
  • Works in powerline, powerline-plain, and powerline-naked (plain and naked inherit __powerline_prompt_command from base)

Fixes #2372

🤖 Generated with Claude Code

seefood and others added 4 commits April 18, 2026 18:42
When a command's output has no trailing newline, \e[G (column 1) in PS1
would overwrite that output with the prompt. Add a missing-newline
indicator in PROMPT_COMMAND: reversed-video % marks the incomplete line,
then \r\e[K moves to column 1 and clears it, so the prompt always
renders cleanly regardless of the previous command's output.

Fixes Bash-it#2372

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Verifies that __powerline_prompt_command:
- outputs the \e[7m%\e[0m\r\e[K sequence to stdout
- outputs it as the very first bytes (before segment/PS1 content)

Uses a no-op stub segment and a _save-and-reload-history stub to avoid
pulling in every plugin that the default segments depend on.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace the reversed-% + \e[K approach (which cleared the previous
command's unterminated output instead of preserving it) with the fix
suggested by @joshiste in Bash-it#2372: pad the current line with COLUMNS-1
spaces so the terminal auto-wraps the cursor to a fresh line, then
carriage-return to column 1. This preserves any partial output from
the previous command instead of erasing it.

The \e[G reset in PS1 is now redundant since the cursor is already at
column 1 by the time PS1 is rendered, so beginning_of_line is removed.

Fixes Bash-it#2372
@seefood

seefood commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Updated the implementation based on the feedback in #2372: the reversed-% + \e[K approach cleared the previous command's unterminated output instead of preserving it (as joshiste reported).

Replaced it with the approach joshiste suggested: overflow the current line with COLUMNS-1 spaces so the terminal auto-wraps the cursor onto a fresh line, then \r to column 1. This preserves any partial output from the previous command instead of erasing it. beginning_of_line (\e[G) is now redundant since the cursor is already at column 1 by the time PS1 is rendered, so it was removed.

Tests updated accordingly (test/themes/powerline.base.bats), including a fallback check for when COLUMNS is unset.

…missing-newline

* origin/master:
  Fix get_default_branch function
  fix(themes/powerline): remove erroneous \e[G from PS1
  test(themes/powerline): suppress SC2034 for externally-consumed variables
  test(themes/powerline): add BATS tests for POWERLINE_PROMPT_FOREGROUND_COLOR
  fix(themes/powerline): restore POWERLINE_PROMPT_FOREGROUND_COLOR support

# Conflicts:
#	test/themes/powerline.base.bats
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.

[Bug]: Powerline overwrites output of last command when it doesn't end with newline

1 participant