working table :)

This commit is contained in:
Anish Lakhwara 2024-02-27 00:30:21 -08:00
parent f0a4366bc2
commit 9f7105f6b8

25
main.go
View file

@ -10,13 +10,15 @@ import (
"github.com/charmbracelet/bubbles/table"
"github.com/charmbracelet/lipgloss"
"os"
// "unsafe"
"strconv"
"strings"
)
// Task representation.
type Task struct {
Id int32 `json:"id"`
Id int `json:"id"`
Description string `json:"description"`
Tags []string `json:"tags"`
Project string `json:"project"`
Status string `json:"status"`
Uuid string `json:"uuid"`
@ -85,27 +87,24 @@ func main() {
})
columns := []table.Column{
{Title: "Rank", Width: 4},
{Title: "City", Width: 10},
{Title: "Country", Width: 10},
{Title: "Population", Width: 10},
{Title: "ID", Width: 4},
{Title: "Project", Width: 10},
{Title: "Tags", Width: 10},
{Title: "Description", Width: 50},
// {Title: "Urgency", Width: 10},
}
// rows := *(*[]table.Row)(unsafe.Pointer(&tasks))
rows := make([]table.Row, len(tasks))
for i := 0; i < len(tasks); i++ {
jsonBytes, err := json.Marshal(tasks[i])
if err != nil {
log.Fatalf("Error marshaling struct: %v", err)
}
rows[i] = string(jsonBytes)
t := tasks[i]
rows[i] = []string{strconv.Itoa(t.Id), t.Project, strings.Join(t.Tags[:], " "), t.Description} // fmt.Sprintf("%f", t.Urgency)
}
t := table.New(
table.WithColumns(columns),
table.WithRows(rows),
table.WithFocused(true),
table.WithHeight(7),
table.WithHeight(20),
)
s := table.DefaultStyles()