summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2023-04-22 12:25:50 -0500
committerJeff Carr <[email protected]>2023-04-22 12:25:50 -0500
commit52eb9b1ad29756756881b90ba5221d03cd504fbd (patch)
tree8e80b65d20516d57797b7e3d39d44a147c7641ba
parent2b10d882a35d5a8b79c7d48eaa59e7d027be5e8d (diff)
unloading the gocui toolkit works
Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--README-goreadme.md4
-rw-r--r--main.go18
-rw-r--r--toolkit/gocui/main.go1
-rw-r--r--toolkit/gocui/plugin.go6
-rw-r--r--toolkit/widget.go5
5 files changed, 29 insertions, 5 deletions
diff --git a/README-goreadme.md b/README-goreadme.md
index 9336c80..160264f 100644
--- a/README-goreadme.md
+++ b/README-goreadme.md
@@ -146,7 +146,7 @@ attempts to locate the .so file
`func ShowDebugValues()`
-### func [StandardExit](/main.go#L153)
+### func [StandardExit](/main.go#L169)
`func StandardExit()`
@@ -187,7 +187,7 @@ var Config GuiConfig
The Node is a binary tree. This is how all GUI elements are stored
simply the name and the size of whatever GUI element exists
-#### func [New](/main.go#L126)
+#### func [New](/main.go#L142)
`func New() *Node`
diff --git a/main.go b/main.go
index 68c14be..deb53b5 100644
--- a/main.go
+++ b/main.go
@@ -112,13 +112,29 @@ func (n *Node) doUserEvent(a toolkit.Action) {
}
func (n *Node) LoadToolkit(name string) *Node {
- log(logInfo, "Start() Main(f) for name =", name)
+ log(logInfo, "LoadToolkit() for name =", name)
if (FindPlugin(name) == nil) {
return n
}
return n
}
+func (n *Node) CloseToolkit(name string) bool {
+ log(logInfo, "CloseToolkit() for name =", name)
+ for _, aplug := range allPlugins {
+ log(debugGui, "CloseToolkit() found", aplug.name)
+ if (aplug.name == name) {
+ log(debugNow, "CloseToolkit() sending close", name)
+ var a toolkit.Action
+ a.ActionType = toolkit.CloseToolkit
+ aplug.pluginChan <- a
+ sleep(.5)
+ return true
+ }
+ }
+ return false
+}
+
// There should only be one of these per application
// This is due to restrictions by being cross platform
// some toolkit's on some operating systems don't support more than one
diff --git a/toolkit/gocui/main.go b/toolkit/gocui/main.go
index de35700..f0415f5 100644
--- a/toolkit/gocui/main.go
+++ b/toolkit/gocui/main.go
@@ -83,5 +83,6 @@ func main() {
log("This is a test log entry")
MouseMain()
+ log(true, "MouseMain() closed")
me.baseGui.Close()
}
diff --git a/toolkit/gocui/plugin.go b/toolkit/gocui/plugin.go
index ce47f20..f70ae96 100644
--- a/toolkit/gocui/plugin.go
+++ b/toolkit/gocui/plugin.go
@@ -1,6 +1,7 @@
package main
import (
+ "os"
// if you include more than just this import
// then your plugin might be doing something un-ideal (just a guess from 2023/02/27)
"git.wit.org/wit/gui/toolkit"
@@ -38,6 +39,11 @@ func action(a *toolkit.Action) {
w.AddText(a.S)
case toolkit.Move:
log(logNow, "attempt to move() =", a.ActionType, a.WidgetType, a.Name)
+ case toolkit.CloseToolkit:
+ log(logNow, "attempting to close the plugin and release stdout and stderr")
+ me.baseGui.Close()
+ // defer outf.Close()
+ setOutput(os.Stdout)
default:
log(logError, "action() Unknown =", a.ActionType, a.WidgetType, a.Name)
}
diff --git a/toolkit/widget.go b/toolkit/widget.go
index 769bf09..21f2f47 100644
--- a/toolkit/widget.go
+++ b/toolkit/widget.go
@@ -109,7 +109,6 @@ const (
const (
Add ActionType = iota
- User // the user did something (mouse, keyboard, etc)
Delete
Get
Set
@@ -127,7 +126,9 @@ const (
Append
Move
Dump
- Quit
+ User // the user did something (mouse, keyboard, etc)
+ InitToolkit // initializes the toolkit
+ CloseToolkit // closes the toolkit
)
func (s WidgetType) String() string {