commit 58b95642ed8659e8181344172909906f5620dba5
parent c9bc15f439cb6d8dcd74dc0b6425e15d114b6950
Author: Sean Enck <sean@ttypty.com>
Date: Sun, 3 Sep 2023 19:02:30 -0400
simpler wordwrap
Diffstat:
4 files changed, 28 insertions(+), 12 deletions(-)
diff --git a/go.mod b/go.mod
@@ -5,7 +5,6 @@ go 1.19
require (
github.com/aymanbagabas/go-osc52 v1.2.2
github.com/hashicorp/go-envparse v0.1.0
- github.com/muesli/reflow v0.3.0
github.com/pquerna/otp v1.4.0
github.com/tobischo/gokeepasslib/v3 v3.5.1
mvdan.cc/sh/v3 v3.7.0
@@ -15,8 +14,6 @@ require (
github.com/aead/argon2 v0.0.0-20180111183520-a87724528b07 // indirect
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect
github.com/boombuler/barcode v1.0.1 // indirect
- github.com/mattn/go-runewidth v0.0.12 // indirect
- github.com/rivo/uniseg v0.2.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/sys v0.11.0 // indirect
)
diff --git a/go.sum b/go.sum
@@ -15,17 +15,10 @@ github.com/hashicorp/go-envparse v0.1.0 h1:bE++6bhIsNCPLvgDZkYqo3nA+/PFI51pkrHdm
github.com/hashicorp/go-envparse v0.1.0/go.mod h1:OHheN1GoygLlAkTlXLXvAdnXdZxy8JUweQ1rAXx1xnc=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
-github.com/mattn/go-runewidth v0.0.12 h1:Y41i/hVW3Pgwr8gV+J23B9YEY0zxjptBuCWEaxmAOow=
-github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
-github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
-github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pquerna/otp v1.4.0 h1:wZvl1TIVxKRThZIBiwOOHOGP/1+nZyWBil9Y2XNEDzg=
github.com/pquerna/otp v1.4.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg=
-github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
-github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
-github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rogpeppe/go-internal v1.10.1-0.20230524175051-ec119421bb97 h1:3RPlVWzZ/PDqmVuf/FKHARG5EMid/tl7cv54Sw/QRVY=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
diff --git a/internal/app/core_test.go b/internal/app/core_test.go
@@ -1,6 +1,7 @@
package app_test
import (
+ "strings"
"testing"
"github.com/enckse/lockbox/internal/app"
@@ -15,4 +16,11 @@ func TestUsage(t *testing.T) {
if len(u) != 108 {
t.Errorf("invalid verbose usage, out of date? %d", len(u))
}
+ for _, usage := range u {
+ for _, l := range strings.Split(usage, "\n") {
+ if len(l) > 80 {
+ t.Errorf("usage line > 80 (%d), line: %s", len(l), l)
+ }
+ }
+ }
}
diff --git a/internal/config/core.go b/internal/config/core.go
@@ -12,7 +12,6 @@ import (
"strconv"
"strings"
- "github.com/muesli/reflow/wordwrap"
"mvdan.cc/sh/v3/shell"
)
@@ -450,10 +449,29 @@ func Wrap(indent uint, in string) string {
}
indenture := int(80 - indent)
for _, s := range sections {
- for _, line := range strings.Split(wordwrap.String(s, indenture), "\n") {
+ for _, line := range strings.Split(wrap(s, indenture), "\n") {
fmt.Fprintf(&out, "%s%s\n", indenting, line)
}
fmt.Fprint(&out, "\n")
}
return out.String()
}
+
+func wrap(in string, maxLength int) string {
+ var lines []string
+ var cur []string
+ for _, p := range strings.Split(in, " ") {
+ state := strings.Join(cur, " ")
+ l := len(p)
+ if len(state)+l >= maxLength {
+ lines = append(lines, strings.Join(cur, " "))
+ cur = []string{p}
+ } else {
+ cur = append(cur, p)
+ }
+ }
+ if len(cur) > 0 {
+ lines = append(lines, strings.Join(cur, " "))
+ }
+ return strings.Join(lines, "\n")
+}