fill with spaces instead of null chars
This commit is contained in:
1 parent
29c14533dd
commit
af113e71ef
3 files changed
+7
-32
No files matched your search
@@ -13,18 +13,10 @@ import (
|
|||||||
|
|
||||||
func isRoot(name string) bool { return filepath.Dir(name) == name }
|
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 {
|
func runeSliceWidth(rs []rune) int {
|
||||||
w := 0
|
w := 0
|
||||||
for _, r := range rs {
|
for _, r := range rs {
|
||||||
w += runeWidth(r)
|
w += runewidth.RuneWidth(r)
|
||||||
}
|
}
|
||||||
return w
|
return w
|
||||||
}
|
}
|
||||||
@@ -33,7 +25,7 @@ func runeSliceWidthRange(rs []rune, beg int, end int) []rune {
|
|||||||
curr := 0
|
curr := 0
|
||||||
b := 0
|
b := 0
|
||||||
for i, r := range rs {
|
for i, r := range rs {
|
||||||
w := runeWidth(r)
|
w := runewidth.RuneWidth(r)
|
||||||
switch {
|
switch {
|
||||||
case curr == beg:
|
case curr == beg:
|
||||||
b = i
|
b = i
|
||||||
|
|||||||
@@ -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) {
|
func TestRuneSliceWidth(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
rs []rune
|
rs []rune
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import (
|
|||||||
"unicode"
|
"unicode"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
|
"github.com/mattn/go-runewidth"
|
||||||
"github.com/nsf/termbox-go"
|
"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' {
|
if r == '\t' {
|
||||||
x += gOpts.tabstop - (x-off)%gOpts.tabstop
|
x += gOpts.tabstop - (x-off)%gOpts.tabstop
|
||||||
} else {
|
} 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 {
|
if w > win.w-2 {
|
||||||
s = runeSliceWidthRange(s, 0, win.w-2)
|
s = runeSliceWidthRange(s, 0, win.w-2)
|
||||||
} else {
|
} 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 {
|
switch gOpts.showinfo {
|
||||||
|
|||||||
Reference in new issue
Block a user