mirror of https://github.com/docker/cli.git
Merge pull request #4251 from thaJeztah/update_runewidth
vendor: github.com/mattn/go-runewidth v0.0.14
This commit is contained in:
commit
b403a49207
|
@ -19,7 +19,7 @@ require (
|
||||||
github.com/google/go-cmp v0.5.9
|
github.com/google/go-cmp v0.5.9
|
||||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
|
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
|
||||||
github.com/imdario/mergo v0.3.13
|
github.com/imdario/mergo v0.3.13
|
||||||
github.com/mattn/go-runewidth v0.0.13
|
github.com/mattn/go-runewidth v0.0.14
|
||||||
github.com/mitchellh/mapstructure v1.3.2
|
github.com/mitchellh/mapstructure v1.3.2
|
||||||
github.com/moby/buildkit v0.11.6
|
github.com/moby/buildkit v0.11.6
|
||||||
github.com/moby/patternmatcher v0.5.0
|
github.com/moby/patternmatcher v0.5.0
|
||||||
|
|
|
@ -257,8 +257,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
github.com/lib/pq v1.9.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
github.com/lib/pq v1.9.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||||
github.com/magiconair/properties v1.5.3 h1:C8fxWnhYyME3n0klPOhVM7PtYUB3eV1W3DeFmN3j53Y=
|
github.com/magiconair/properties v1.5.3 h1:C8fxWnhYyME3n0klPOhVM7PtYUB3eV1W3DeFmN3j53Y=
|
||||||
github.com/magiconair/properties v1.5.3/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
github.com/magiconair/properties v1.5.3/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
||||||
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
|
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
|
||||||
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||||
github.com/mattn/go-sqlite3 v1.6.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
github.com/mattn/go-sqlite3 v1.6.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
||||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||||
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
|
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
language: go
|
|
||||||
sudo: false
|
|
||||||
go:
|
|
||||||
- 1.13.x
|
|
||||||
- tip
|
|
||||||
|
|
||||||
before_install:
|
|
||||||
- go get -t -v ./...
|
|
||||||
|
|
||||||
script:
|
|
||||||
- go generate
|
|
||||||
- git diff --cached --exit-code
|
|
||||||
- ./go.test.sh
|
|
||||||
|
|
||||||
after_success:
|
|
||||||
- bash <(curl -s https://codecov.io/bash)
|
|
|
@ -1,7 +1,7 @@
|
||||||
go-runewidth
|
go-runewidth
|
||||||
============
|
============
|
||||||
|
|
||||||
[![Build Status](https://travis-ci.org/mattn/go-runewidth.png?branch=master)](https://travis-ci.org/mattn/go-runewidth)
|
[![Build Status](https://github.com/mattn/go-runewidth/workflows/test/badge.svg?branch=master)](https://github.com/mattn/go-runewidth/actions?query=workflow%3Atest)
|
||||||
[![Codecov](https://codecov.io/gh/mattn/go-runewidth/branch/master/graph/badge.svg)](https://codecov.io/gh/mattn/go-runewidth)
|
[![Codecov](https://codecov.io/gh/mattn/go-runewidth/branch/master/graph/badge.svg)](https://codecov.io/gh/mattn/go-runewidth)
|
||||||
[![GoDoc](https://godoc.org/github.com/mattn/go-runewidth?status.svg)](http://godoc.org/github.com/mattn/go-runewidth)
|
[![GoDoc](https://godoc.org/github.com/mattn/go-runewidth?status.svg)](http://godoc.org/github.com/mattn/go-runewidth)
|
||||||
[![Go Report Card](https://goreportcard.com/badge/github.com/mattn/go-runewidth)](https://goreportcard.com/report/github.com/mattn/go-runewidth)
|
[![Go Report Card](https://goreportcard.com/badge/github.com/mattn/go-runewidth)](https://goreportcard.com/report/github.com/mattn/go-runewidth)
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
echo "" > coverage.txt
|
|
||||||
|
|
||||||
for d in $(go list ./... | grep -v vendor); do
|
|
||||||
go test -race -coverprofile=profile.out -covermode=atomic "$d"
|
|
||||||
if [ -f profile.out ]; then
|
|
||||||
cat profile.out >> coverage.txt
|
|
||||||
rm profile.out
|
|
||||||
fi
|
|
||||||
done
|
|
|
@ -2,6 +2,7 @@ package runewidth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/rivo/uniseg"
|
"github.com/rivo/uniseg"
|
||||||
)
|
)
|
||||||
|
@ -34,7 +35,13 @@ func handleEnv() {
|
||||||
EastAsianWidth = env == "1"
|
EastAsianWidth = env == "1"
|
||||||
}
|
}
|
||||||
// update DefaultCondition
|
// update DefaultCondition
|
||||||
|
if DefaultCondition.EastAsianWidth != EastAsianWidth {
|
||||||
DefaultCondition.EastAsianWidth = EastAsianWidth
|
DefaultCondition.EastAsianWidth = EastAsianWidth
|
||||||
|
if len(DefaultCondition.combinedLut) > 0 {
|
||||||
|
DefaultCondition.combinedLut = DefaultCondition.combinedLut[:0]
|
||||||
|
CreateLUT()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type interval struct {
|
type interval struct {
|
||||||
|
@ -89,6 +96,7 @@ var nonprint = table{
|
||||||
|
|
||||||
// Condition have flag EastAsianWidth whether the current locale is CJK or not.
|
// Condition have flag EastAsianWidth whether the current locale is CJK or not.
|
||||||
type Condition struct {
|
type Condition struct {
|
||||||
|
combinedLut []byte
|
||||||
EastAsianWidth bool
|
EastAsianWidth bool
|
||||||
StrictEmojiNeutral bool
|
StrictEmojiNeutral bool
|
||||||
}
|
}
|
||||||
|
@ -104,10 +112,16 @@ func NewCondition() *Condition {
|
||||||
// RuneWidth returns the number of cells in r.
|
// RuneWidth returns the number of cells in r.
|
||||||
// See http://www.unicode.org/reports/tr11/
|
// See http://www.unicode.org/reports/tr11/
|
||||||
func (c *Condition) RuneWidth(r rune) int {
|
func (c *Condition) RuneWidth(r rune) int {
|
||||||
|
if r < 0 || r > 0x10FFFF {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
if len(c.combinedLut) > 0 {
|
||||||
|
return int(c.combinedLut[r>>1]>>(uint(r&1)*4)) & 3
|
||||||
|
}
|
||||||
// optimized version, verified by TestRuneWidthChecksums()
|
// optimized version, verified by TestRuneWidthChecksums()
|
||||||
if !c.EastAsianWidth {
|
if !c.EastAsianWidth {
|
||||||
switch {
|
switch {
|
||||||
case r < 0x20 || r > 0x10FFFF:
|
case r < 0x20:
|
||||||
return 0
|
return 0
|
||||||
case (r >= 0x7F && r <= 0x9F) || r == 0xAD: // nonprint
|
case (r >= 0x7F && r <= 0x9F) || r == 0xAD: // nonprint
|
||||||
return 0
|
return 0
|
||||||
|
@ -124,7 +138,7 @@ func (c *Condition) RuneWidth(r rune) int {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch {
|
switch {
|
||||||
case r < 0 || r > 0x10FFFF || inTables(r, nonprint, combining):
|
case inTables(r, nonprint, combining):
|
||||||
return 0
|
return 0
|
||||||
case inTable(r, narrow):
|
case inTable(r, narrow):
|
||||||
return 1
|
return 1
|
||||||
|
@ -138,6 +152,27 @@ func (c *Condition) RuneWidth(r rune) int {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateLUT will create an in-memory lookup table of 557056 bytes for faster operation.
|
||||||
|
// This should not be called concurrently with other operations on c.
|
||||||
|
// If options in c is changed, CreateLUT should be called again.
|
||||||
|
func (c *Condition) CreateLUT() {
|
||||||
|
const max = 0x110000
|
||||||
|
lut := c.combinedLut
|
||||||
|
if len(c.combinedLut) != 0 {
|
||||||
|
// Remove so we don't use it.
|
||||||
|
c.combinedLut = nil
|
||||||
|
} else {
|
||||||
|
lut = make([]byte, max/2)
|
||||||
|
}
|
||||||
|
for i := range lut {
|
||||||
|
i32 := int32(i * 2)
|
||||||
|
x0 := c.RuneWidth(i32)
|
||||||
|
x1 := c.RuneWidth(i32 + 1)
|
||||||
|
lut[i] = uint8(x0) | uint8(x1)<<4
|
||||||
|
}
|
||||||
|
c.combinedLut = lut
|
||||||
|
}
|
||||||
|
|
||||||
// StringWidth return width as you can see
|
// StringWidth return width as you can see
|
||||||
func (c *Condition) StringWidth(s string) (width int) {
|
func (c *Condition) StringWidth(s string) (width int) {
|
||||||
g := uniseg.NewGraphemes(s)
|
g := uniseg.NewGraphemes(s)
|
||||||
|
@ -180,11 +215,47 @@ func (c *Condition) Truncate(s string, w int, tail string) string {
|
||||||
return s[:pos] + tail
|
return s[:pos] + tail
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TruncateLeft cuts w cells from the beginning of the `s`.
|
||||||
|
func (c *Condition) TruncateLeft(s string, w int, prefix string) string {
|
||||||
|
if c.StringWidth(s) <= w {
|
||||||
|
return prefix
|
||||||
|
}
|
||||||
|
|
||||||
|
var width int
|
||||||
|
pos := len(s)
|
||||||
|
|
||||||
|
g := uniseg.NewGraphemes(s)
|
||||||
|
for g.Next() {
|
||||||
|
var chWidth int
|
||||||
|
for _, r := range g.Runes() {
|
||||||
|
chWidth = c.RuneWidth(r)
|
||||||
|
if chWidth > 0 {
|
||||||
|
break // See StringWidth() for details.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if width+chWidth > w {
|
||||||
|
if width < w {
|
||||||
|
_, pos = g.Positions()
|
||||||
|
prefix += strings.Repeat(" ", width+chWidth-w)
|
||||||
|
} else {
|
||||||
|
pos, _ = g.Positions()
|
||||||
|
}
|
||||||
|
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
width += chWidth
|
||||||
|
}
|
||||||
|
|
||||||
|
return prefix + s[pos:]
|
||||||
|
}
|
||||||
|
|
||||||
// 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 := ""
|
out := ""
|
||||||
for _, r := range []rune(s) {
|
for _, r := range s {
|
||||||
cw := c.RuneWidth(r)
|
cw := c.RuneWidth(r)
|
||||||
if r == '\n' {
|
if r == '\n' {
|
||||||
out += string(r)
|
out += string(r)
|
||||||
|
@ -257,6 +328,11 @@ func Truncate(s string, w int, tail string) string {
|
||||||
return DefaultCondition.Truncate(s, w, tail)
|
return DefaultCondition.Truncate(s, w, tail)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TruncateLeft cuts w cells from the beginning of the `s`.
|
||||||
|
func TruncateLeft(s string, w int, prefix string) string {
|
||||||
|
return DefaultCondition.TruncateLeft(s, w, prefix)
|
||||||
|
}
|
||||||
|
|
||||||
// Wrap return string wrapped with w cells
|
// Wrap return string wrapped with w cells
|
||||||
func Wrap(s string, w int) string {
|
func Wrap(s string, w int) string {
|
||||||
return DefaultCondition.Wrap(s, w)
|
return DefaultCondition.Wrap(s, w)
|
||||||
|
@ -271,3 +347,12 @@ func FillLeft(s string, w int) string {
|
||||||
func FillRight(s string, w int) string {
|
func FillRight(s string, w int) string {
|
||||||
return DefaultCondition.FillRight(s, w)
|
return DefaultCondition.FillRight(s, w)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateLUT will create an in-memory lookup table of 557055 bytes for faster operation.
|
||||||
|
// This should not be called concurrently with other operations.
|
||||||
|
func CreateLUT() {
|
||||||
|
if len(DefaultCondition.combinedLut) > 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
DefaultCondition.CreateLUT()
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
//go:build appengine
|
||||||
// +build appengine
|
// +build appengine
|
||||||
|
|
||||||
package runewidth
|
package runewidth
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// +build js
|
//go:build js && !appengine
|
||||||
// +build !appengine
|
// +build js,!appengine
|
||||||
|
|
||||||
package runewidth
|
package runewidth
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
// +build !windows
|
//go:build !windows && !js && !appengine
|
||||||
// +build !js
|
// +build !windows,!js,!appengine
|
||||||
// +build !appengine
|
|
||||||
|
|
||||||
package runewidth
|
package runewidth
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// +build windows
|
//go:build windows && !appengine
|
||||||
// +build !appengine
|
// +build windows,!appengine
|
||||||
|
|
||||||
package runewidth
|
package runewidth
|
||||||
|
|
||||||
|
|
|
@ -147,7 +147,7 @@ github.com/klauspost/compress/internal/cpuinfo
|
||||||
github.com/klauspost/compress/internal/snapref
|
github.com/klauspost/compress/internal/snapref
|
||||||
github.com/klauspost/compress/zstd
|
github.com/klauspost/compress/zstd
|
||||||
github.com/klauspost/compress/zstd/internal/xxhash
|
github.com/klauspost/compress/zstd/internal/xxhash
|
||||||
# github.com/mattn/go-runewidth v0.0.13
|
# github.com/mattn/go-runewidth v0.0.14
|
||||||
## explicit; go 1.9
|
## explicit; go 1.9
|
||||||
github.com/mattn/go-runewidth
|
github.com/mattn/go-runewidth
|
||||||
# github.com/matttproud/golang_protobuf_extensions v1.0.4
|
# github.com/matttproud/golang_protobuf_extensions v1.0.4
|
||||||
|
|
Loading…
Reference in New Issue