Skip to content

Commit

Permalink
Import runewidth and use it instead of len(), to fix utf8 problems.
Browse files Browse the repository at this point in the history
  • Loading branch information
james-antill committed Oct 16, 2017
1 parent c2b1fd2 commit 3dec992
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions powerline.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"strings"

"github.com/mattn/go-runewidth"
"golang.org/x/crypto/ssh/terminal"
"golang.org/x/text/width"
"os"
Expand Down Expand Up @@ -102,8 +103,10 @@ func (p *powerline) draw() string {

shellActualLength := 0
if shellMaxLength > 0 {
rlen := runewidth.StringWidth

for _, segment := range p.Segments {
shellActualLength += len(segment.content) + len(segment.separator)
shellActualLength += rlen(segment.content) + rlen(segment.separator)
}
for shellActualLength > shellMaxLength {
minPriority := MaxInteger
Expand All @@ -117,7 +120,7 @@ func (p *powerline) draw() string {
if minPrioritySegmentId != -1 {
segment := p.Segments[minPrioritySegmentId]
p.Segments = append(p.Segments[:minPrioritySegmentId], p.Segments[minPrioritySegmentId+1:]...)
shellActualLength -= len(segment.content) + len(segment.separator)
shellActualLength -= rlen(segment.content) + rlen(segment.separator)
}
}
}
Expand Down

0 comments on commit 3dec992

Please sign in to comment.