399 lines
8.9 KiB
Go
399 lines
8.9 KiB
Go
// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT.
|
|
// This file was autogenerated with autogenpb v0.5.6-2-gfabf425 2025-09-23_15:21:15_UTC
|
|
// go install go.wit.com/apps/autogenpb@latest
|
|
//
|
|
// define which structs (messages) you want to use in the .proto file
|
|
// Then sort.pb.go and marshal.pb.go files are autogenerated
|
|
//
|
|
// autogenpb uses it and has an example .proto file with instructions
|
|
//
|
|
|
|
package forgepb
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"go.wit.com/gui"
|
|
"go.wit.com/lib/protobuf/guipb"
|
|
"go.wit.com/log"
|
|
"google.golang.org/protobuf/proto"
|
|
anypb "google.golang.org/protobuf/types/known/anypb"
|
|
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
|
|
"google.golang.org/protobuf/types/known/wrapperspb"
|
|
)
|
|
|
|
// START GUI
|
|
|
|
func (x *Patches) NewTable(title string) *PatchesTable {
|
|
t := new(PatchesTable)
|
|
t.x = x
|
|
pb := new(guipb.Table)
|
|
pb.Title = title
|
|
t.pb = pb
|
|
return t
|
|
}
|
|
|
|
// force the application to choose the type of data. this allows the GUI plugin to be smarter
|
|
func (t *PatchesTable) AddStringFunc(title string, f func(*Patch) string) *PatchAnyFunc {
|
|
t.pb.Order = append(t.pb.Order, title)
|
|
|
|
sf := new(PatchAnyFunc)
|
|
sf.title = title
|
|
sf.f = func(x *Patch) any {
|
|
return f(x)
|
|
}
|
|
sf.attr = new(guipb.ColAttr)
|
|
sf.attr.Width = int32(sf.Width)
|
|
sf.attr.Type = guipb.ColAttr_STRING
|
|
|
|
t.anyFuncs = append(t.anyFuncs, sf)
|
|
return sf
|
|
}
|
|
|
|
// force the application to choose the type of data. this allows the GUI plugin to be smarter
|
|
func (t *PatchesTable) AddButtonFunc(title string, f func(*Patch) string) *PatchAnyFunc {
|
|
t.pb.Order = append(t.pb.Order, title)
|
|
|
|
sf := new(PatchAnyFunc)
|
|
sf.title = title
|
|
sf.f = func(x *Patch) any {
|
|
return f(x)
|
|
}
|
|
sf.attr = new(guipb.ColAttr)
|
|
sf.attr.Width = int32(sf.Width)
|
|
sf.attr.Type = guipb.ColAttr_STRING
|
|
sf.attr.Click = true
|
|
|
|
t.anyFuncs = append(t.anyFuncs, sf)
|
|
return sf
|
|
}
|
|
|
|
// force the application to choose the type of data. this allows the GUI plugin to be smarter
|
|
func (t *PatchesTable) AddIntFunc(title string, f func(*Patch) int) *PatchAnyFunc {
|
|
t.pb.Order = append(t.pb.Order, title)
|
|
|
|
sf := new(PatchAnyFunc)
|
|
sf.title = title
|
|
sf.f = func(x *Patch) any {
|
|
return f(x)
|
|
}
|
|
sf.attr = new(guipb.ColAttr)
|
|
sf.attr.Width = int32(sf.Width)
|
|
sf.attr.Type = guipb.ColAttr_INT
|
|
|
|
t.anyFuncs = append(t.anyFuncs, sf)
|
|
return sf
|
|
}
|
|
|
|
// force the application to choose the type of data. this allows the GUI plugin to be smarter
|
|
func (t *PatchesTable) AddTimeFunc(title string, f func(*Patch) time.Time) *PatchAnyFunc {
|
|
t.pb.Order = append(t.pb.Order, title)
|
|
|
|
sf := new(PatchAnyFunc)
|
|
sf.title = title
|
|
sf.f = func(x *Patch) any {
|
|
return f(x)
|
|
}
|
|
sf.attr = new(guipb.ColAttr)
|
|
sf.attr.Width = int32(sf.Width)
|
|
sf.attr.Type = guipb.ColAttr_TIME
|
|
|
|
// t.timeFuncs = append(t.timeFuncs, sf)
|
|
t.anyFuncs = append(t.anyFuncs, sf)
|
|
return sf
|
|
}
|
|
|
|
func (sf *PatchAnyFunc) SetTitle(title string) {
|
|
sf.title = title
|
|
}
|
|
|
|
func (mt *PatchesTable) SetParent(p *gui.Node) {
|
|
mt.parent = p
|
|
}
|
|
|
|
func (mt *PatchesTable) ShowTable() {
|
|
// log.Info("ShowTable() SENDING TO GUI")
|
|
mt.MakeTable()
|
|
mt.parent.ShowTable(mt.pb)
|
|
}
|
|
|
|
type PatchAnyFunc struct {
|
|
title string
|
|
f func(*Patch) any
|
|
Custom func(*Patch)
|
|
Width int
|
|
attr *guipb.ColAttr
|
|
}
|
|
|
|
type PatchesTable struct {
|
|
pb *guipb.Table
|
|
parent *gui.Node
|
|
x *Patches
|
|
hostnames []string
|
|
anyFuncs []*PatchAnyFunc
|
|
CustomFunc func(*Patch)
|
|
}
|
|
|
|
func (mt *PatchesTable) doAnyFuncNew(sf *PatchAnyFunc) bool {
|
|
r := new(guipb.AnyCol)
|
|
r.Header = new(guipb.Widget)
|
|
r.Header.Name = sf.title
|
|
r.Attr = proto.Clone(sf.attr).(*guipb.ColAttr)
|
|
r.Attr.Width = int32(sf.Width)
|
|
|
|
for m := range mt.x.IterAll() {
|
|
t := sf.f(m)
|
|
switch r.Attr.Type {
|
|
case guipb.ColAttr_STRING:
|
|
// anyProto, err := anypb.New(tsProto)
|
|
stringValue := wrapperspb.String(t.(string))
|
|
anyProto, err := anypb.New(stringValue)
|
|
_ = err // do something with err someday (?)
|
|
r.Vals = append(r.Vals, anyProto)
|
|
// return col.Vals[row] true
|
|
case guipb.ColAttr_INT:
|
|
var finalInt int
|
|
finalInt = t.(int)
|
|
intVal := wrapperspb.Int32(int32(finalInt))
|
|
anyProto, _ := anypb.New(intVal)
|
|
r.Vals = append(r.Vals, anyProto)
|
|
case guipb.ColAttr_DURATION:
|
|
case guipb.ColAttr_TIME:
|
|
var goTime time.Time
|
|
goTime = t.(time.Time)
|
|
tsProto := timestamppb.New(goTime)
|
|
anyProto, err := anypb.New(tsProto)
|
|
_ = err // do something with err someday (?)
|
|
r.Vals = append(r.Vals, anyProto)
|
|
default:
|
|
log.Info("cell unhandled type", r.Attr.Type)
|
|
}
|
|
// cellTime := r.Vals[row]
|
|
// s := shell.FormatDuration(time.Since(cellTime.AsTime()))
|
|
}
|
|
|
|
mt.pb.AnyCols = append(mt.pb.AnyCols, r)
|
|
return true
|
|
}
|
|
|
|
func (mt *PatchesTable) MakeTable() {
|
|
for _, sf := range mt.anyFuncs {
|
|
mt.doAnyFuncNew(sf)
|
|
}
|
|
}
|
|
|
|
func (t *PatchesTable) AddNamespace() *PatchAnyFunc {
|
|
sf := t.AddStringFunc("Namespace", func(m *Patch) string {
|
|
return m.Namespace
|
|
})
|
|
return sf
|
|
}
|
|
|
|
func (t *PatchesTable) AddGH() *PatchAnyFunc {
|
|
sf := t.AddStringFunc("GH", func(m *Patch) string {
|
|
return m.GH
|
|
})
|
|
return sf
|
|
}
|
|
|
|
func (t *PatchesTable) AddGT() *PatchAnyFunc {
|
|
sf := t.AddStringFunc("GT", func(m *Patch) string {
|
|
return m.GT
|
|
})
|
|
return sf
|
|
}
|
|
|
|
func (t *PatchesTable) AddGP() *PatchAnyFunc {
|
|
sf := t.AddStringFunc("GP", func(m *Patch) string {
|
|
return m.GP
|
|
})
|
|
return sf
|
|
}
|
|
|
|
func (t *PatchesTable) AddGs() *PatchAnyFunc {
|
|
sf := t.AddStringFunc("Gs", func(m *Patch) string {
|
|
return m.Gs
|
|
})
|
|
return sf
|
|
}
|
|
|
|
func (t *PatchesTable) AddGaI() *PatchAnyFunc {
|
|
sf := t.AddStringFunc("GaI", func(m *Patch) string {
|
|
return m.GaI
|
|
})
|
|
return sf
|
|
}
|
|
|
|
func (t *PatchesTable) AddGan() *PatchAnyFunc {
|
|
sf := t.AddStringFunc("Gan", func(m *Patch) string {
|
|
return m.Gan
|
|
})
|
|
return sf
|
|
}
|
|
|
|
func (t *PatchesTable) AddGae() *PatchAnyFunc {
|
|
sf := t.AddStringFunc("Gae", func(m *Patch) string {
|
|
return m.Gae
|
|
})
|
|
return sf
|
|
}
|
|
|
|
func (t *PatchesTable) AddGcI() *PatchAnyFunc {
|
|
sf := t.AddStringFunc("GcI", func(m *Patch) string {
|
|
return m.GcI
|
|
})
|
|
return sf
|
|
}
|
|
|
|
func (t *PatchesTable) AddGcn() *PatchAnyFunc {
|
|
sf := t.AddStringFunc("Gcn", func(m *Patch) string {
|
|
return m.Gcn
|
|
})
|
|
return sf
|
|
}
|
|
|
|
func (t *PatchesTable) AddGce() *PatchAnyFunc {
|
|
sf := t.AddStringFunc("Gce", func(m *Patch) string {
|
|
return m.Gce
|
|
})
|
|
return sf
|
|
}
|
|
|
|
func (t *PatchesTable) AddGN() *PatchAnyFunc {
|
|
sf := t.AddStringFunc("GN", func(m *Patch) string {
|
|
return m.GN
|
|
})
|
|
return sf
|
|
}
|
|
|
|
func (t *PatchesTable) AddGGG() *PatchAnyFunc {
|
|
sf := t.AddStringFunc("GGG", func(m *Patch) string {
|
|
return m.GGG
|
|
})
|
|
return sf
|
|
}
|
|
|
|
func (t *PatchesTable) AddGGS() *PatchAnyFunc {
|
|
sf := t.AddStringFunc("GGS", func(m *Patch) string {
|
|
return m.GGS
|
|
})
|
|
return sf
|
|
}
|
|
|
|
func (t *PatchesTable) AddGGK() *PatchAnyFunc {
|
|
sf := t.AddStringFunc("GGK", func(m *Patch) string {
|
|
return m.GGK
|
|
})
|
|
return sf
|
|
}
|
|
|
|
func (t *PatchesTable) AddNewHash() *PatchAnyFunc {
|
|
sf := t.AddStringFunc("NewHash", func(m *Patch) string {
|
|
return m.NewHash
|
|
})
|
|
return sf
|
|
}
|
|
|
|
func (t *PatchesTable) AddState() *PatchAnyFunc {
|
|
sf := t.AddStringFunc("State", func(m *Patch) string {
|
|
return m.State
|
|
})
|
|
return sf
|
|
}
|
|
|
|
func (t *PatchesTable) AddFilename() *PatchAnyFunc {
|
|
sf := t.AddStringFunc("Filename", func(m *Patch) string {
|
|
return m.Filename
|
|
})
|
|
return sf
|
|
}
|
|
|
|
func (t *PatchesTable) AddStartHash() *PatchAnyFunc {
|
|
sf := t.AddStringFunc("StartHash", func(m *Patch) string {
|
|
return m.StartHash
|
|
})
|
|
return sf
|
|
}
|
|
|
|
func (t *PatchesTable) AddCommitHash() *PatchAnyFunc {
|
|
sf := t.AddStringFunc("CommitHash", func(m *Patch) string {
|
|
return m.CommitHash
|
|
})
|
|
return sf
|
|
}
|
|
|
|
func (t *PatchesTable) AddComment() *PatchAnyFunc {
|
|
sf := t.AddStringFunc("Comment", func(m *Patch) string {
|
|
return m.Comment
|
|
})
|
|
return sf
|
|
}
|
|
|
|
func (t *PatchesTable) AddPatchId() *PatchAnyFunc {
|
|
sf := t.AddStringFunc("PatchId", func(m *Patch) string {
|
|
return m.PatchId
|
|
})
|
|
return sf
|
|
}
|
|
|
|
func (t *PatchesTable) AddTreeHash() *PatchAnyFunc {
|
|
sf := t.AddStringFunc("TreeHash", func(m *Patch) string {
|
|
return m.TreeHash
|
|
})
|
|
return sf
|
|
}
|
|
func (mt *PatchesTable) NewUuid() {
|
|
mt.pb.Uuid = uuid.New().String()
|
|
}
|
|
|
|
// START TABLE UPDATE (doesn't work yet)
|
|
|
|
func (mt *PatchesTable) dumpStringFunc(name string) {
|
|
for i, r := range mt.pb.StringCols {
|
|
// log.Info("could use", i, r.Header.Name, "for name =", name)
|
|
if r.Header.Name == name {
|
|
log.Info("dump Strings row", i, r.Header.Name, r.Vals)
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
func (mt *PatchesTable) Delete() {
|
|
if mt == nil {
|
|
log.Info("mt == nil table already deleted")
|
|
return
|
|
}
|
|
// log.Info("table Delete here")
|
|
mt.parent.DeleteTable(mt.pb)
|
|
}
|
|
|
|
func (mt *PatchesTable) patchesCustom(w *guipb.Widget) {
|
|
row := mt.x.Patches[w.Location.Y-1]
|
|
// log.Info("got to patchesCustom() with", w.Location.X, w.Location.Y-1)
|
|
|
|
for i, sf := range mt.anyFuncs {
|
|
if i == int(w.Location.X) {
|
|
if sf.Custom != nil {
|
|
log.Info("doing Custom() func for button")
|
|
sf.Custom(row)
|
|
return
|
|
}
|
|
}
|
|
}
|
|
mt.CustomFunc(row)
|
|
}
|
|
|
|
func (mt *PatchesTable) Custom(f func(*Patch)) {
|
|
mt.pb.RegisterCustom(mt.patchesCustom)
|
|
mt.CustomFunc = f
|
|
}
|
|
|
|
func (mt *PatchesTable) GetUuid() string {
|
|
return mt.pb.Uuid
|
|
}
|
|
|
|
// END TABLE UPDATE
|
|
|
|
// END GUI
|