Skip to content

Modern Docker Management, Designed for Everyone

fix(cli): update table library and fix column header alignment

Kyle Mendella83d6108e0dd
diff --git a/cli/go.mod b/cli/go.mod
index 146c51627..ab06a7e9c 100644
--- a/cli/go.mod
+++ b/cli/go.mod
@@ -6,7 +6,7 @@ require (
github.com/charmbracelet/fang v0.4.4
github.com/fatih/color v1.18.0
github.com/getarcaneapp/arcane/types v0.0.0-20251219045603-8a9960a2bf04
- github.com/olekukonko/tablewriter v0.0.5
+ github.com/rodaine/table v1.3.0
github.com/schollz/progressbar/v3 v3.19.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.10.2
diff --git a/cli/go.sum b/cli/go.sum
index 2ade745e5..41a4f0495 100644
--- a/cli/go.sum
+++ b/cli/go.sum
@@ -50,6 +50,7 @@ github.com/getarcaneapp/arcane/types v0.0.0-20251219045603-8a9960a2bf04 h1:ufDqw
github.com/getarcaneapp/arcane/types v0.0.0-20251219045603-8a9960a2bf04/go.mod h1:7Wj+0JnpYq4RQS+otyM6e4zkyJKDC01wxkWPyFCHwZA=
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
+github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
@@ -67,7 +68,7 @@ github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHP
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
-github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
+github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-runewidth v0.0.19 h1:v++JhqYnZuu5jSKrk9RbgF5v4CGUjqRfBm05byFGLdw=
github.com/mattn/go-runewidth v0.0.19/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=
github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk=
@@ -86,8 +87,6 @@ github.com/muesli/mango-pflag v0.1.0 h1:UADqbYgpUyRoBja3g6LUL+3LErjpsOwaC9ywvBWe
github.com/muesli/mango-pflag v0.1.0/go.mod h1:YEQomTxaCUp8PrbhFh10UfbhbQrM/xJ4i2PB8VTLLW0=
github.com/muesli/roff v0.1.0 h1:YD0lalCotmYuF5HhZliKWlIx7IEhiXeSfq7hNjFqGF8=
github.com/muesli/roff v0.1.0/go.mod h1:pjAHQM9hdUUwm/krAfrLGgJkXJ+YuhtsfZ42kieB2Ig=
-github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
-github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040=
@@ -96,8 +95,11 @@ github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsK
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+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/rodaine/table v1.3.0 h1:4/3S3SVkHnVZX91EHFvAMV7K42AnJ0XuymRR2C5HlGE=
+github.com/rodaine/table v1.3.0/go.mod h1:47zRsHar4zw0jgxGxL9YtFfs7EGN6B/TaS+/Dmk4WxU=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
@@ -112,7 +114,14 @@ github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
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.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+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/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
+github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/xhit/go-str2duration/v2 v2.1.0 h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8Ydu2Bstc=
diff --git a/cli/internal/output/output.go b/cli/internal/output/output.go
index e085a4542..6135623ae 100644
--- a/cli/internal/output/output.go
+++ b/cli/internal/output/output.go
@@ -14,10 +14,11 @@ package output
import (
"fmt"
- "os"
+ "regexp"
+ "strings"
"github.com/fatih/color"
- "github.com/olekukonko/tablewriter"
+ "github.com/mattn/go-runewidth"
)
var (
@@ -28,6 +29,8 @@ var (
headerColor = color.New(color.FgHiWhite, color.Bold).SprintFunc()
)
+var ansiRegexp = regexp.MustCompile("\x1b\\[[0-9;]*[a-zA-Z]")
+
// Success prints a success message in green.
// The message is prefixed with a newline for visual separation.
// Format specifiers and arguments work like fmt.Printf.
@@ -76,32 +79,118 @@ func KeyValue(key string, value interface{}) {
fmt.Printf("%s: %v\n", color.New(color.Bold).Sprint(key), color.New(color.FgBlue).Sprint(value))
}
+func stripAnsi(s string) string {
+ if s == "" {
+ return s
+ }
+ return ansiRegexp.ReplaceAllString(s, "")
+}
+
// Table prints a formatted table with headers and rows.
-// Headers are displayed in bold cyan. The table is rendered without borders
+// Headers are displayed in bold cyan. The table is rendered with borders
// for a clean terminal appearance. Columns are automatically aligned.
func Table(headers []string, rows [][]string) {
fmt.Println()
- table := tablewriter.NewWriter(os.Stdout)
- table.SetHeader(headers)
- table.SetAutoWrapText(false)
- table.SetAutoFormatHeaders(true)
- table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
- table.SetAlignment(tablewriter.ALIGN_LEFT)
- table.SetCenterSeparator("")
- table.SetColumnSeparator("")
- table.SetRowSeparator("")
- table.SetHeaderLine(false)
- table.SetBorder(false)
- table.SetTablePadding(" ") // pad with spaces
- table.SetNoWhiteSpace(false)
-
- // Set header colors
- headerColors := make([]tablewriter.Colors, len(headers))
- for i := range headerColors {
- headerColors[i] = tablewriter.Colors{tablewriter.Bold, tablewriter.FgHiCyanColor}
+
+ n := len(headers)
+ if n == 0 {
+ return
+ }
+
+ // Compute display widths for each column (strip ANSI sequences when measuring)
+ widths := make([]int, n)
+ for i, h := range headers {
+ w := runewidth.StringWidth(stripAnsi(h))
+ widths[i] = w
+ }
+
+ for _, row := range rows {
+ for i := 0; i < n; i++ {
+ var cell string
+ if i < len(row) {
+ cell = row[i]
+ } else {
+ cell = ""
+ }
+ // consider multiline cells; take widest line
+ lines := strings.Split(cell, "\n")
+ for _, ln := range lines {
+ w := runewidth.StringWidth(stripAnsi(ln))
+ if w > widths[i] {
+ widths[i] = w
+ }
+ }
+ }
}
- table.SetHeaderColor(headerColors...)
- table.AppendBulk(rows)
- table.Render()
+ // Formatters
+ headerFmt := color.New(color.Bold, color.FgHiCyan).SprintFunc()
+ columnFmt := color.New(color.FgYellow).SprintFunc()
+ sep := " "
+
+ // Print header line
+ for i, h := range headers {
+ visible := stripAnsi(h)
+ colored := headerFmt(h)
+ padLen := widths[i] - runewidth.StringWidth(visible)
+ if padLen < 0 {
+ padLen = 0
+ }
+ if i < n-1 {
+ fmt.Print(colored + strings.Repeat(" ", padLen) + sep)
+ } else {
+ fmt.Print(colored + strings.Repeat(" ", padLen))
+ }
+ }
+ fmt.Println()
+
+ // Print each row, supporting multiline cells
+ for _, row := range rows {
+ // Prepare lines per column
+ cellLines := make([][]string, n)
+ maxLines := 1
+ for i := 0; i < n; i++ {
+ var cell string
+ if i < len(row) {
+ cell = row[i]
+ } else {
+ cell = ""
+ }
+ lines := strings.Split(cell, "\n")
+ cellLines[i] = lines
+ if len(lines) > maxLines {
+ maxLines = len(lines)
+ }
+ }
+
+ for li := 0; li < maxLines; li++ {
+ for i := 0; i < n; i++ {
+ var val string
+ if li < len(cellLines[i]) {
+ val = cellLines[i][li]
+ } else {
+ val = ""
+ }
+
+ var rendered string
+ if i == 0 {
+ rendered = columnFmt(val)
+ } else {
+ rendered = fmt.Sprint(val)
+ }
+
+ padLen := widths[i] - runewidth.StringWidth(stripAnsi(val))
+ if padLen < 0 {
+ padLen = 0
+ }
+
+ if i < n-1 {
+ fmt.Print(rendered + strings.Repeat(" ", padLen) + sep)
+ } else {
+ fmt.Print(rendered + strings.Repeat(" ", padLen))
+ }
+ }
+ fmt.Println()
+ }
+ }
}