Skip to content

Commit a8fc274

Browse files
committed
Improved quality of newline flag
1 parent ffce7ba commit a8fc274

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

powerline.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,48 @@ func (p *powerline) draw() string {
8383
buffer.WriteString(segment.separator)
8484
buffer.WriteString(p.reset)
8585
}
86-
buffer.WriteString(" ")
86+
buffer.WriteRune(' ')
8787

8888
drawnResult := buffer.String()
8989
if *p.args.EastAsianWidth {
90+
var spaceBuffer bytes.Buffer
9091
for _, r := range drawnResult {
9192
switch width.LookupRune(r).Kind() {
9293
case width.Neutral:
9394
case width.EastAsianAmbiguous:
94-
drawnResult += " "
95+
spaceBuffer.WriteRune(' ')
9596
case width.EastAsianWide:
9697
case width.EastAsianNarrow:
9798
case width.EastAsianFullwidth:
9899
case width.EastAsianHalfwidth:
99100
}
100101
}
102+
drawnResult += spaceBuffer.String()
101103
}
102104

103105
if *p.args.PromptOnNewLine {
104-
drawnResult += "\n"
106+
var nextLineBuffer bytes.Buffer
107+
nextLineBuffer.WriteRune('\n')
108+
109+
var foreground, background uint8
110+
if *p.args.PrevError == 0 {
111+
foreground = p.theme.CmdPassedFg
112+
background = p.theme.CmdPassedBg
113+
} else {
114+
foreground = p.theme.CmdFailedFg
115+
background = p.theme.CmdFailedBg
116+
}
117+
118+
nextLineBuffer.WriteString(p.fgColor(foreground))
119+
nextLineBuffer.WriteString(p.bgColor(background))
120+
nextLineBuffer.WriteString(p.shellInfo.rootIndicator)
121+
nextLineBuffer.WriteString(p.reset)
122+
nextLineBuffer.WriteString(p.fgColor(background))
123+
nextLineBuffer.WriteString(p.symbolTemplates.Separator)
124+
nextLineBuffer.WriteString(p.reset)
125+
nextLineBuffer.WriteRune(' ')
126+
127+
drawnResult += nextLineBuffer.String()
105128
}
106129

107130
return drawnResult

0 commit comments

Comments
 (0)