Skip to content

Commit 8270959

Browse files
authored
Merge pull request #2385 from seefood/fix/2372-powerline-missing-newline
fix(themes/powerline): ensure prompt starts on a new line
2 parents 7f9621e + a654eb8 commit 8270959

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

test/themes/powerline.base.bats

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,46 @@ function local_setup_file() {
88
load "${BASH_IT?}/themes/powerline/powerline.base.bash"
99
}
1010

11+
# Stub a no-op segment so we can run __powerline_prompt_command without
12+
# sourcing every plugin that the default segments depend on.
13+
function __powerline_noop_prompt() { :; }
14+
# _save-and-reload-history is called unconditionally; stub it out.
15+
function _save-and-reload-history() { :; }
16+
17+
# --- __powerline_prompt_command: missing-newline handler (fixes #2372) ---
18+
19+
@test "powerline base: __powerline_prompt_command overflows the line and returns to column 1" {
20+
COLUMNS=20
21+
POWERLINE_PROMPT=("noop")
22+
run __powerline_prompt_command
23+
24+
local expected
25+
expected="$(printf '%*s\r' "$((COLUMNS - 1))" '')"
26+
assert_output --partial "${expected}"
27+
}
28+
29+
@test "powerline base: __powerline_prompt_command missing-newline sequence is first output" {
30+
COLUMNS=20
31+
POWERLINE_PROMPT=("noop")
32+
run __powerline_prompt_command
33+
34+
# Confirm the padding+carriage-return appears at the very start, meaning it
35+
# is a direct printf rather than anything embedded in PS1 or segments.
36+
local prefix
37+
prefix="$(printf '%*s\r' "$((COLUMNS - 1))" '')"
38+
[[ "${output}" == "${prefix}"* ]]
39+
}
40+
41+
@test "powerline base: __powerline_prompt_command falls back to 80 columns when COLUMNS is unset" {
42+
unset COLUMNS
43+
POWERLINE_PROMPT=("noop")
44+
run __powerline_prompt_command
45+
46+
local expected
47+
expected="$(printf '%*s\r' 79 '')"
48+
assert_output --partial "${expected}"
49+
}
50+
1151
function local_setup() {
1252
LEFT_PROMPT=""
1353
SEGMENTS_AT_LEFT=0

themes/powerline/powerline.base.bash

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,11 @@ function __powerline_prompt_command() {
289289
local last_status="$?" ## always the first
290290
local info prompt_color segment prompt
291291

292+
# If the previous command left output without a trailing newline, overflow
293+
# the rest of the line with spaces so the terminal auto-wraps the cursor
294+
# onto a fresh line before the prompt is drawn (mirrors zsh's PROMPT_SP).
295+
printf '%*s\r' "$((${COLUMNS:-80} - 1))" ''
296+
292297
local LEFT_PROMPT=""
293298
local SEGMENTS_AT_LEFT=0
294299
local LAST_SEGMENT_COLOR=""

0 commit comments

Comments
 (0)