fill with spaces instead of null chars

This commit is contained in:
Gokcehan committed 2016-12-22 22:58:55 +03:00
1 parent 29c14533dd
commit af113e71ef
3 files changed
+7 -32

No files matched your search

+2 -10
View File
@@ -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
-20
View File
@@ -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
+5 -2
View File
@@ -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 {