diff --git a/misc.go b/misc.go index 02fb2a5b..4c85cba8 100644 --- a/misc.go +++ b/misc.go @@ -13,18 +13,10 @@ import ( func isRoot(name string) bool { return filepath.Dir(name) == name } -func runeWidth(r rune) int { - w := runewidth.RuneWidth(r) - if w == 0 || (w == 2 && runewidth.IsAmbiguousWidth(r)) { - w = 1 - } - return w -} - func runeSliceWidth(rs []rune) int { w := 0 for _, r := range rs { - w += runeWidth(r) + w += runewidth.RuneWidth(r) } return w } @@ -33,7 +25,7 @@ func runeSliceWidthRange(rs []rune, beg int, end int) []rune { curr := 0 b := 0 for i, r := range rs { - w := runeWidth(r) + w := runewidth.RuneWidth(r) switch { case curr == beg: b = i diff --git a/misc_test.go b/misc_test.go index da2e4b1d..3ab27b1f 100644 --- a/misc_test.go +++ b/misc_test.go @@ -27,26 +27,6 @@ func TestIsRoot(t *testing.T) { } } -func TestRuneWidth(t *testing.T) { - tests := []struct { - r rune - exp int - }{ - {' ', 1}, - {'a', 1}, - {'ı', 1}, - {'ş', 1}, - {'世', 2}, - {'界', 2}, - } - - for _, test := range tests { - if got := runeWidth(test.r); got != test.exp { - t.Errorf("at input '%c' expected '%d' but got '%d'", test.r, test.exp, got) - } - } -} - func TestRuneSliceWidth(t *testing.T) { tests := []struct { rs []rune diff --git a/ui.go b/ui.go index b2923b49..d551dae0 100644 --- a/ui.go +++ b/ui.go @@ -16,6 +16,7 @@ import ( "unicode" "unicode/utf8" + "github.com/mattn/go-runewidth" "github.com/nsf/termbox-go" ) @@ -195,7 +196,7 @@ func (win *win) print(x, y int, fg, bg termbox.Attribute, s string) { if r == '\t' { x += gOpts.tabstop - (x-off)%gOpts.tabstop } else { - x += runeWidth(r) + x += runewidth.RuneWidth(r) } } } @@ -279,7 +280,9 @@ func (win *win) printd(dir *dir, marks, saves map[string]bool) { if w > win.w-2 { s = runeSliceWidthRange(s, 0, win.w-2) } else { - s = append(s, make([]rune, win.w-2-w)...) + for i := 0; i < win.w-2-w; i++ { + s = append(s, ' ') + } } switch gOpts.showinfo {