Skip to content

Commit

Permalink
if pos < w: add empty chars
Browse files Browse the repository at this point in the history
  • Loading branch information
tty2 committed Sep 16, 2022
1 parent 669734a commit b18c354
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion runewidth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package runewidth

import (
"os"
"strings"

"github.com/rivo/uniseg"
)
Expand Down Expand Up @@ -233,7 +234,12 @@ func (c *Condition) TrimPrefix(s string, w int, prefix string) string {
}
}
if width+chWidth > w {
pos, _ = g.Positions()
if width < w {
_, pos = g.Positions()
prefix += strings.Repeat(" ", w-width)
} else {
pos, _ = g.Positions()
}

break
}
Expand Down
2 changes: 2 additions & 0 deletions runewidth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ var trimprefixtests = []struct {
{"あいうえお", 6, "...", "...えお"},
{"あいうえお", 10, "", ""},
{"あいうえお", 10, "...", "..."},
{"あいうえお", 5, "", " えお"},
{"Aあいうえお", 5, "", "うえお"},
}

func TestTrimPrefix(t *testing.T) {
Expand Down

0 comments on commit b18c354

Please # to comment.