vendor: github.com/mattn/go-runewidth v0.0.23
full diff: https://github.com/mattn/go-runewidth/compare/v0.0.22...v0.0.23 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -165,7 +165,7 @@ require (
|
|||||||
github.com/lestrrat-go/jwx/v3 v3.0.11 // indirect
|
github.com/lestrrat-go/jwx/v3 v3.0.11 // indirect
|
||||||
github.com/lestrrat-go/option v1.0.1 // indirect
|
github.com/lestrrat-go/option v1.0.1 // indirect
|
||||||
github.com/lestrrat-go/option/v2 v2.0.0 // indirect
|
github.com/lestrrat-go/option/v2 v2.0.0 // indirect
|
||||||
github.com/mattn/go-runewidth v0.0.22 // indirect
|
github.com/mattn/go-runewidth v0.0.23 // indirect
|
||||||
github.com/mattn/go-shellwords v1.0.12 // indirect
|
github.com/mattn/go-shellwords v1.0.12 // indirect
|
||||||
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
|
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
|
||||||
github.com/moby/docker-image-spec v1.3.1 // indirect
|
github.com/moby/docker-image-spec v1.3.1 // indirect
|
||||||
|
|||||||
@@ -406,8 +406,8 @@ github.com/lestrrat-go/option/v2 v2.0.0 h1:XxrcaJESE1fokHy3FpaQ/cXW8ZsIdWcdFzzLO
|
|||||||
github.com/lestrrat-go/option/v2 v2.0.0/go.mod h1:oSySsmzMoR0iRzCDCaUfsCzxQHUEuhOViQObyy7S6Vg=
|
github.com/lestrrat-go/option/v2 v2.0.0/go.mod h1:oSySsmzMoR0iRzCDCaUfsCzxQHUEuhOViQObyy7S6Vg=
|
||||||
github.com/letsencrypt/boulder v0.20251110.0 h1:J8MnKICeilO91dyQ2n5eBbab24neHzUpYMUIOdOtbjc=
|
github.com/letsencrypt/boulder v0.20251110.0 h1:J8MnKICeilO91dyQ2n5eBbab24neHzUpYMUIOdOtbjc=
|
||||||
github.com/letsencrypt/boulder v0.20251110.0/go.mod h1:ogKCJQwll82m7OVHWyTuf8eeFCjuzdRQlgnZcCl0V+8=
|
github.com/letsencrypt/boulder v0.20251110.0/go.mod h1:ogKCJQwll82m7OVHWyTuf8eeFCjuzdRQlgnZcCl0V+8=
|
||||||
github.com/mattn/go-runewidth v0.0.22 h1:76lXsPn6FyHtTY+jt2fTTvsMUCZq1k0qwRsAMuxzKAk=
|
github.com/mattn/go-runewidth v0.0.23 h1:7ykA0T0jkPpzSvMS5i9uoNn2Xy3R383f9HDx3RybWcw=
|
||||||
github.com/mattn/go-runewidth v0.0.22/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=
|
github.com/mattn/go-runewidth v0.0.23/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=
|
||||||
github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk=
|
github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk=
|
||||||
github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=
|
github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=
|
||||||
github.com/miekg/dns v1.1.57 h1:Jzi7ApEIzwEPLHWRcafCN9LZSBbqQpxjt/wpgvg7wcM=
|
github.com/miekg/dns v1.1.57 h1:Jzi7ApEIzwEPLHWRcafCN9LZSBbqQpxjt/wpgvg7wcM=
|
||||||
|
|||||||
+69
-22
@@ -24,10 +24,48 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
zerowidth table // combining + nonprint merged for faster zero-width lookup
|
||||||
|
widewidth table // ambiguous + doublewidth merged for EA path
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
zerowidth = mergeIntervals(combining, nonprint)
|
||||||
|
widewidth = mergeIntervals(ambiguous, doublewidth)
|
||||||
handleEnv()
|
handleEnv()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func mergeIntervals(t1, t2 table) table {
|
||||||
|
merged := make(table, 0, len(t1)+len(t2))
|
||||||
|
i, j := 0, 0
|
||||||
|
for i < len(t1) && j < len(t2) {
|
||||||
|
if t1[i].first <= t2[j].first {
|
||||||
|
merged = append(merged, t1[i])
|
||||||
|
i++
|
||||||
|
} else {
|
||||||
|
merged = append(merged, t2[j])
|
||||||
|
j++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
merged = append(merged, t1[i:]...)
|
||||||
|
merged = append(merged, t2[j:]...)
|
||||||
|
if len(merged) == 0 {
|
||||||
|
return merged
|
||||||
|
}
|
||||||
|
result := merged[:1]
|
||||||
|
for _, iv := range merged[1:] {
|
||||||
|
last := &result[len(result)-1]
|
||||||
|
if iv.first <= last.last+1 {
|
||||||
|
if iv.last > last.last {
|
||||||
|
last.last = iv.last
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result = append(result, iv)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
func handleEnv() {
|
func handleEnv() {
|
||||||
env := os.Getenv("RUNEWIDTH_EASTASIAN")
|
env := os.Getenv("RUNEWIDTH_EASTASIAN")
|
||||||
if env == "" {
|
if env == "" {
|
||||||
@@ -52,15 +90,6 @@ type interval struct {
|
|||||||
|
|
||||||
type table []interval
|
type table []interval
|
||||||
|
|
||||||
func inTables(r rune, ts ...table) bool {
|
|
||||||
for _, t := range ts {
|
|
||||||
if inTable(r, t) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func inTable(r rune, t table) bool {
|
func inTable(r rune, t table) bool {
|
||||||
if r < t[0].first {
|
if r < t[0].first {
|
||||||
return false
|
return false
|
||||||
@@ -131,9 +160,7 @@ func (c *Condition) RuneWidth(r rune) int {
|
|||||||
return 0
|
return 0
|
||||||
case r < 0x300:
|
case r < 0x300:
|
||||||
return 1
|
return 1
|
||||||
case inTable(r, narrow):
|
case inTable(r, zerowidth):
|
||||||
return 1
|
|
||||||
case inTables(r, nonprint, combining):
|
|
||||||
return 0
|
return 0
|
||||||
case inTable(r, doublewidth):
|
case inTable(r, doublewidth):
|
||||||
return 2
|
return 2
|
||||||
@@ -142,13 +169,13 @@ func (c *Condition) RuneWidth(r rune) int {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch {
|
switch {
|
||||||
case inTables(r, nonprint, combining):
|
case inTable(r, zerowidth):
|
||||||
return 0
|
return 0
|
||||||
case inTable(r, narrow):
|
case inTable(r, narrow):
|
||||||
return 1
|
return 1
|
||||||
case inTables(r, ambiguous, doublewidth):
|
case inTable(r, widewidth):
|
||||||
return 2
|
return 2
|
||||||
case !c.StrictEmojiNeutral && inTables(r, ambiguous, emoji, narrow):
|
case !c.StrictEmojiNeutral && inTable(r, emoji):
|
||||||
return 2
|
return 2
|
||||||
default:
|
default:
|
||||||
return 1
|
return 1
|
||||||
@@ -185,6 +212,16 @@ func (c *Condition) StringWidth(s string) (width int) {
|
|||||||
return c.RuneWidth(r)
|
return c.RuneWidth(r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ASCII fast path: no grapheme clustering needed for pure ASCII
|
||||||
|
if isAllASCII(s) {
|
||||||
|
for i := 0; i < len(s); i++ {
|
||||||
|
b := s[i]
|
||||||
|
if b >= 0x20 && b != 0x7F {
|
||||||
|
width++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
g := graphemes.FromString(s)
|
g := graphemes.FromString(s)
|
||||||
for g.Next() {
|
for g.Next() {
|
||||||
var chWidth int
|
var chWidth int
|
||||||
@@ -199,6 +236,15 @@ func (c *Condition) StringWidth(s string) (width int) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isAllASCII(s string) bool {
|
||||||
|
for i := 0; i < len(s); i++ {
|
||||||
|
if s[i] >= 0x80 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// Truncate return string truncated with w cells
|
// Truncate return string truncated with w cells
|
||||||
func (c *Condition) Truncate(s string, w int, tail string) string {
|
func (c *Condition) Truncate(s string, w int, tail string) string {
|
||||||
if c.StringWidth(s) <= w {
|
if c.StringWidth(s) <= w {
|
||||||
@@ -264,24 +310,25 @@ func (c *Condition) TruncateLeft(s string, w int, prefix string) string {
|
|||||||
// Wrap return string wrapped with w cells
|
// Wrap return string wrapped with w cells
|
||||||
func (c *Condition) Wrap(s string, w int) string {
|
func (c *Condition) Wrap(s string, w int) string {
|
||||||
width := 0
|
width := 0
|
||||||
out := ""
|
var out strings.Builder
|
||||||
|
out.Grow(len(s) + len(s)/w + 1)
|
||||||
for _, r := range s {
|
for _, r := range s {
|
||||||
cw := c.RuneWidth(r)
|
cw := c.RuneWidth(r)
|
||||||
if r == '\n' {
|
if r == '\n' {
|
||||||
out += string(r)
|
out.WriteRune(r)
|
||||||
width = 0
|
width = 0
|
||||||
continue
|
continue
|
||||||
} else if width+cw > w {
|
} else if width+cw > w {
|
||||||
out += "\n"
|
out.WriteByte('\n')
|
||||||
width = 0
|
width = 0
|
||||||
out += string(r)
|
out.WriteRune(r)
|
||||||
width += cw
|
width += cw
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
out += string(r)
|
out.WriteRune(r)
|
||||||
width += cw
|
width += cw
|
||||||
}
|
}
|
||||||
return out
|
return out.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// FillLeft return string filled in left by spaces in w cells
|
// FillLeft return string filled in left by spaces in w cells
|
||||||
@@ -320,7 +367,7 @@ func RuneWidth(r rune) int {
|
|||||||
|
|
||||||
// IsAmbiguousWidth returns whether is ambiguous width or not.
|
// IsAmbiguousWidth returns whether is ambiguous width or not.
|
||||||
func IsAmbiguousWidth(r rune) bool {
|
func IsAmbiguousWidth(r rune) bool {
|
||||||
return inTables(r, private, ambiguous)
|
return inTable(r, private) || inTable(r, ambiguous)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsCombiningWidth returns whether is combining width or not.
|
// IsCombiningWidth returns whether is combining width or not.
|
||||||
|
|||||||
Vendored
+1
-1
@@ -634,7 +634,7 @@ github.com/lestrrat-go/option
|
|||||||
# github.com/lestrrat-go/option/v2 v2.0.0
|
# github.com/lestrrat-go/option/v2 v2.0.0
|
||||||
## explicit; go 1.23
|
## explicit; go 1.23
|
||||||
github.com/lestrrat-go/option/v2
|
github.com/lestrrat-go/option/v2
|
||||||
# github.com/mattn/go-runewidth v0.0.22
|
# github.com/mattn/go-runewidth v0.0.23
|
||||||
## explicit; go 1.20
|
## explicit; go 1.20
|
||||||
github.com/mattn/go-runewidth
|
github.com/mattn/go-runewidth
|
||||||
# github.com/mattn/go-shellwords v1.0.12
|
# github.com/mattn/go-shellwords v1.0.12
|
||||||
|
|||||||
Reference in New Issue
Block a user