diff --git a/test/themes/powerline.base.bats b/test/themes/powerline.base.bats index a64540176e..444259ad70 100644 --- a/test/themes/powerline.base.bats +++ b/test/themes/powerline.base.bats @@ -8,6 +8,46 @@ function local_setup_file() { load "${BASH_IT?}/themes/powerline/powerline.base.bash" } +# Stub a no-op segment so we can run __powerline_prompt_command without +# sourcing every plugin that the default segments depend on. +function __powerline_noop_prompt() { :; } +# _save-and-reload-history is called unconditionally; stub it out. +function _save-and-reload-history() { :; } + +# --- __powerline_prompt_command: missing-newline handler (fixes #2372) --- + +@test "powerline base: __powerline_prompt_command overflows the line and returns to column 1" { + COLUMNS=20 + POWERLINE_PROMPT=("noop") + run __powerline_prompt_command + + local expected + expected="$(printf '%*s\r' "$((COLUMNS - 1))" '')" + assert_output --partial "${expected}" +} + +@test "powerline base: __powerline_prompt_command missing-newline sequence is first output" { + COLUMNS=20 + POWERLINE_PROMPT=("noop") + run __powerline_prompt_command + + # Confirm the padding+carriage-return appears at the very start, meaning it + # is a direct printf rather than anything embedded in PS1 or segments. + local prefix + prefix="$(printf '%*s\r' "$((COLUMNS - 1))" '')" + [[ "${output}" == "${prefix}"* ]] +} + +@test "powerline base: __powerline_prompt_command falls back to 80 columns when COLUMNS is unset" { + unset COLUMNS + POWERLINE_PROMPT=("noop") + run __powerline_prompt_command + + local expected + expected="$(printf '%*s\r' 79 '')" + assert_output --partial "${expected}" +} + function local_setup() { LEFT_PROMPT="" SEGMENTS_AT_LEFT=0 diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index bcf9bc1b9c..2a1fe51cfb 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -289,6 +289,11 @@ function __powerline_prompt_command() { local last_status="$?" ## always the first local info prompt_color segment prompt + # If the previous command left output without a trailing newline, overflow + # the rest of the line with spaces so the terminal auto-wraps the cursor + # onto a fresh line before the prompt is drawn (mirrors zsh's PROMPT_SP). + printf '%*s\r' "$((${COLUMNS:-80} - 1))" '' + local LEFT_PROMPT="" local SEGMENTS_AT_LEFT=0 local LAST_SEGMENT_COLOR=""