diff --git a/Makefile b/Makefile index 7af2b6f..dba769b 100644 --- a/Makefile +++ b/Makefile @@ -69,6 +69,7 @@ doc: goget: GO111MODULE="off" go get -v -t -u make -C toolkit/gocui goget + make -C toolkit/andlabs goget # GO111MODULE=on go install github.com/posener/goreadme/cmd/goreadme@latest (worked Oct 20 2022) README.md: doc.go diff --git a/plugin.go b/plugin.go index 5443bb0..556bc9e 100644 --- a/plugin.go +++ b/plugin.go @@ -107,6 +107,7 @@ func sendCallback(p *aplug, funcName string) func(chan toolkit.Action) { /* TODO: clean this up. use command args? + TODO: use LD_LIBRARY_PATH ? This searches in the following order for the plugin .so files: ./toolkit/ ~/go/src/go.wit.org/gui/toolkit/ @@ -138,6 +139,12 @@ func searchPaths(name string) *aplug { if (p != nil) { return p } + + filename = "/usr/local/lib/" + name + ".so" + p = tryfile(name, filename) + if (p != nil) { + return p + } return nil } @@ -149,7 +156,7 @@ func tryfile(name string, filename string) *aplug { log(debugGui, "plugin FAILED =", filename, err) return nil } - log(debugGui, "loading plugin =", filename) + log(debugGui, "tryfile() loading plugin =", filename) var newPlug *aplug newPlug = new(aplug) @@ -166,17 +173,20 @@ func tryfile(name string, filename string) *aplug { // for things like: add a new button called 'Check IPv6' newPlug.PluginChannel = getPluginChannel(newPlug, "PluginChannel") + // add it to the list of plugins allPlugins = append(allPlugins, newPlug) - log(debugPlugin, "initPlugin() END", newPlug.name, filename) - // newPlug.Init() // set the communication to the plugins newPlug.pluginChan = newPlug.PluginChannel() + if (newPlug.pluginChan == nil) { + log(debugError, "tryfile() ERROR PluginChannel() returned nil for plugin:", newPlug.name, filename) + return nil + } newPlug.Callback(Config.guiChan) - newPlug.InitOk = true + log(debugPlugin, "tryfile() END", newPlug.name, filename) return newPlug } diff --git a/toolkit/andlabs/Makefile b/toolkit/andlabs/Makefile index 8b0502c..65bd8f0 100644 --- a/toolkit/andlabs/Makefile +++ b/toolkit/andlabs/Makefile @@ -2,3 +2,6 @@ all: plugin plugin: GO111MODULE="off" go build -buildmode=plugin -o ../andlabs.so + +goget: + GO111MODULE="off" go get -v -t -u diff --git a/toolkit/gocui/main.go b/toolkit/gocui/main.go index 7f9958f..c3418a6 100644 --- a/toolkit/gocui/main.go +++ b/toolkit/gocui/main.go @@ -13,12 +13,9 @@ import ( // to this toolkit from the wit/gui golang package func init() { log(logInfo, "Init() of awesome-gocui") - me.defaultWidth = 10 - me.defaultHeight = 2 // this means by default one line of text in a button + Set(&me, "default") me.defaultBehavior = true - me.horizontalPadding = 20 - me.horizontalPadding = 20 me.groupPadding = 4 me.buttonPadding = 3 @@ -29,14 +26,21 @@ func init() { me.padW = 3 me.padH = 3 + // todo, remove all of these + me.defaultWidth = 10 + me.defaultHeight = 2 // this means by default one line of text in a button + + me.horizontalPadding = 20 + me.horizontalPadding = 20 + // todo, remove all of these + me.pluginChan = make(chan toolkit.Action) log(logNow, "Init() start pluginChan") go catchActionChannel() - sleep(.1) + sleep(.1) // probably not needed, but in here for now under development go main() - // probably not needed, but in here for now under development - sleep(.1) + sleep(.1) // probably not needed, but in here for now under development } // this sets the channel to send user events back from the plugin diff --git a/toolkit/gocui/mouse.go b/toolkit/gocui/mouse.go index 4337f42..0ad8e29 100644 --- a/toolkit/gocui/mouse.go +++ b/toolkit/gocui/mouse.go @@ -35,33 +35,28 @@ func MouseMain() { func layout(g *gocui.Gui) error { maxX, maxY := g.Size() + mx, my := g.MousePosition() if _, err := g.View("msg"); msgMouseDown && err == nil { moveMsg(g) } - if v, err := g.SetView("global", -1, -1, maxX, maxY, 0); err != nil { + // if v, err := g.SetView("global", -1, -1, maxX, maxY, 0); err != nil { + // what is this do? I made it just the top 2 lines for now. Is this useful for something? + if v, err := g.SetView("global", -1, -1, maxX, 2, 10); err != nil { if !errors.Is(err, gocui.ErrUnknownView) { + log("global failed", maxX, maxY) return err } v.Frame = false } - /* - if v, err := g.SetView("but1", 2, 2, 22, 7, 0); err != nil { - if !errors.Is(err, gocui.ErrUnknownView) { - return err - } - v.SelBgColor = gocui.ColorGreen - v.SelFgColor = gocui.ColorBlack - fmt.Fprintln(v, "Button 1 - line 1") - fmt.Fprintln(v, "Button 1 - line 2") - fmt.Fprintln(v, "Button 1 - line 3") - fmt.Fprintln(v, "Button 1 - line 4") - if _, err := g.SetCurrentView("but1"); err != nil { - return err - } - } - */ helplayout(g) + if widgetView, _ := g.View("msg"); widgetView == nil { + log(logInfo, "create output widget now", maxX, maxY, mx, my) + makeOutputWidget(g, "this is a create before a mouse click") + } else { + log(logInfo, "output widget already exists", maxX, maxY, mx, my) + } updateHighlightedView(g) + log(logInfo, "layout() END", maxX, maxY, mx, my) return nil } diff --git a/toolkit/gocui/showMsg.go b/toolkit/gocui/showStdout.go similarity index 57% rename from toolkit/gocui/showMsg.go rename to toolkit/gocui/showStdout.go index e749834..c367ab9 100644 --- a/toolkit/gocui/showMsg.go +++ b/toolkit/gocui/showStdout.go @@ -36,16 +36,27 @@ func showMsg(g *gocui.Gui, v *gocui.View) error { } // setOutput(me.rootNode) - maxX, maxY := g.Size() - if v, err := g.SetView("msg", maxX/2, maxY/2, maxX/2+outputW, maxY/2+outputH, 0); err == nil || errors.Is(err, gocui.ErrUnknownView) { - v.Clear() - v.SelBgColor = gocui.ColorCyan - v.SelFgColor = gocui.ColorBlack - l += "foo\n" + "bar\n" - fmt.Fprintln(v, l) - } - // g.SetViewOnTop("msg") - g.SetViewBeneath("msg", "help", 24) - // g.SetViewOnBottom("msg") + makeOutputWidget(g, l) return nil } + +func makeOutputWidget(g *gocui.Gui, stringFromMouseClick string) { + maxX, maxY := g.Size() + v, err := g.SetView("msg", maxX-32, maxY/2, maxX/2+outputW, maxY/2+outputH, 0) + // help, err := g.SetView("help", maxX-32, 0, maxX-1, 13, 0) + if errors.Is(err, gocui.ErrUnknownView) { + log("this is supposed to happen?", err) + } + + if (err != nil) { + log("create output window failed", err) + return + } + + v.Clear() + v.SelBgColor = gocui.ColorCyan + v.SelFgColor = gocui.ColorBlack + fmt.Fprintln(v, "figure out how to capture STDOUT to here\n" + stringFromMouseClick) + g.SetViewOnBottom("msg") + return +} diff --git a/toolkit/gocui/structs.go b/toolkit/gocui/structs.go index e8e8172..4ee74c7 100644 --- a/toolkit/gocui/structs.go +++ b/toolkit/gocui/structs.go @@ -10,6 +10,8 @@ package main import ( "fmt" + "reflect" + "strconv" "sync" "github.com/awesome-gocui/gocui" "git.wit.org/wit/gui/toolkit" @@ -37,12 +39,12 @@ type config struct { defaultHeight int // nextW int // where the next window or tab flag should go - padW int + padW int `default:"3" dense:"2"` padH int - // where the raw corner is - rawW int - rawH int + // the raw beginning of each window (or tab) + rawW int `default:"7"` + rawH int `default:"3"` bookshelf bool // do you want things arranged in the box like a bookshelf or a stack? canvas bool // if set to true, the windows are a raw canvas @@ -52,8 +54,8 @@ type config struct { margin bool // add space around the frames of windows horizontalPadding int - groupPadding int - buttonPadding int + groupPadding int `default:"6" dense:"2"` // this is supposed to be how far to indent to the left + buttonPadding int `default:"4" dense:"3"` // if 3, buttons slightly overlap } var ( @@ -156,3 +158,43 @@ func (w *cuiWidget) Write(p []byte) (n int, err error) { return len(p), nil } + +func Set(ptr interface{}, tag string) error { + if reflect.TypeOf(ptr).Kind() != reflect.Ptr { + return fmt.Errorf("Not a pointer") + } + + v := reflect.ValueOf(ptr).Elem() + t := v.Type() + + for i := 0; i < t.NumField(); i++ { + if defaultVal := t.Field(i).Tag.Get(tag); defaultVal != "-" { + if err := setField(v.Field(i), defaultVal); err != nil { + return err + } + + } + } + return nil +} + +func setField(field reflect.Value, defaultVal string) error { + + if !field.CanSet() { + log("Can't set value\n") + return fmt.Errorf("Can't set value\n") + } + + switch field.Kind() { + case reflect.Int: + if val, err := strconv.ParseInt(defaultVal, 1, 64); err == nil { + field.Set(reflect.ValueOf(int(val)).Convert(field.Type())) + } + case reflect.String: + field.Set(reflect.ValueOf(defaultVal).Convert(field.Type())) + case reflect.Bool: + field.Set(reflect.ValueOf(defaultVal).Convert(field.Type())) + } + + return nil +}