Initial giu version, not very good looking, maybe prefer CharmBracelet Tea
This commit is contained in:
93
cmd/sqv-giu/main.go
Normal file
93
cmd/sqv-giu/main.go
Normal file
@@ -0,0 +1,93 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
engine "git.pablu.de/pablu/sqv-engine"
|
||||
g "github.com/AllenDang/giu"
|
||||
)
|
||||
|
||||
type Test struct {
|
||||
tables []engine.Table
|
||||
enabled []bool
|
||||
}
|
||||
|
||||
func (t *Test) loop() {
|
||||
tableMenuItems := make([]g.Widget, len(t.tables))
|
||||
|
||||
for i, table := range t.tables {
|
||||
tableMenuItems[i] = g.MenuItem(table.Name).OnClick(func() {
|
||||
t.enabled[i] = !t.enabled[i]
|
||||
})
|
||||
}
|
||||
|
||||
g.MainMenuBar().Layout(
|
||||
g.Menu("Tables").Layout(
|
||||
tableMenuItems...,
|
||||
),
|
||||
).Build()
|
||||
|
||||
for i, table := range t.tables {
|
||||
if t.enabled[i] {
|
||||
g.Window(table.Name).Layout(
|
||||
SqlTable(table),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func SqlTable(table engine.Table) *g.TableWidget {
|
||||
tableColumns := make([]*g.TableColumnWidget, 0)
|
||||
for _, column := range table.Columns {
|
||||
tableColumns = append(tableColumns, g.TableColumn(column.Name))
|
||||
}
|
||||
|
||||
tableRows := make([]*g.TableRowWidget, 0)
|
||||
for _, row := range table.Rows {
|
||||
tableRows = append(tableRows, SqlValueRow(row))
|
||||
}
|
||||
|
||||
return g.Table().Columns(
|
||||
tableColumns...,
|
||||
).Rows(tableRows...)
|
||||
}
|
||||
|
||||
func SqlValueRow(row engine.Row) *g.TableRowWidget {
|
||||
v := make([]g.Widget, 0)
|
||||
for _, values := range row.Values {
|
||||
v = append(v, g.Label(values))
|
||||
}
|
||||
|
||||
return g.TableRow(v...)
|
||||
}
|
||||
|
||||
func main() {
|
||||
wnd := g.NewMasterWindow("SQV", 800, 600, 0)
|
||||
|
||||
//nolint:gocritic // should be here for doc
|
||||
// errMarkers = imgui.NewErrorMarkers()
|
||||
file, err := os.ReadFile("test.sql")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
m := engine.NewManagerFromFile(string(file))
|
||||
if err := m.Start(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
t := Test{
|
||||
tables: m.GetTables(),
|
||||
enabled: make([]bool, len(m.GetTables())),
|
||||
}
|
||||
|
||||
t.tables[2].Rows = []engine.Row{
|
||||
engine.Row{
|
||||
Values: []string{
|
||||
"HELLO", "WORLD", "!",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
wnd.Run(t.loop)
|
||||
}
|
||||
Reference in New Issue
Block a user