fix: fixed a minor UI bug while rendering table cells with special UTF8 characters (fixes #211)

This commit is contained in:
evilsocket 2018-03-29 12:27:02 +02:00
commit 89434e1a2a
No known key found for this signature in database
GPG key ID: 1564D7F30393A456

View file

@ -5,6 +5,7 @@ import (
"io" "io"
"regexp" "regexp"
"strings" "strings"
"unicode/utf8"
) )
var ansi = regexp.MustCompile("\033\\[(?:[0-9]{1,3}(?:;[0-9]{1,3})*)?[m|K]") var ansi = regexp.MustCompile("\033\\[(?:[0-9]{1,3}(?:;[0-9]{1,3})*)?[m|K]")
@ -13,8 +14,7 @@ func viewLen(s string) int {
for _, m := range ansi.FindAllString(s, -1) { for _, m := range ansi.FindAllString(s, -1) {
s = strings.Replace(s, m, "", -1) s = strings.Replace(s, m, "", -1)
} }
return utf8.RuneCountInString(s)
return len(s)
} }
func maxLen(strings []string) int { func maxLen(strings []string) int {
@ -59,7 +59,6 @@ func padded(s string, maxLen int, align Alignment) string {
} }
func AsTable(w io.Writer, columns []string, rows [][]string) { func AsTable(w io.Writer, columns []string, rows [][]string) {
for i, col := range columns { for i, col := range columns {
columns[i] = fmt.Sprintf(" %s ", col) columns[i] = fmt.Sprintf(" %s ", col)
} }