diff --git a/go.mod b/go.mod index ac48311..7d4d201 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/go-chi/chi/v5 v5.3.0 github.com/google/uuid v1.6.0 github.com/hashicorp/nomad/api v0.0.0-20260220212019-daca79db0bd6 - github.com/jedib0t/go-pretty/v6 v6.8.1 + github.com/jedib0t/go-pretty/v6 v6.8.2 github.com/rs/zerolog v1.35.1 github.com/stretchr/testify v1.11.1 ) diff --git a/go.sum b/go.sum index 60508eb..8a410b0 100644 --- a/go.sum +++ b/go.sum @@ -42,8 +42,8 @@ github.com/hashicorp/go-rootcerts v1.0.2 h1:jzhAVGtqPKbwpyCPELlgNWhE1znq+qwJtW5O github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8= github.com/hashicorp/nomad/api v0.0.0-20260220212019-daca79db0bd6 h1:QN/GwpGyiW8RdNcHGMA1xVnM8tJkAGNDR/BZ47XR+OU= github.com/hashicorp/nomad/api v0.0.0-20260220212019-daca79db0bd6/go.mod h1:KkLNLU0Nyfh5jWsFoF/PsmMbKpRIAoIV4lmQoJWgKCk= -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/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= 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 d8b3084..7902b0e 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 d41bd12..9e19866 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -57,7 +57,7 @@ github.com/hashicorp/go-rootcerts ## explicit; go 1.20 github.com/hashicorp/nomad/api github.com/hashicorp/nomad/api/contexts -# 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