summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core.go12
-rw-r--r--src/util/chars.go5
2 files changed, 14 insertions, 3 deletions
diff --git a/src/core.go b/src/core.go
index 46cd957a..7a762e3c 100644
--- a/src/core.go
+++ b/src/core.go
@@ -126,7 +126,17 @@ func Run(opts *Options) (int, error) {
return false
}
item.text, item.colors = ansiProcessor(stringBytes(transformed))
- item.text.TrimTrailingWhitespaces()
+
+ // We should not trim trailing whitespaces with background colors
+ var maxColorOffset int32
+ if item.colors != nil {
+ for _, ansi := range *item.colors {
+ if ansi.color.bg >= 0 {
+ maxColorOffset = util.Max32(maxColorOffset, ansi.offset[1])
+ }
+ }
+ }
+ item.text.TrimTrailingWhitespaces(int(maxColorOffset))
item.text.Index = itemIndex
item.origText = &data
itemIndex++
diff --git a/src/util/chars.go b/src/util/chars.go
index e5234303..b1a03fa9 100644
--- a/src/util/chars.go
+++ b/src/util/chars.go
@@ -184,9 +184,10 @@ func (chars *Chars) TrailingWhitespaces() int {
return whitespaces
}
-func (chars *Chars) TrimTrailingWhitespaces() {
+func (chars *Chars) TrimTrailingWhitespaces(maxIndex int) {
whitespaces := chars.TrailingWhitespaces()
- chars.slice = chars.slice[0 : len(chars.slice)-whitespaces]
+ end := len(chars.slice) - whitespaces
+ chars.slice = chars.slice[0:Max(end, maxIndex)]
}
func (chars *Chars) TrimSuffix(runes []rune) {