Skip to content

Commit

Permalink
Use lipgloss to render available workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
antham committed Apr 28, 2024
1 parent b157c42 commit 2d8621f
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions cmd/list.go
Original file line number Diff line number Diff line change
@@ -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"
)

Expand All @@ -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
},
}
Expand Down

0 comments on commit 2d8621f

Please sign in to comment.