Update dependencies (#5518)
This commit is contained in:
35
vendor/github.com/gosuri/uitable/util/strutil/strutil.go
generated
vendored
35
vendor/github.com/gosuri/uitable/util/strutil/strutil.go
generated
vendored
@@ -3,12 +3,18 @@ package strutil
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"regexp"
|
||||
|
||||
"github.com/mattn/go-runewidth"
|
||||
)
|
||||
|
||||
const ansi = "[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"
|
||||
|
||||
var re = regexp.MustCompile(ansi)
|
||||
|
||||
// PadRight returns a new string of a specified length in which the end of the current string is padded with spaces or with a specified Unicode character.
|
||||
func PadRight(str string, length int, pad byte) string {
|
||||
slen := runewidth.StringWidth(str)
|
||||
slen := StringWidth(str)
|
||||
if slen >= length {
|
||||
return str
|
||||
}
|
||||
@@ -21,7 +27,7 @@ func PadRight(str string, length int, pad byte) string {
|
||||
|
||||
// PadLeft returns a new string of a specified length in which the beginning of the current string is padded with spaces or with a specified Unicode character.
|
||||
func PadLeft(str string, length int, pad byte) string {
|
||||
slen := runewidth.StringWidth(str)
|
||||
slen := StringWidth(str)
|
||||
if slen >= length {
|
||||
return str
|
||||
}
|
||||
@@ -36,7 +42,7 @@ func PadLeft(str string, length int, pad byte) string {
|
||||
// Resize resizes the string with the given length. It ellipses with '...' when the string's length exceeds
|
||||
// the desired length or pads spaces to the right of the string when length is smaller than desired
|
||||
func Resize(s string, length uint, rightAlign bool) string {
|
||||
slen := runewidth.StringWidth(s)
|
||||
slen := StringWidth(s)
|
||||
n := int(length)
|
||||
if slen == n {
|
||||
return s
|
||||
@@ -53,7 +59,7 @@ func Resize(s string, length uint, rightAlign bool) string {
|
||||
w := 0
|
||||
for _, r := range rs {
|
||||
buf.WriteRune(r)
|
||||
rw := runewidth.RuneWidth(r)
|
||||
rw := RuneWidth(r)
|
||||
if w+rw >= n-3 {
|
||||
break
|
||||
}
|
||||
@@ -65,8 +71,12 @@ func Resize(s string, length uint, rightAlign bool) string {
|
||||
return s
|
||||
}
|
||||
|
||||
// Join joins the list of the string with the delim provided
|
||||
// Join joins the list of the string with the delim provided.
|
||||
// Returns an empty string for empty list
|
||||
func Join(list []string, delim string) string {
|
||||
if len(list) == 0 {
|
||||
return ""
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
for i := 0; i < len(list)-1; i++ {
|
||||
buf.WriteString(list[i] + delim)
|
||||
@@ -74,3 +84,18 @@ func Join(list []string, delim string) string {
|
||||
buf.WriteString(list[len(list)-1])
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// Strip strips the string of all colors
|
||||
func Strip(s string) string {
|
||||
return re.ReplaceAllString(s, "")
|
||||
}
|
||||
|
||||
// StringWidth returns the actual width of the string without colors
|
||||
func StringWidth(s string) int {
|
||||
return runewidth.StringWidth(Strip(s))
|
||||
}
|
||||
|
||||
// RuneWidth returns the actual width of the rune
|
||||
func RuneWidth(s rune) int {
|
||||
return runewidth.RuneWidth(s)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user