diff --git a/go.mod b/go.mod index 40d4b7872..dcfc9ce80 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/gorilla/websocket v1.5.4-0.20240702125206-a62d9d2a8413 github.com/h2non/filetype v1.1.3 github.com/jackc/pgx/v5 v5.10.0 - github.com/jedib0t/go-pretty/v6 v6.8.1 + github.com/jedib0t/go-pretty/v6 v6.8.2 github.com/manifoldco/promptui v0.9.0 github.com/mattn/go-sqlite3 v1.14.45 github.com/nbutton23/zxcvbn-go v0.0.0-20210217022336-fa2cb2858354 diff --git a/go.sum b/go.sum index 7b279994a..f51e62cec 100644 --- a/go.sum +++ b/go.sum @@ -141,8 +141,8 @@ github.com/jackc/pgx/v5 v5.10.0 h1:VhSvgU2jSli8o3AqIEOTJr7rZwAEUVo4E4XhR94Zfr0= github.com/jackc/pgx/v5 v5.10.0/go.mod h1:mal1tBGAFfLHvZzaYh77YS/eC6IX9OWbRV1QIIM0Jn4= github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo= github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= -github.com/jedib0t/go-pretty/v6 v6.8.1 h1:0fkCNhjrX0zPpwkWaDYU5VMrygg41Tu197mWILIJoqQ= -github.com/jedib0t/go-pretty/v6 v6.8.1/go.mod h1:YwC5CE4fJ1HFUDeivSV1r//AmANFHyqczZk+U6BDALU= +github.com/jedib0t/go-pretty/v6 v6.8.2 h1:FmKNr1GOyot/zqNQplE8HLhFguJaeHJTCArntnI4uxE= +github.com/jedib0t/go-pretty/v6 v6.8.2/go.mod h1:YwC5CE4fJ1HFUDeivSV1r//AmANFHyqczZk+U6BDALU= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= diff --git a/vendor/github.com/jedib0t/go-pretty/v6/text/string.go b/vendor/github.com/jedib0t/go-pretty/v6/text/string.go index d8b308459..7902b0e06 100644 --- a/vendor/github.com/jedib0t/go-pretty/v6/text/string.go +++ b/vendor/github.com/jedib0t/go-pretty/v6/text/string.go @@ -286,13 +286,16 @@ func StringWidthWithoutEscSequences(str string) int { return count } -// Trim trims a string to the given length while ignoring escape sequences. For -// ex.: +// Trim trims a string to the given display width (maxLen columns) while +// ignoring escape sequences. Wide East Asian characters count as two columns, +// so the result never exceeds maxLen columns. For ex.: // // Trim("Ghost", 3) == "Gho" // Trim("Ghost", 6) == "Ghost" // Trim("\x1b[33mGhost\x1b[0m", 3) == "\x1b[33mGho\x1b[0m" // Trim("\x1b[33mGhost\x1b[0m", 6) == "\x1b[33mGhost\x1b[0m" +// Trim("生命生命", 3) == "生" +// Trim("生命生命", 4) == "生命" func Trim(str string, maxLen int) string { if maxLen <= 0 { return "" @@ -301,7 +304,7 @@ func Trim(str string, maxLen int) string { var out strings.Builder out.Grow(maxLen) - outLen, esp := 0, EscSeqParser{} + outLen, full, esp := 0, false, EscSeqParser{} for _, sChr := range str { if esp.InSequence() { esp.Consume(sChr) @@ -313,10 +316,17 @@ func Trim(str string, maxLen int) string { out.WriteRune(sChr) continue } - if outLen < maxLen { - outLen++ - out.WriteRune(sChr) - continue + // Count the display width of the rune (wide East Asian characters + // occupy two columns) instead of counting runes, so the result never + // exceeds maxLen columns. Once a rune no longer fits, stop emitting + // visible runes but keep copying any trailing escape sequences. + if !full { + if w := RuneWidth(sChr); outLen+w <= maxLen { + outLen += w + out.WriteRune(sChr) + continue + } + full = true } } return out.String() diff --git a/vendor/modules.txt b/vendor/modules.txt index bc027c676..7fecf44b1 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -248,7 +248,7 @@ github.com/jackc/pgx/v5/stdlib ## explicit; go 1.19 github.com/jackc/puddle/v2 github.com/jackc/puddle/v2/internal/genstack -# github.com/jedib0t/go-pretty/v6 v6.8.1 +# github.com/jedib0t/go-pretty/v6 v6.8.2 ## explicit; go 1.18 github.com/jedib0t/go-pretty/v6/table github.com/jedib0t/go-pretty/v6/text