Skip to content

Commit e3823c2

Browse files
committed
cli: strip ANSI sequences (colors, styles) from table output when stdout is not a TTY
1 parent 2f717a1 commit e3823c2

10 files changed

Lines changed: 17 additions & 10 deletions

File tree

‎cmd/uncloud/context/ls.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"maps"
66
"slices"
77

8+
"charm.land/lipgloss/v2"
89
"github.com/psviderski/uncloud/internal/cli"
910
"github.com/psviderski/uncloud/internal/cli/tui"
1011
"github.com/spf13/cobra"
@@ -50,6 +51,6 @@ func list(uncli *cli.CLI) error {
5051
t.Row(name, current, fmt.Sprintf("%d", connCount))
5152
}
5253

53-
fmt.Println(t)
54+
lipgloss.Println(t)
5455
return nil
5556
}

‎cmd/uncloud/image/ls.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func list(ctx context.Context, uncli *cli.CLI, opts listOptions) error {
179179
})
180180

181181
// Print the images in a table format.
182-
fmt.Println(formatImageTable(rows))
182+
lipgloss.Println(formatImageTable(rows))
183183

184184
return nil
185185
}

‎cmd/uncloud/machine/ls.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/netip"
77
"strings"
88

9+
"charm.land/lipgloss/v2"
910
"github.com/psviderski/uncloud/internal/cli"
1011
"github.com/psviderski/uncloud/internal/cli/tui"
1112
"github.com/psviderski/uncloud/internal/machine/network"
@@ -68,7 +69,7 @@ func list(ctx context.Context, uncli *cli.CLI) error {
6869
)
6970
}
7071

71-
fmt.Println(t)
72+
lipgloss.Println(t)
7273
return nil
7374
}
7475

‎cmd/uncloud/machine/rm.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func remove(ctx context.Context, uncli *cli.CLI, nameOrID string, opts removeOpt
114114
plural = "s"
115115
}
116116
fmt.Printf("Found %d service container%s on machine '%s':\n", len(containers), plural, m.Name)
117-
fmt.Println(formatContainerTree(containers))
117+
lipgloss.Println(formatContainerTree(containers))
118118
fmt.Println()
119119
fmt.Println("This will remove all service containers from the machine, remove it from the cluster, " +
120120
"and reset it to the uninitialised state.")

‎cmd/uncloud/machine/rtt.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"sort"
77
"time"
88

9+
"charm.land/lipgloss/v2"
910
"github.com/psviderski/uncloud/internal/cli"
1011
"github.com/psviderski/uncloud/internal/cli/tui"
1112
"github.com/spf13/cobra"
@@ -107,7 +108,7 @@ func rtt(ctx context.Context, uncli *cli.CLI) error {
107108
t.Row(r.machine, r.peer, tui.FormatRTT(r.median), formatRTTStdDev(r.stdDev))
108109
}
109110

110-
fmt.Println(t)
111+
lipgloss.Println(t)
111112
return nil
112113
}
113114

‎cmd/uncloud/ps.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func printContainers(containers []containerInfo) error {
182182
}
183183
}
184184

185-
fmt.Println(t)
185+
lipgloss.Println(t)
186186
return nil
187187
}
188188

‎cmd/uncloud/service/inspect.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"slices"
77
"time"
88

9+
"charm.land/lipgloss/v2"
910
"github.com/docker/docker/pkg/stringid"
1011
"github.com/docker/go-units"
1112
"github.com/psviderski/uncloud/internal/cli"
@@ -126,6 +127,6 @@ func inspect(ctx context.Context, uncli *cli.CLI, opts inspectOptions) error {
126127
}
127128
}
128129

129-
fmt.Println(t)
130+
lipgloss.Println(t)
130131
return nil
131132
}

‎cmd/uncloud/service/ls.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"slices"
77
"strings"
88

9+
"charm.land/lipgloss/v2"
910
"github.com/psviderski/uncloud/internal/cli"
1011
"github.com/psviderski/uncloud/internal/cli/tui"
1112
"github.com/psviderski/uncloud/pkg/api"
@@ -82,6 +83,6 @@ func list(ctx context.Context, uncli *cli.CLI) error {
8283
t.Row(row...)
8384
}
8485

85-
fmt.Println(t)
86+
lipgloss.Println(t)
8687
return nil
8788
}

‎cmd/uncloud/volume/ls.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"slices"
77
"strings"
88

9+
"charm.land/lipgloss/v2"
910
"github.com/psviderski/uncloud/internal/cli"
1011
"github.com/psviderski/uncloud/internal/cli/completion"
1112
"github.com/psviderski/uncloud/internal/cli/tui"
@@ -95,6 +96,6 @@ func list(ctx context.Context, uncli *cli.CLI, opts listOptions) error {
9596
t.Row(v.Volume.Name, v.Volume.Driver, v.MachineName)
9697
}
9798

98-
fmt.Println(t)
99+
lipgloss.Println(t)
99100
return nil
100101
}

‎cmd/uncloud/wg/wg.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"strings"
77
"time"
88

9+
"charm.land/lipgloss/v2"
910
"github.com/docker/go-units"
1011
"github.com/psviderski/uncloud/internal/cli"
1112
"github.com/psviderski/uncloud/internal/cli/completion"
@@ -133,6 +134,6 @@ func runShow(ctx context.Context, uncli *cli.CLI, opts showOptions) error {
133134
)
134135
}
135136

136-
fmt.Println(t)
137+
lipgloss.Println(t)
137138
return nil
138139
}

0 commit comments

Comments
 (0)