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