From e3823c29bfa2c0dd34046312fedaec94bd40a6ec Mon Sep 17 00:00:00 2001 From: Pasha Sviderski Date: Thu, 18 Jun 2026 20:29:22 +1000 Subject: [PATCH] cli: strip ANSI sequences (colors, styles) from table output when stdout is not a TTY --- cmd/uncloud/context/ls.go | 3 ++- cmd/uncloud/image/ls.go | 2 +- cmd/uncloud/machine/ls.go | 3 ++- cmd/uncloud/machine/rm.go | 2 +- cmd/uncloud/machine/rtt.go | 3 ++- cmd/uncloud/ps.go | 2 +- cmd/uncloud/service/inspect.go | 3 ++- cmd/uncloud/service/ls.go | 3 ++- cmd/uncloud/volume/ls.go | 3 ++- cmd/uncloud/wg/wg.go | 3 ++- 10 files changed, 17 insertions(+), 10 deletions(-) diff --git a/cmd/uncloud/context/ls.go b/cmd/uncloud/context/ls.go index 2d4d4050..0a843b8c 100644 --- a/cmd/uncloud/context/ls.go +++ b/cmd/uncloud/context/ls.go @@ -5,6 +5,7 @@ import ( "maps" "slices" + "charm.land/lipgloss/v2" "github.com/psviderski/uncloud/internal/cli" "github.com/psviderski/uncloud/internal/cli/tui" "github.com/spf13/cobra" @@ -50,6 +51,6 @@ func list(uncli *cli.CLI) error { t.Row(name, current, fmt.Sprintf("%d", connCount)) } - fmt.Println(t) + lipgloss.Println(t) return nil } diff --git a/cmd/uncloud/image/ls.go b/cmd/uncloud/image/ls.go index 7c3edb6e..e725fe86 100644 --- a/cmd/uncloud/image/ls.go +++ b/cmd/uncloud/image/ls.go @@ -179,7 +179,7 @@ func list(ctx context.Context, uncli *cli.CLI, opts listOptions) error { }) // Print the images in a table format. - fmt.Println(formatImageTable(rows)) + lipgloss.Println(formatImageTable(rows)) return nil } diff --git a/cmd/uncloud/machine/ls.go b/cmd/uncloud/machine/ls.go index e04c15d8..bb12cc8b 100644 --- a/cmd/uncloud/machine/ls.go +++ b/cmd/uncloud/machine/ls.go @@ -6,6 +6,7 @@ import ( "net/netip" "strings" + "charm.land/lipgloss/v2" "github.com/psviderski/uncloud/internal/cli" "github.com/psviderski/uncloud/internal/cli/tui" "github.com/psviderski/uncloud/internal/machine/network" @@ -68,7 +69,7 @@ func list(ctx context.Context, uncli *cli.CLI) error { ) } - fmt.Println(t) + lipgloss.Println(t) return nil } diff --git a/cmd/uncloud/machine/rm.go b/cmd/uncloud/machine/rm.go index 181929ed..05bcc9f2 100644 --- a/cmd/uncloud/machine/rm.go +++ b/cmd/uncloud/machine/rm.go @@ -114,7 +114,7 @@ func remove(ctx context.Context, uncli *cli.CLI, nameOrID string, opts removeOpt plural = "s" } fmt.Printf("Found %d service container%s on machine '%s':\n", len(containers), plural, m.Name) - fmt.Println(formatContainerTree(containers)) + lipgloss.Println(formatContainerTree(containers)) fmt.Println() fmt.Println("This will remove all service containers from the machine, remove it from the cluster, " + "and reset it to the uninitialised state.") diff --git a/cmd/uncloud/machine/rtt.go b/cmd/uncloud/machine/rtt.go index 387ba212..ce662409 100644 --- a/cmd/uncloud/machine/rtt.go +++ b/cmd/uncloud/machine/rtt.go @@ -6,6 +6,7 @@ import ( "sort" "time" + "charm.land/lipgloss/v2" "github.com/psviderski/uncloud/internal/cli" "github.com/psviderski/uncloud/internal/cli/tui" "github.com/spf13/cobra" @@ -107,7 +108,7 @@ func rtt(ctx context.Context, uncli *cli.CLI) error { t.Row(r.machine, r.peer, tui.FormatRTT(r.median), formatRTTStdDev(r.stdDev)) } - fmt.Println(t) + lipgloss.Println(t) return nil } diff --git a/cmd/uncloud/ps.go b/cmd/uncloud/ps.go index 5d5927b4..00f663b9 100644 --- a/cmd/uncloud/ps.go +++ b/cmd/uncloud/ps.go @@ -182,7 +182,7 @@ func printContainers(containers []containerInfo) error { } } - fmt.Println(t) + lipgloss.Println(t) return nil } diff --git a/cmd/uncloud/service/inspect.go b/cmd/uncloud/service/inspect.go index 3364c563..c7500c9a 100644 --- a/cmd/uncloud/service/inspect.go +++ b/cmd/uncloud/service/inspect.go @@ -6,6 +6,7 @@ import ( "slices" "time" + "charm.land/lipgloss/v2" "github.com/docker/docker/pkg/stringid" "github.com/docker/go-units" "github.com/psviderski/uncloud/internal/cli" @@ -126,6 +127,6 @@ func inspect(ctx context.Context, uncli *cli.CLI, opts inspectOptions) error { } } - fmt.Println(t) + lipgloss.Println(t) return nil } diff --git a/cmd/uncloud/service/ls.go b/cmd/uncloud/service/ls.go index 1ccca21f..17523b80 100644 --- a/cmd/uncloud/service/ls.go +++ b/cmd/uncloud/service/ls.go @@ -6,6 +6,7 @@ import ( "slices" "strings" + "charm.land/lipgloss/v2" "github.com/psviderski/uncloud/internal/cli" "github.com/psviderski/uncloud/internal/cli/tui" "github.com/psviderski/uncloud/pkg/api" @@ -82,6 +83,6 @@ func list(ctx context.Context, uncli *cli.CLI) error { t.Row(row...) } - fmt.Println(t) + lipgloss.Println(t) return nil } diff --git a/cmd/uncloud/volume/ls.go b/cmd/uncloud/volume/ls.go index e6b6d343..f9497430 100644 --- a/cmd/uncloud/volume/ls.go +++ b/cmd/uncloud/volume/ls.go @@ -6,6 +6,7 @@ import ( "slices" "strings" + "charm.land/lipgloss/v2" "github.com/psviderski/uncloud/internal/cli" "github.com/psviderski/uncloud/internal/cli/completion" "github.com/psviderski/uncloud/internal/cli/tui" @@ -95,6 +96,6 @@ func list(ctx context.Context, uncli *cli.CLI, opts listOptions) error { t.Row(v.Volume.Name, v.Volume.Driver, v.MachineName) } - fmt.Println(t) + lipgloss.Println(t) return nil } diff --git a/cmd/uncloud/wg/wg.go b/cmd/uncloud/wg/wg.go index df052e4c..902a1d3d 100644 --- a/cmd/uncloud/wg/wg.go +++ b/cmd/uncloud/wg/wg.go @@ -6,6 +6,7 @@ import ( "strings" "time" + "charm.land/lipgloss/v2" "github.com/docker/go-units" "github.com/psviderski/uncloud/internal/cli" "github.com/psviderski/uncloud/internal/cli/completion" @@ -133,6 +134,6 @@ func runShow(ctx context.Context, uncli *cli.CLI, opts showOptions) error { ) } - fmt.Println(t) + lipgloss.Println(t) return nil }