diff --git a/test/themes/powerline.base.bats b/test/themes/powerline.base.bats new file mode 100644 index 0000000000..210ad39461 --- /dev/null +++ b/test/themes/powerline.base.bats @@ -0,0 +1,32 @@ +# shellcheck shell=bats +# shellcheck disable=SC2034 # Variables consumed by externally-loaded powerline functions. + +load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" + +function local_setup_file() { + setup_libs "colors" + 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 outputs missing-newline escape sequence to stdout" { + POWERLINE_PROMPT=("noop") + run __powerline_prompt_command + assert_output --partial $'\e[7m%\e[0m\r\e[K' +} + +@test "powerline base: __powerline_prompt_command missing-newline sequence is first output" { + POWERLINE_PROMPT=("noop") + run __powerline_prompt_command + # Use bash pattern match to confirm the sequence appears at the very start, + # meaning it is a direct printf rather than anything embedded in PS1 or segments. + local prefix=$'\e[7m%\e[0m\r\e[K' + [[ "${output}" == "${prefix}"* ]] +} diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index 85ba0dce93..75e8886eac 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -290,6 +290,10 @@ function __powerline_prompt_command() { local beginning_of_line='\[\e[G\]' local info prompt_color segment prompt + # Reversed % marks where a missing trailing newline was; \r\e[K then + # clears the line so the prompt always starts cleanly at column 1. + printf '%b' '\e[7m%\e[0m\r\e[K' + local LEFT_PROMPT="" local SEGMENTS_AT_LEFT=0 local LAST_SEGMENT_COLOR=""