Skip to content

Commit f0bad8b

Browse files
committed
feat: use lipgloss table for ls commands
1 parent 98dd10c commit f0bad8b

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

cmd/ls.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
/*
2-
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
3-
*/
41
package cmd
52

63
import (
74
"fmt"
85
"moco/data"
96
"time"
107

8+
"github.com/charmbracelet/lipgloss"
9+
"github.com/charmbracelet/lipgloss/table"
1110
"github.com/spf13/cobra"
1211
)
1312

@@ -16,9 +15,13 @@ var projectCmd = &cobra.Command{
1615
Short: "List projects",
1716
Run: func(cmd *cobra.Command, args []string) {
1817
projects, _ := data.GetProjects()
18+
t := table.New().
19+
Border(lipgloss.NormalBorder()).
20+
Headers("ID", "Name")
1921
for _, project := range projects {
20-
fmt.Printf("%d %s\n", project.Id, project.Name)
22+
t.Row(fmt.Sprintf("%d", project.Id), project.GetName())
2123
}
24+
fmt.Println(t)
2225
},
2326
}
2427

@@ -28,25 +31,30 @@ var taskCmd = &cobra.Command{
2831
Run: func(cmd *cobra.Command, args []string) {
2932
projectId, err := cmd.Flags().GetInt("project")
3033

34+
t := table.New().
35+
Border(lipgloss.NormalBorder()).
36+
Headers("ID", "Name")
3137
if projectId != 0 && err == nil {
3238
project, err := data.GetProject(projectId)
3339
if err != nil {
3440
fmt.Println(err)
3541
return
3642
}
3743
for _, task := range project.Tasks {
38-
fmt.Printf("%d %s\n", task.Id, task.Name)
44+
t.Row(fmt.Sprintf("%d", task.Id), task.Name)
3945
}
46+
fmt.Println(t)
4047
return
4148
}
4249

4350
projects, _ := data.GetProjects()
4451
for _, project := range projects {
4552
tasks := project.Tasks
4653
for _, task := range tasks {
47-
fmt.Printf("%d %s\n", task.Id, task.Name)
54+
t.Row(fmt.Sprintf("%d", task.Id), task.Name)
4855
}
4956
}
57+
fmt.Println(t)
5058
},
5159
}
5260

@@ -56,6 +64,10 @@ var activityCmd = &cobra.Command{
5664
Run: func(cmd *cobra.Command, args []string) {
5765
activities, _ := data.GetActivities()
5866
today, _ := cmd.Flags().GetBool("today")
67+
t := table.New().
68+
Border(lipgloss.NormalBorder()).
69+
Headers("ID", "Date", "Time", "Description")
70+
5971
for _, activity := range activities {
6072
if !today || activity.Date == time.Now().Format("2006-01-02") {
6173
prefix := " "
@@ -66,9 +78,10 @@ var activityCmd = &cobra.Command{
6678
elapsed := time.Since(started).Round(time.Second)
6779
duration += elapsed
6880
}
69-
fmt.Printf("%s%d\t%s\t(%s)\n", prefix, activity.Id, activity.Description, duration.String())
81+
t.Row(fmt.Sprintf("%d", activity.Id), activity.Date, fmt.Sprintf("%s%s", prefix, duration.String()), activity.Description)
7082
}
7183
}
84+
fmt.Println(t)
7285
},
7386
}
7487

0 commit comments

Comments
 (0)