diff --git a/go.mod b/go.mod index 244c931..b1561a0 100644 --- a/go.mod +++ b/go.mod @@ -21,5 +21,5 @@ require ( github.com/mattn/go-runewidth v0.0.15 // indirect github.com/rivo/uniseg v0.4.7 // indirect golang.org/x/sys v0.19.0 // indirect - zgo.at/termtext v1.3.0 // indirect + zgo.at/termtext v1.4.0 // indirect ) diff --git a/go.sum b/go.sum index 83eeda4..29210b6 100644 --- a/go.sum +++ b/go.sum @@ -31,5 +31,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= zgo.at/acidtab v1.0.0 h1:KtXvxtY0uXKNQW1dz113e++5XodEs5HEqIO9AJDT7Nk= zgo.at/acidtab v1.0.0/go.mod h1:dOHM1/D5cRCsskzFmyniTDVZjuwnqFdAcvRiT3RTvY0= zgo.at/termtext v0.0.0-20211017203350-a2beb4680d76/go.mod h1:P0jvULwo8z82ad7+WR6vg5vTy86dqvbOmR3bT3NlYvc= -zgo.at/termtext v1.3.0 h1:aJRg7PJOJHJCsWnzmYk8iLWP/bd9rfw9zOmyMNxzyXk= -zgo.at/termtext v1.3.0/go.mod h1:CBx+HpG2ijB3W0Bd4CK8UtzcsXw+EmvvlhQUyQpZO+E= +zgo.at/termtext v1.4.0 h1:r7fzyT5jsdRw9Z0uCQh+A+TWhWk+pC5HDJd1o8EH8NI= +zgo.at/termtext v1.4.0/go.mod h1:CBx+HpG2ijB3W0Bd4CK8UtzcsXw+EmvvlhQUyQpZO+E= diff --git a/vendor/modules.txt b/vendor/modules.txt index fac51b0..3e2d63a 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -24,6 +24,6 @@ golang.org/x/sys/unix # zgo.at/acidtab v1.0.0 ## explicit; go 1.16 zgo.at/acidtab -# zgo.at/termtext v1.3.0 +# zgo.at/termtext v1.4.0 ## explicit; go 1.16 zgo.at/termtext diff --git a/vendor/zgo.at/termtext/termtext.go b/vendor/zgo.at/termtext/termtext.go index 25e362e..b409973 100644 --- a/vendor/zgo.at/termtext/termtext.go +++ b/vendor/zgo.at/termtext/termtext.go @@ -13,6 +13,21 @@ import ( // Number of spaces to count a tab as. var TabWidth = 8 +// Widths sets the width for the given runes. +// +// This can be useful in some cases where the written text is different. For +// example when encoding JSON some characters get written as a \-escape. To +// account for this, you can override the width for those: +// +// termtext.Escapes = map[rune]int{ +// '\b': 2, +// '\f': 2, +// '\n': 2, +// '\r': 2, +// '\t': 2, +// } +var Widths map[rune]int + // Width gets the display width of a string. // // The "display width" is the number of columns a string will occupy in a @@ -32,6 +47,11 @@ func Width(s string) int { continue } + if ll, ok := Widths[runes[0]]; ok { + l += ll + continue + } + /// One codepoint: check for tab and escapes. switch r := runes[0]; { case r == '\t':