continue work on testing using 'any' in GUI PB
This commit is contained in:
parent
bd897e4edb
commit
b53d68d6b8
22
README.md
22
README.md
|
@ -1,27 +1,11 @@
|
||||||
// Copyright 2025 WIT.COM Inc Licensed GPL 3.0
|
// Copyright 2025 WIT.COM Inc Licensed GPL 3.0
|
||||||
|
|
||||||
// you can replace all of COBOL with this amount of GO
|
|
||||||
|
|
||||||
// ah yes, COBOL. what an ancient throwback. for those that know
|
// ah yes, COBOL. what an ancient throwback. for those that know
|
||||||
// then you know exactly what is in this file. For those that don't, here it is:
|
// then you know exactly what is in this file. For those that don't, here it is:
|
||||||
|
|
||||||
// All this does is output human readable text formatted to be viewable on
|
// All this does is output human readable text formatted to be viewable on
|
||||||
// a console with a fixed with font. AKA: a typerwriter. Which is exactly
|
// a console with a fixed with font. AKA: a typerwriter. Which is exactly
|
||||||
// what COBOL did in the 1970's (60s? notsure) And the 80s.
|
// what COBOL did in the 1970's (60s? notsure). And the 80s.
|
||||||
|
|
||||||
// So, you want to dump out stuff on the console. Let's see. Something like
|
// Perl, before GO, was great for this kinda thing. GO with
|
||||||
|
// protobuffers is even better
|
||||||
/*
|
|
||||||
forge --favorites
|
|
||||||
|
|
||||||
go.wit.com/apps/myapp v0.2.0 (installed)
|
|
||||||
go.wit.com/lib/somethingfun v0.0.7 (not downloaded)
|
|
||||||
*/
|
|
||||||
|
|
||||||
// anyway, you get the idea. This is also called COBOL because it does
|
|
||||||
// truncate every line output to the columns you see with stty -a
|
|
||||||
// my monitor is huge, so it's not going to work at 80x24. 160x48 is better
|
|
||||||
// actually, I'd predict some of these will probably end up 240 wide
|
|
||||||
// long live good eyesight and 4K monitors!
|
|
||||||
|
|
||||||
// TODO: fix this to truncate with stty cols width
|
|
||||||
|
|
71
tablePB.go
71
tablePB.go
|
@ -11,6 +11,7 @@ import (
|
||||||
"go.wit.com/lib/protobuf/guipb"
|
"go.wit.com/lib/protobuf/guipb"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
"google.golang.org/protobuf/types/known/anypb"
|
"google.golang.org/protobuf/types/known/anypb"
|
||||||
|
"google.golang.org/protobuf/types/known/timestamppb"
|
||||||
"google.golang.org/protobuf/types/known/wrapperspb"
|
"google.golang.org/protobuf/types/known/wrapperspb"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -34,6 +35,9 @@ func PrintTable(pb *guipb.Table) {
|
||||||
var sizes []int
|
var sizes []int
|
||||||
for _, name := range pb.Order {
|
for _, name := range pb.Order {
|
||||||
arg, attr, tmp := getColAttr(pb, name)
|
arg, attr, tmp := getColAttr(pb, name)
|
||||||
|
if attr == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
HEIGHT = tmp
|
HEIGHT = tmp
|
||||||
args = append(args, arg)
|
args = append(args, arg)
|
||||||
if attr.Width == 0 {
|
if attr.Width == 0 {
|
||||||
|
@ -49,6 +53,11 @@ func PrintTable(pb *guipb.Table) {
|
||||||
for i := range HEIGHT {
|
for i := range HEIGHT {
|
||||||
var cells []string
|
var cells []string
|
||||||
for _, name := range pb.Order {
|
for _, name := range pb.Order {
|
||||||
|
if val, ok := getAnyCell(pb, name, int(i)); ok {
|
||||||
|
h += 1
|
||||||
|
cells = append(cells, val)
|
||||||
|
continue
|
||||||
|
}
|
||||||
if val, ok := getTableCell(pb, name, int(i)); ok {
|
if val, ok := getTableCell(pb, name, int(i)); ok {
|
||||||
// log.Info("tree: CELL GOOD", pb.Title, name, w, h, val)
|
// log.Info("tree: CELL GOOD", pb.Title, name, w, h, val)
|
||||||
h += 1
|
h += 1
|
||||||
|
@ -112,6 +121,61 @@ func getTableCell(t *guipb.Table, name string, row int) (string, bool) {
|
||||||
s := shell.FormatDuration(time.Since(cellTime.AsTime()))
|
s := shell.FormatDuration(time.Since(cellTime.AsTime()))
|
||||||
return s, true
|
return s, true
|
||||||
}
|
}
|
||||||
|
for _, r := range t.AnyCols {
|
||||||
|
if name != r.Header.Name {
|
||||||
|
// log.Info("skip sint row:", r.Header.Name, "!=", name)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// cellTime := r.Vals[row]
|
||||||
|
// s := shell.FormatDuration(time.Since(cellTime.AsTime()))
|
||||||
|
return "fixme", true
|
||||||
|
}
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAnyCell(t *guipb.Table, name string, row int) (string, bool) {
|
||||||
|
for _, col := range t.AnyCols {
|
||||||
|
if name != col.Header.Name {
|
||||||
|
// log.Info("skip sint row:", r.Header.Name, "!=", name)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
anyVal := col.Vals[row]
|
||||||
|
|
||||||
|
switch col.Attr.Type {
|
||||||
|
case guipb.ColAttr_STRING:
|
||||||
|
// return col.Vals[row] true
|
||||||
|
case guipb.ColAttr_INT:
|
||||||
|
var finalInt int32
|
||||||
|
// 1. Check if the Any contains an Int32Value
|
||||||
|
if anyVal.MessageIs(&wrapperspb.Int32Value{}) {
|
||||||
|
var intValue wrapperspb.Int32Value
|
||||||
|
// 2. Unmarshal into the wrapper
|
||||||
|
if err := anyVal.UnmarshalTo(&intValue); err == nil {
|
||||||
|
// 3. Get the native Go int32 from the wrapper
|
||||||
|
finalInt = intValue.GetValue()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%d", finalInt), true
|
||||||
|
case guipb.ColAttr_DURATION:
|
||||||
|
case guipb.ColAttr_TIME:
|
||||||
|
var sout string
|
||||||
|
var tsProto timestamppb.Timestamp
|
||||||
|
if err := anyVal.UnmarshalTo(&tsProto); err == nil {
|
||||||
|
// It's a timestamp, now convert it back to a Go time.Time
|
||||||
|
goTime := tsProto.AsTime()
|
||||||
|
// fmt.Printf("Successfully unpacked timestamp: %v\n", goTime)
|
||||||
|
sout = shell.FormatDuration(time.Since(goTime))
|
||||||
|
return sout, true
|
||||||
|
}
|
||||||
|
return "", false
|
||||||
|
default:
|
||||||
|
log.Info("cell unhandled type", col.Attr.Type)
|
||||||
|
}
|
||||||
|
// cellTime := r.Vals[row]
|
||||||
|
// s := shell.FormatDuration(time.Since(cellTime.AsTime()))
|
||||||
|
return "fixme", true
|
||||||
|
}
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,5 +208,12 @@ func getColAttr(t *guipb.Table, name string) (string, *guipb.ColAttr, int) {
|
||||||
}
|
}
|
||||||
return r.Header.Name, r.Attr, len(r.Vals)
|
return r.Header.Name, r.Attr, len(r.Vals)
|
||||||
}
|
}
|
||||||
|
for _, r := range t.AnyCols {
|
||||||
|
if name != r.Header.Name {
|
||||||
|
// log.Info("skip sint row:", r.Header.Name, "!=", name)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return r.Header.Name, r.Attr, len(r.Vals)
|
||||||
|
}
|
||||||
return "", nil, 0
|
return "", nil, 0
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue