From 2d8621f6df0c6db3dba95c98a707c313aa76d476 Mon Sep 17 00:00:00 2001 From: Anthony HAMON Date: Mon, 29 Apr 2024 01:10:31 +0200 Subject: [PATCH] Use lipgloss to render available workspaces --- cmd/list.go | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/cmd/list.go b/cmd/list.go index 9bb3b77..fce7fd5 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -1,11 +1,11 @@ package cmd import ( - "cmp" "fmt" - "slices" "github.com/antham/wo/workspace" + "github.com/charmbracelet/lipgloss" + "github.com/charmbracelet/lipgloss/table" "github.com/spf13/cobra" ) @@ -23,12 +23,29 @@ var lsCmd = &cobra.Command{ if err != nil { return err } - slices.SortFunc(workspaces, func(a, b workspace.Workspace) int { - return cmp.Compare(a.Name, b.Name) - }) + wss := []string{} + workspaceRowTableSize := 11 for _, w := range workspaces { - fmt.Println(w.Name) + if len(w.Name)+1 > workspaceRowTableSize { + workspaceRowTableSize = len(w.Name) + 1 + } + wss = append(wss, w.Name) } + ws := table.New(). + Border(lipgloss.NormalBorder()). + BorderStyle(lipgloss.NewStyle().Foreground(lipgloss.Color("#C683D7"))). + Headers("Workspaces"). + StyleFunc(func(row, col int) lipgloss.Style { + var style lipgloss.Style + switch { + case row == 0: + style = style.Bold(true).Foreground(lipgloss.Color("#C683D7")) + } + style = style.Copy().Width(workspaceRowTableSize) + return style + }). + Rows([][]string{wss}...) + fmt.Println(ws) return nil }, }