diff --git a/cmd/uncloud/caddy/deploy.go b/cmd/uncloud/caddy/deploy.go index c0e1d77c..8cdcb12f 100644 --- a/cmd/uncloud/caddy/deploy.go +++ b/cmd/uncloud/caddy/deploy.go @@ -88,12 +88,12 @@ func runDeploy(ctx context.Context, uncli *cli.CLI, opts deployOptions) error { if len(currentImages) > 1 { formattedImages := make([]string, len(currentImages)) for i, img := range currentImages { - formattedImages[i] = tui.FormatImage(img, lipgloss.NewStyle()) + formattedImages[i] = tui.FormatImage(img, tui.NoStyle) } fmt.Println(tui.Faint.Render("current images (multiple versions detected): ") + strings.Join(formattedImages, tui.Faint.Render(", "))) } else { - fmt.Println(tui.Faint.Render("current image: ") + tui.FormatImage(currentImages[0], lipgloss.NewStyle())) + fmt.Println(tui.Faint.Render("current image: ") + tui.FormatImage(currentImages[0], tui.NoStyle)) } } diff --git a/cmd/uncloud/image/ls.go b/cmd/uncloud/image/ls.go index 31ff1ebc..91e6dd82 100644 --- a/cmd/uncloud/image/ls.go +++ b/cmd/uncloud/image/ls.go @@ -10,13 +10,13 @@ import ( "time" "charm.land/lipgloss/v2" - "charm.land/lipgloss/v2/table" "github.com/charmbracelet/colorprofile" "github.com/containerd/platforms" "github.com/docker/docker/api/types/image" "github.com/docker/go-units" "github.com/psviderski/uncloud/internal/cli" + "github.com/psviderski/uncloud/internal/cli/tui" "github.com/psviderski/uncloud/pkg/api" "github.com/spf13/cobra" ) @@ -260,22 +260,7 @@ func formatImageTable(rows []imageRow) string { columns[5].hide = true } - t := table.New(). - // Remove the default border. - Border(lipgloss.Border{}). - BorderTop(false). - BorderBottom(false). - BorderLeft(false). - BorderRight(false). - BorderHeader(false). - BorderColumn(false). - StyleFunc(func(row, col int) lipgloss.Style { - if row == table.HeaderRow { - return lipgloss.NewStyle().Bold(true).PaddingRight(3) - } - // Regular style for data rows with padding. - return lipgloss.NewStyle().PaddingRight(3) - }) + t := tui.NewTable() var headers []string for _, col := range columns { @@ -288,7 +273,7 @@ func formatImageTable(rows []imageRow) string { for _, row := range rows { values := []string{ row.id, - row.name, + tui.FormatImage(row.name, tui.NoStyle), row.platforms, row.createdHuman, row.size, diff --git a/cmd/uncloud/ps.go b/cmd/uncloud/ps.go index 6154724a..7dcb9a38 100644 --- a/cmd/uncloud/ps.go +++ b/cmd/uncloud/ps.go @@ -8,7 +8,6 @@ import ( "charm.land/huh/v2/spinner" "charm.land/lipgloss/v2" - "charm.land/lipgloss/v2/table" "github.com/docker/docker/api/types/container" "github.com/docker/go-units" "github.com/psviderski/uncloud/internal/cli/tui" @@ -132,23 +131,7 @@ func runPs(ctx context.Context, uncli *cli.CLI, opts psOptions) error { } func printContainers(containers []containerInfo) error { - t := table.New(). - // Remove the default border. - Border(lipgloss.Border{}). - BorderTop(false). - BorderBottom(false). - BorderLeft(false). - BorderRight(false). - BorderHeader(false). - BorderColumn(false). - StyleFunc(func(row, col int) lipgloss.Style { - if row == table.HeaderRow { - return lipgloss.NewStyle().Bold(true).PaddingRight(3) - } - // Regular style for data rows with padding. - return lipgloss.NewStyle().PaddingRight(3) - }) - + t := tui.NewTable() t.Headers("SERVICE", "CONTAINER ID", "CONTAINER NAME", "IMAGE", "CREATED", "STATUS", "IP ADDRESS", "MACHINE") for _, ctr := range containers { @@ -175,7 +158,7 @@ func printContainers(containers []containerInfo) error { ctr.serviceName, id, ctr.name, - ctr.image, + tui.FormatImage(ctr.image, tui.NoStyle), created, statusStyle.Render(ctr.status), ctr.ip, diff --git a/internal/cli/tui/style.go b/internal/cli/tui/style.go index f5bed0db..523b5486 100644 --- a/internal/cli/tui/style.go +++ b/internal/cli/tui/style.go @@ -6,6 +6,8 @@ import ( ) var ( + NoStyle = lipgloss.NewStyle() + Faint = lipgloss.NewStyle().Faint(true) Red = lipgloss.NewStyle().Foreground(lipgloss.Red) Green = lipgloss.NewStyle().Foreground(lipgloss.Green) diff --git a/internal/cli/tui/table.go b/internal/cli/tui/table.go new file mode 100644 index 00000000..bf9cf35e --- /dev/null +++ b/internal/cli/tui/table.go @@ -0,0 +1,24 @@ +package tui + +import ( + "charm.land/lipgloss/v2" + "charm.land/lipgloss/v2/table" +) + +// NewTable creates a borderless table with bold headers and consistent padding for CLI output. +func NewTable() *table.Table { + return table.New(). + Border(lipgloss.Border{}). + BorderTop(false). + BorderBottom(false). + BorderLeft(false). + BorderRight(false). + BorderHeader(false). + BorderColumn(false). + StyleFunc(func(row, col int) lipgloss.Style { + if row == table.HeaderRow { + return Bold.PaddingRight(3) + } + return NoStyle.PaddingRight(3) + }) +} diff --git a/pkg/client/deploy/deploy.go b/pkg/client/deploy/deploy.go index b8779b07..207c0840 100644 --- a/pkg/client/deploy/deploy.go +++ b/pkg/client/deploy/deploy.go @@ -114,7 +114,7 @@ func (sp *ServicePlan) Format() string { if sp.IsNewService { specTable.Row("", "image:", tui.FormatImage(sp.Spec.Container.Image, tui.Green)) } else { - specTable.Row("", "image:", tui.FormatImage(sp.Spec.Container.Image, lipgloss.NewStyle())) + specTable.Row("", "image:", tui.FormatImage(sp.Spec.Container.Image, tui.NoStyle)) } } else { mod := "" @@ -233,7 +233,7 @@ func formatImageDiff(oldImage, newImage string) string { } if oldImage == newImage { - return tui.FormatImage(newImage, lipgloss.NewStyle()) + return tui.FormatImage(newImage, tui.NoStyle) } oldRef, _ := reference.ParseDockerRef(oldImage)