summaryrefslogtreecommitdiff
path: root/plugin.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2023-04-06 18:00:18 -0500
committerJeff Carr <[email protected]>2023-04-06 18:00:18 -0500
commitbf60121b6515681ac505e80cb6824ba6bd978c29 (patch)
treecdb87a9169185da1c33827702ef1b405c3d1ed00 /plugin.go
parent70f8797122741ef61951d3400317173a1d9974da (diff)
gocui: callbacks work via a channel
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'plugin.go')
-rw-r--r--plugin.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/plugin.go b/plugin.go
index f38559d..f4e97d0 100644
--- a/plugin.go
+++ b/plugin.go
@@ -33,6 +33,10 @@ type aplug struct {
Quit func()
// NewWindow func(*toolkit.Widget)
+ // sets the chan for the plugin to call back too
+ Callback func(chan toolkit.Action)
+ // NewWindow func(*toolkit.Widget)
+
// simplifies passing to the plugin
// Send func(*toolkit.Widget, *toolkit.Widget)
@@ -83,6 +87,8 @@ func LoadToolkit(name string) bool {
// Sends a widget (button, checkbox, etc) and it's parent widget
newPlug.Action = loadFuncA(&newPlug, "Action")
+ newPlug.Callback = loadCallback(&newPlug, "Callback")
+
allPlugins = append(allPlugins, &newPlug)
log(debugPlugin, "gui.LoadToolkit() END", newPlug.name, filename)
@@ -112,6 +118,25 @@ func loadFuncE(p *aplug, funcName string) func() {
return newfunc
}
+func loadCallback(p *aplug, funcName string) func(chan toolkit.Action) {
+ var newfunc func(chan toolkit.Action)
+ var ok bool
+ var test plugin.Symbol
+
+ test, err = p.plug.Lookup(funcName)
+ if err != nil {
+ log(debugGui, "DID NOT FIND: name =", test, "err =", err)
+ return nil
+ }
+
+ newfunc, ok = test.(func(chan toolkit.Action))
+ if !ok {
+ log(debugGui, "function name =", funcName, "names didn't map correctly. Fix the plugin name =", p.name)
+ return nil
+ }
+ return newfunc
+}
+
func loadFunc2(p *aplug, funcName string) func(*toolkit.Widget, *toolkit.Widget) {
var newfunc func(*toolkit.Widget, *toolkit.Widget)
var ok bool