// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT. // This file was autogenerated with autogenpb v0.0.79 2025-09-01_01:52:08_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 chatpb import ( "time" "github.com/google/uuid" "go.wit.com/gui" "go.wit.com/lib/protobuf/guipb" "go.wit.com/log" timestamppb "google.golang.org/protobuf/types/known/timestamppb" ) // START GUI func (x *Chats) NewTable(title string) *ChatsTable { t := new(ChatsTable) t.x = x pb := new(guipb.Table) pb.Title = title t.pb = pb return t } func (t *ChatsTable) AddStringFunc(title string, f func(*Chat) string) *ChatStringFunc { t.pb.Order = append(t.pb.Order, title) sf := new(ChatStringFunc) sf.title = title sf.f = f sf.order = t.order t.order += 1 t.stringFuncs = append(t.stringFuncs, sf) return sf } func (t *ChatsTable) AddButtonFunc(title string, f func(*Chat) string) *ChatButtonFunc { t.pb.Order = append(t.pb.Order, title) sf := new(ChatButtonFunc) sf.title = title sf.f = f sf.order = t.order t.order += 1 t.buttonFuncs = append(t.buttonFuncs, sf) return sf } func (t *ChatsTable) AddIntFunc(title string, f func(*Chat) int) *ChatIntFunc { t.pb.Order = append(t.pb.Order, title) sf := new(ChatIntFunc) sf.title = title sf.f = f sf.order = t.order t.order += 1 t.intFuncs = append(t.intFuncs, sf) return sf } func (t *ChatsTable) AddTimeFunc(title string, f func(*Chat) time.Time) *ChatTimeFunc { t.pb.Order = append(t.pb.Order, title) sf := new(ChatTimeFunc) sf.title = title sf.f = f sf.order = t.order t.order += 1 t.timeFuncs = append(t.timeFuncs, sf) return sf } func (sf *ChatStringFunc) SetTitle(title string) { sf.title = title } func (sf *ChatIntFunc) SetTitle(title string) { sf.title = title } func (sf *ChatTimeFunc) SetTitle(title string) { sf.title = title } func (mt *ChatsTable) SetParent(p *gui.Node) { mt.parent = p } func (mt *ChatsTable) ShowTable() { // log.Info("ShowTable() SENDING TO GUI") mt.MakeTable() mt.parent.ShowTable(mt.pb) } type ChatStringFunc struct { title string f func(*Chat) string Custom func(*Chat) order int } type ChatButtonFunc struct { title string f func(*Chat) string Custom func(*Chat) order int } type ChatIntFunc struct { title string f func(*Chat) int Custom func(*Chat) order int } type ChatTimeFunc struct { title string f func(*Chat) time.Time Custom func(*Chat) order int } type ChatsTable struct { pb *guipb.Table parent *gui.Node x *Chats hostnames []string stringFuncs []*ChatStringFunc intFuncs []*ChatIntFunc timeFuncs []*ChatTimeFunc buttonFuncs []*ChatButtonFunc CustomFunc func(*Chat) order int } func (mt *ChatsTable) doStringFunc(name string) bool { for _, sf := range mt.stringFuncs { if sf.title != name { continue } // log.Info("chatpb: found stringfunc name:", name) r := new(guipb.StringRow) r.Header = new(guipb.Widget) r.Header.Name = name for m := range mt.x.IterAll() { r.Vals = append(r.Vals, sf.f(m)) // log.Info("chatpb: adding", name, r.Vals) } mt.pb.StringRows = append(mt.pb.StringRows, r) return true } return false } func (mt *ChatsTable) doButtonFunc(name string) bool { for _, sf := range mt.buttonFuncs { if sf.title != name { continue } // log.Info("chatpb: found stringfunc name:", name) r := new(guipb.ButtonRow) r.Header = new(guipb.Widget) r.Header.Name = name for m := range mt.x.IterAll() { r.Vals = append(r.Vals, sf.f(m)) // log.Info("chatpb: adding", name, r.Vals) } mt.pb.ButtonRows = append(mt.pb.ButtonRows, r) return true } return false } func (mt *ChatsTable) doIntFunc(name string) bool { for _, sf := range mt.intFuncs { if sf.title != name { continue } // log.Info("chatpb: found intfunc name:", name) r := new(guipb.IntRow) r.Header = new(guipb.Widget) r.Header.Name = name for m := range mt.x.IterAll() { r.Vals = append(r.Vals, int64(sf.f(m))) // log.Info("chatpb: adding", name, r.Vals) } mt.pb.IntRows = append(mt.pb.IntRows, r) return true } return false } func (mt *ChatsTable) doTimeFunc(name string) bool { for _, sf := range mt.timeFuncs { if sf.title != name { continue } // log.Info("chatpb: found timefunc name:", name) r := new(guipb.TimeRow) r.Header = new(guipb.Widget) r.Header.Name = name for m := range mt.x.IterAll() { t := sf.f(m) r.Vals = append(r.Vals, timestamppb.New(t)) // convert to protobuf time // log.Info("chatpb: adding", name, r.Vals) } mt.pb.TimeRows = append(mt.pb.TimeRows, r) return true } return false } func (mt *ChatsTable) MakeTable() { for _, name := range mt.pb.Order { // log.Info("chatpb: looking for row name()", name) if mt.doStringFunc(name) { continue } if mt.doIntFunc(name) { continue } if mt.doTimeFunc(name) { continue } if mt.doButtonFunc(name) { continue } } } func (t *ChatsTable) AddUuid() *ChatStringFunc { sf := t.AddStringFunc("Uuid", func(m *Chat) string { return m.Uuid }) return sf } func (t *ChatsTable) AddChatName() *ChatStringFunc { sf := t.AddStringFunc("ChatName", func(m *Chat) string { return m.ChatName }) return sf } func (mt *ChatsTable) NewUuid() { mt.pb.Uuid = uuid.New().String() } // START TABLE UPDATE func (mt *ChatsTable) todoUpdate() { for _, name := range mt.pb.Order { // log.Info("Chatpb: trying to update row()", name) if mt.updateStringFunc(name) { continue } if mt.updateTimeFunc(name) { continue } /* if mt.updateIntFunc(name) { continue } */ } // mt.dumpStringFunc("Hostname") mt.parent.UpdateTable(mt.pb) } func (mt *ChatsTable) dumpStringFunc(name string) { for i, r := range mt.pb.StringRows { // 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 *ChatsTable) updateStringFunc(name string) bool { // log.Info("LOOKING FOR STRING row", name) var found *guipb.StringRow for _, r := range mt.pb.StringRows { // log.Info("could use", i, r.Header.Name, "for name =", name) if r.Header.Name == name { // log.Info("found row", i, r.Header.Name) found = r break } } if found == nil { log.Info("did not find string row", name) return false } for _, sf := range mt.stringFuncs { if sf.title != name { continue } // log.Info("Chatpb: starting", name, found.Vals) for i, _ := range found.Vals { tmp := sf.f(mt.x.Chats[i]) if tmp == "www.wit.com" { log.Info("virtpb: FOUND WWW", i) tmp = "new.www" } found.Vals[i] = tmp } // log.Info("Chatpb: ending", name, found.Vals) return true } return false } func (mt *ChatsTable) updateTimeFunc(name string) bool { log.Info("LOOKING FOR TIME row", name) var found *guipb.TimeRow for i, r := range mt.pb.TimeRows { // log.Info("could use", i, r.Header.Name, "for name =", name) if r.Header.Name == name { log.Info("found row", i, r.Header.Name) found = r break } } if found == nil { log.Info("did not find time row", name) return false } for _, sf := range mt.timeFuncs { if sf.title != name { continue } // log.Info("updateTimeFunc() has row len =", len(mt.x.Chats)) // log.Info("virtpb: starting", name, found.Vals) for i, _ := range found.Vals { newt := sf.f(mt.x.Chats[i]) found.Vals[i] = timestamppb.New(newt) // convert to protobuf time } // log.Info("virtpb: ending", name, found.Vals) return true } return false } func (mt *ChatsTable) Delete() { if mt == nil { log.Info("mt == nil table already deleted") return } // log.Info("table Delete here") mt.parent.DeleteTable(mt.pb) } func (mt *ChatsTable) chatsCustom(w *guipb.Widget) { row := mt.x.Chats[w.Location.Y-1] // log.Info("got to chatsCustom() with", w.Location.X, w.Location.Y-1) for _, sf := range mt.buttonFuncs { if sf.order == int(w.Location.X) { // log.Info("found order", sf.order) if sf.Custom != nil { log.Info("doing Custom() func for button") sf.Custom(row) return } } } mt.CustomFunc(row) } func (mt *ChatsTable) Custom(f func(*Chat)) { mt.pb.RegisterCustom(mt.chatsCustom) mt.CustomFunc = f } func (mt *ChatsTable) GetUuid() string { return mt.pb.Uuid } // END TABLE UPDATE // END GUI