diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c6f63dc..a27983a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,7 +25,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: 1.17 + go-version: 1.18 # Download all the tools used in the steps that follow - name: Set up Tools diff --git a/README.md b/README.md index af77db9..107d1bf 100644 --- a/README.md +++ b/README.md @@ -84,31 +84,3 @@ of the functions available are used in one or more of the other packages here. - [Wrap](text/wrap.go) text GoDoc has examples for all the available functions. - -## Upgrading from v5 or less to v6 or above - -If you are using a version of this library older than `v6.0.0` and want to move -to a newer version of this library, you'd have to modify the import paths from -something like: -```golang - "github.com/jedib0t/go-pretty/list" - "github.com/jedib0t/go-pretty/progress" - "github.com/jedib0t/go-pretty/table" - "github.com/jedib0t/go-pretty/text" -``` -to: -```golang - "github.com/jedib0t/go-pretty/v6/list" - "github.com/jedib0t/go-pretty/v6/progress" - "github.com/jedib0t/go-pretty/v6/table" - "github.com/jedib0t/go-pretty/v6/text" -``` - -I'd recommend you fire up your favorite IDE and do a mass search and replace for -all occurrences of `jedib0t/go-pretty/` to `jedib0t/go-pretty/v6/`. If you are -on a system with access to `find`, `grep`, `xargs` and `sed`, you could just run -the following from within your code folder to do the same: -``` -find . -type f -name "*.go" | grep -v vendor | xargs sed -i 's/jedib0t\/go-pretty\//jedib0t\/go-pretty\/v6\//g' -``` -If you are on macOS, you'll have to use `sed -i ''` instead of `sed -i`. diff --git a/cmd/demo-progress/demo.go b/cmd/demo-progress/demo.go index 813d443..e0a77a9 100644 --- a/cmd/demo-progress/demo.go +++ b/cmd/demo-progress/demo.go @@ -36,6 +36,7 @@ var ( text.FgCyan, text.FgWhite, } + rng = rand.New(rand.NewSource(time.Now().UnixNano())) timeStart = time.Now() ) @@ -74,9 +75,9 @@ func trackSomething(pw progress.Writer, idx int64, updateMessage bool) { units := getUnits(idx) message := getMessage(idx, units) tracker := progress.Tracker{ - DeferStart: *flagRandomDefer && rand.Float64() < 0.5, + DeferStart: *flagRandomDefer && rng.Float64() < 0.5, Message: message, - RemoveOnCompletion: *flagRandomRemove && rand.Float64() < 0.25, + RemoveOnCompletion: *flagRandomRemove && rng.Float64() < 0.25, Total: total, Units: *units, } diff --git a/go.mod b/go.mod index 9af7193..4a4779f 100644 --- a/go.mod +++ b/go.mod @@ -1,21 +1,21 @@ module github.com/jedib0t/go-pretty/v6 -go 1.17 +go 1.18 require ( - github.com/mattn/go-runewidth v0.0.15 + github.com/mattn/go-runewidth v0.0.16 github.com/pkg/profile v1.7.0 - github.com/stretchr/testify v1.8.4 - golang.org/x/sys v0.17.0 - golang.org/x/term v0.17.0 - golang.org/x/text v0.21.0 + github.com/stretchr/testify v1.10.0 + golang.org/x/sys v0.30.0 + golang.org/x/term v0.29.0 + golang.org/x/text v0.22.0 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect - github.com/felixge/fgprof v0.9.3 // indirect - github.com/google/pprof v0.0.0-20211214055906-6f57359322fd // indirect + github.com/felixge/fgprof v0.9.5 // indirect + github.com/google/pprof v0.0.0-20240227163752-401108e1b7e7 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/rivo/uniseg v0.2.0 // indirect + github.com/rivo/uniseg v0.4.7 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 0041eb3..340a23b 100644 --- a/go.sum +++ b/go.sum @@ -1,35 +1,117 @@ +github.com/chromedp/cdproto v0.0.0-20230802225258-3cf4e6d46a89/go.mod h1:GKljq0VrfU4D5yc+2qA6OVr8pmO/MBbPEWqWQ/oqGEs= +github.com/chromedp/chromedp v0.9.2/go.mod h1:LkSXJKONWTCHAfQasKFUZI+mxqS4tZqhmtGzzhLsnLs= +github.com/chromedp/sysutil v1.0.0/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moAV0xufSww= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/logex v1.2.1/go.mod h1:JLbx6lG2kDbNRFnfkgvh4eRJRPX1QCoOIWomwysCBrQ= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/felixge/fgprof v0.9.3 h1:VvyZxILNuCiUCSXtPtYmmtGvb65nqXh2QFWc0Wpf2/g= github.com/felixge/fgprof v0.9.3/go.mod h1:RdbpDgzqYVh/T9fPELJyV7EYJuHB55UTEULNun8eiPw= -github.com/google/pprof v0.0.0-20211214055906-6f57359322fd h1:1FjCyPC+syAzJ5/2S8fqdZK1R22vvA0J7JZKcuOIQ7Y= +github.com/felixge/fgprof v0.9.5 h1:8+vR6yu2vvSKn08urWyEuxx75NWPEvybbkBirEpsbVY= +github.com/felixge/fgprof v0.9.5/go.mod h1:yKl+ERSa++RYOs32d8K6WEXCB4uXdLls4ZaZPpayhMM= +github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM= +github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= +github.com/gobwas/ws v1.2.1/go.mod h1:hRKAFb8wOxFROYNsT1bqfWnhX+b5MFeJM9r2ZSwg/KY= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/pprof v0.0.0-20211214055906-6f57359322fd/go.mod h1:KgnwoLYCZ8IQu3XUZ8Nc/bM9CCZFOyjUNOSygVozoDg= +github.com/google/pprof v0.0.0-20240227163752-401108e1b7e7 h1:y3N7Bm7Y9/CtpiVkw/ZWj6lSlDF3F74SfKwfTCer72Q= +github.com/google/pprof v0.0.0-20240227163752-401108e1b7e7/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik= github.com/ianlancetaylor/demangle v0.0.0-20210905161508-09a460cdf81d/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w= -github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= -github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/ianlancetaylor/demangle v0.0.0-20230524184225-eabc099b10ab/go.mod h1:gx7rwoVhcfuVKG5uya9Hs3Sxj7EIvldVofAWIUtGouw= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= +github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80/go.mod h1:imJHygn/1yfhB7XSJJKlFZKl/J+dCPAknuiaGOshXAs= +github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= +github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde/go.mod h1:nZgzbfBr3hhjoZnS66nKrHmduYNpc34ny7RK4z5/HM0= github.com/pkg/profile v1.7.0 h1:hnbDkaNWPCLMO9wGLdBFTIZvzDrDfBM2072E1S9gJkA= github.com/pkg/profile v1.7.0/go.mod h1:8Uer0jas47ZQMJ7VD+OHknK4YDY07LPUC6dEvqDjvNo= 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/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= +github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= +golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= +golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= +golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= +golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= +golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= -golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= -golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= +golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= +golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU= +golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= +golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/table/render_automerge_test.go b/table/render_automerge_test.go index 200c87a..ed89ff7 100644 --- a/table/render_automerge_test.go +++ b/table/render_automerge_test.go @@ -1,6 +1,7 @@ package table import ( + "strings" "testing" "github.com/jedib0t/go-pretty/v6/text" @@ -763,12 +764,11 @@ func TestTable_Render_AutoMergeLongColumns(t *testing.T) { └───┴──────────┴──────────┴──────────┴──────────┴───────────────────────────────────────────┘`) }) - t.Run("Rebalance long merged columns", func(t *testing.T) { + t.Run("long_merged_columns", func(t *testing.T) { tw := NewWriter() tw.AppendHeader(Row{"ID", "Date", "From", "To", "Subject", "Size"}) - tw.AppendRow(Row{ - 4, + 1, "2024-11-18T09:30:54Z", "Shaylee McDermott", "", @@ -776,7 +776,7 @@ func TestTable_Render_AutoMergeLongColumns(t *testing.T) { "4.2 MB", }) tw.AppendRow(Row{ - 4, + 2, "2024-11-18T09:30:54Z", "Anahi Braun ", "", @@ -784,21 +784,18 @@ func TestTable_Render_AutoMergeLongColumns(t *testing.T) { "4.2 MB", }) tw.AppendRow(Row{ - 4, + 3, "2024-11-18T09:30:54Z", "Brando Barton", "", "Before they sold out jean shorts chartreuse neutra fixie flexitarian goth art party small batch sriracha.", "4.2 MB", }) - const ID = "AAMkADdiOWM1OTBkLTBhZjEtNGFiNS1hOGYwLTY2YWFmOGQyNTMxNgBGAAAAAADBju3TxrP2SZIsqjNb8hmoBwA9J0gY/4/nQ73Lmp9F9NoaAABlJ281AAA9J0gY/4/nQ73Lmp9F9NoaAABlJ6bLAAA=" + longColumn := strings.Repeat("1234567890", 15) tw.AppendRow( - Row{ID, ID, ID, ID, ID, ID}, - RowConfig{ - AutoMerge: true, - AutoMergeAlign: text.AlignLeft, - }) - + Row{4, longColumn, longColumn, longColumn, longColumn, longColumn}, + RowConfig{AutoMerge: true, AutoMergeAlign: text.AlignLeft}, + ) tw.SetStyle(StyleLight) tw.Style().Options.SeparateRows = true @@ -806,14 +803,14 @@ func TestTable_Render_AutoMergeLongColumns(t *testing.T) { ┌────┬──────────────────────┬───────────────────┬────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬────────┐ │ ID │ DATE │ FROM │ TO │ SUBJECT │ SIZE │ ├────┼──────────────────────┼───────────────────┼────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────┤ -│ 4 │ 2024-11-18T09:30:54Z │ Shaylee McDermott │ │ Tote bag photo booth lumbersexual normcore synth meh lumbersexual disrupt craft beer aesthetic. │ 4.2 MB │ +│ 1 │ 2024-11-18T09:30:54Z │ Shaylee McDermott │ │ Tote bag photo booth lumbersexual normcore synth meh lumbersexual disrupt craft beer aesthetic. │ 4.2 MB │ ├────┼──────────────────────┼───────────────────┼────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────┤ -│ 4 │ 2024-11-18T09:30:54Z │ Anahi Braun │ │ Mumblecore salvia mumblecore austin tofu viral asymmetrical small batch distillery you probably haven't heard of them. │ 4.2 MB │ +│ 2 │ 2024-11-18T09:30:54Z │ Anahi Braun │ │ Mumblecore salvia mumblecore austin tofu viral asymmetrical small batch distillery you probably haven't heard of them. │ 4.2 MB │ ├────┼──────────────────────┼───────────────────┼────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────┤ -│ 4 │ 2024-11-18T09:30:54Z │ Brando Barton │ │ Before they sold out jean shorts chartreuse neutra fixie flexitarian goth art party small batch sriracha. │ 4.2 MB │ -├────┴──────────────────────┴───────────────────┴────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴────────┤ -│ AAMkADdiOWM1OTBkLTBhZjEtNGFiNS1hOGYwLTY2YWFmOGQyNTMxNgBGAAAAAADBju3TxrP2SZIsqjNb8hmoBwA9J0gY/4/nQ73Lmp9F9NoaAABlJ281AAA9J0gY/4/nQ73Lmp9F9NoaAABlJ6bLAAA= │ -└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘`) +│ 3 │ 2024-11-18T09:30:54Z │ Brando Barton │ │ Before they sold out jean shorts chartreuse neutra fixie flexitarian goth art party small batch sriracha. │ 4.2 MB │ +├────┼──────────────────────┴───────────────────┴────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴────────┤ +│ 4 │ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 │ +└────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘`) }) } diff --git a/table/render_init.go b/table/render_init.go index 071c98b..333c398 100644 --- a/table/render_init.go +++ b/table/render_init.go @@ -72,12 +72,6 @@ func (t *Table) extractMaxColumnLengthsFromRow(row rowStr, mci mergedColumnIndic startIndexMap = make(map[int]int) t.maxMergedColumnLengths[mergeEndIndex] = startIndexMap } - for index := colIdx + 1; index <= mergeEndIndex; index++ { - maxColWidth := t.getColumnWidthMax(index) - if maxColWidth > 0 && maxColWidth < longestLineLen { - longestLineLen = maxColWidth - } - } if longestLineLen > startIndexMap[colIdx] { startIndexMap[colIdx] = longestLineLen } @@ -88,13 +82,13 @@ func (t *Table) extractMaxColumnLengthsFromRow(row rowStr, mci mergedColumnIndic } } -// Try to rebalance the merged column lengths across all columns -// We rebalance from the lowest end index to the highest, -// and within that set from the highest start index to the lowest. -// We distribute the length across the columns not already exceeding -// the average. -func (t *Table) rebalanceMaxMergedColumnLengths() { +// reBalanceMaxMergedColumnLengths tries to re-balance the merged column lengths +// across all columns. It does this from the lowest end index to the highest, +// and within that set from the highest start index to the lowest. It +// distributes the length across the columns not already exceeding the average. +func (t *Table) reBalanceMaxMergedColumnLengths() { endIndexKeys, startIndexKeysMap := getSortedKeys(t.maxMergedColumnLengths) + middleSepLen := text.StringWidthWithoutEscSequences(t.style.Box.MiddleSeparator) for _, endIndexKey := range endIndexKeys { startIndexKeys := startIndexKeysMap[endIndexKey] for idx := len(startIndexKeys) - 1; idx >= 0; idx-- { @@ -103,13 +97,13 @@ func (t *Table) rebalanceMaxMergedColumnLengths() { for index := startIndexKey; index <= endIndexKey; index++ { columnBalanceMap[index] = struct{}{} } - mergedColumnLength := t.maxMergedColumnLengths[endIndexKey][startIndexKey] - (len(columnBalanceMap)-1)*text.StringWidthWithoutEscSequences(t.style.Box.MiddleSeparator) + mergedColumnLength := t.maxMergedColumnLengths[endIndexKey][startIndexKey] - + ((len(columnBalanceMap) - 1) * middleSepLen) // keep reducing the set of columns until the remainder are the ones less than // the average of the remaining length (total merged length - all lengths > average) for { - // If mergedColumnLength is zero or less then we already exceed the merged length - if mergedColumnLength <= 0 { + if mergedColumnLength <= 0 { // already exceeded the merged length columnBalanceMap = map[int]struct{}{} break } @@ -118,7 +112,6 @@ func (t *Table) rebalanceMaxMergedColumnLengths() { mapReduced := false for mergedColumn := range columnBalanceMap { maxColumnLength := t.maxColumnLengths[mergedColumn] - // If column is already greater then remove from the map and reduce the amount to rebalance if maxColumnLength >= maxLengthSplitAcrossColumns { mapReduced = true mergedColumnLength -= maxColumnLength @@ -129,9 +122,10 @@ func (t *Table) rebalanceMaxMergedColumnLengths() { break } } - // Do we still have any columns to balance? + + // act on any remaining columns that need balancing if len(columnBalanceMap) > 0 { - // remove the max column sizes from the remaining amount to balance, we then + // remove the max column sizes from the remaining amount to balance, then // share out the remainder amongst the columns. numRebalancedColumns := len(columnBalanceMap) balanceColumns := make([]int, 0, numRebalancedColumns) @@ -213,7 +207,7 @@ func (t *Table) initForRenderColumnLengths() { t.maxColumnLengths[colIdx] = minWidth } } - t.rebalanceMaxMergedColumnLengths() + t.reBalanceMaxMergedColumnLengths() } func (t *Table) initForRenderHideColumns() {