Make the geoip lookup output prettier
This commit is contained in:
parent
5b31403061
commit
65b5feef0d
3 changed files with 50 additions and 3 deletions
|
|
@ -1,10 +1,22 @@
|
|||
package cli
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
func RightPad(str string, length int) string {
|
||||
return str + strings.Repeat(" ", length-utf8.RuneCountInString(str))
|
||||
// Finds the control character sequences (like colors)
|
||||
var ctrlFinder = regexp.MustCompile("\x1b\x5b[0-9]+\x6d")
|
||||
|
||||
func escapeAwareRuneCountInString(s string) int {
|
||||
n := utf8.RuneCountInString(s)
|
||||
for _, sm := range ctrlFinder.FindAllString(s, -1) {
|
||||
n -= utf8.RuneCountInString(sm)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func RightPad(str string, length int) string {
|
||||
return str + strings.Repeat(" ", length-escapeAwareRuneCountInString(str))
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue