Compare commits

...

11 Commits

Author SHA1 Message Date
Jeff Carr cf5c8e836b remove for now 2025-03-05 03:47:36 -06:00
Jeff Carr a83ca26ac3 switch to treeInit 2025-02-14 18:11:19 -06:00
Jeff Carr c4e48c6403 standard build rules 2024-12-06 01:52:07 -06:00
Jeff Carr 4a36e0300b clean build rules 2024-12-05 19:15:55 -06:00
Jeff Carr 3125ca435d testing plugins 2024-12-05 18:50:19 -06:00
Jeff Carr 462f019814 no .so files
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-12-03 00:49:11 -06:00
Jeff Carr 1971108f62 "package plugin" would be awesome for golang 2024-12-02 05:17:23 -06:00
Jeff Carr e23b7189d8 add 'make install' for testing 2024-12-01 00:50:20 -06:00
Jeff Carr c5da2ba44c testing for 'package plugin' 2024-11-15 10:02:19 -06:00
Jeff Carr a4275a32fb ignore binary
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-02-12 21:34:07 -06:00
Jeff Carr 9dde5d994a panic() does os.Exit()
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-02-09 10:26:12 -06:00
11 changed files with 229 additions and 102 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
*.swp *.swp
*.so
go.mod go.mod
go.sum go.sum
nocui

1
.plugin Normal file
View File

@ -0,0 +1 @@
// plugin

View File

@ -1,8 +1,20 @@
all: plugin VERSION = $(shell git describe --tags)
ldd ../nocui.so BUILDTIME = $(shell date +%Y.%m.%d)
plugin: all: goimports nocui
go build -v -x -buildmode=plugin -o ../nocui.so @#ldd nocui.so
nocui:
GO111MODULE=off go build -v -buildmode=plugin -o nocui.so \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
install: clean
go build -buildmode=plugin -o ~/go/lib/nocui-${VERSION}.so \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
cd ~/go/lib && ln -f -s nocui-${VERSION}.so nocui.so
clean:
rm -f nocui nocui.so
check-git-clean: check-git-clean:
@git diff-index --quiet HEAD -- || (echo "Git repository is dirty, please commit your changes first"; exit 1) @git diff-index --quiet HEAD -- || (echo "Git repository is dirty, please commit your changes first"; exit 1)

View File

@ -7,13 +7,13 @@ package main
*/ */
import ( import (
"go.wit.com/lib/protobuf/guipb"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/toolkits/tree" "go.wit.com/toolkits/tree"
"go.wit.com/widget" "go.wit.com/widget"
) )
func newAdd(n *tree.Node) {
func Add(n *tree.Node) {
log.Log(INFO, "Add() END =", n.WidgetType, n.String()) log.Log(INFO, "Add() END =", n.WidgetType, n.String())
if n == nil { if n == nil {
log.Warn("Tree Error: Add() sent n == nil") log.Warn("Tree Error: Add() sent n == nil")
@ -59,7 +59,7 @@ func newaction(n *tree.Node, atype widget.ActionType) {
// w.disableColor() // w.disableColor()
case widget.Delete: case widget.Delete:
log.Info("newaction() DeleteNode()") log.Info("newaction() DeleteNode()")
n.DeleteNode() // n.DeleteNode()
case widget.ToolkitClose: case widget.ToolkitClose:
log.Info("newaction() toolkit closed. are the channels cleand up?") log.Info("newaction() toolkit closed. are the channels cleand up?")
return return
@ -69,15 +69,15 @@ func newaction(n *tree.Node, atype widget.ActionType) {
log.Log(INFO, "newaction() END", atype, n.String()) log.Log(INFO, "newaction() END", atype, n.String())
} }
func SetTitle(n *tree.Node, s string) { func setTitle(n *tree.Node, s string) {
SetText(n, s) setText(n, s)
} }
func SetLabel(n *tree.Node, s string) { func setLabel(n *tree.Node, s string) {
SetText(n, s) setText(n, s)
} }
func SetText(n *tree.Node, s string) { func setText(n *tree.Node, s string) {
if n == nil { if n == nil {
log.Warn("Tree Error: Add() sent n == nil") log.Warn("Tree Error: Add() sent n == nil")
return return
@ -91,7 +91,7 @@ func SetText(n *tree.Node, s string) {
log.Info("SetText()", n.WidgetType, n.String()) log.Info("SetText()", n.WidgetType, n.String())
} }
func AddText(n *tree.Node, s string) { func addText(n *tree.Node, s string) {
if n == nil { if n == nil {
log.Warn("Tree Error: Add() sent n == nil") log.Warn("Tree Error: Add() sent n == nil")
return return
@ -104,3 +104,23 @@ func AddText(n *tree.Node, s string) {
// w := n.TK.(*guiWidget) // w := n.TK.(*guiWidget)
// w.AddText(s) // w.AddText(s)
} }
func enableWidget(n *tree.Node) {
log.Info("do enable() here")
}
func disableWidget(n *tree.Node) {
log.Info("do enable() here")
}
func setChecked(n *tree.Node, b bool) {
log.Info("do enable() here")
}
func showTable(n *guipb.Table) {
log.Info("do enable() here")
}
func toolkitClose() {
log.Info("do enable() here")
}

View File

@ -1,51 +0,0 @@
package main
/*
import (
"go.wit.com/log"
"go.wit.com/widget"
"go.wit.com/toolkits/tree"
)
func doWidgetClick(n *tree.Node) {
switch n.WidgetType {
case widget.Root:
// THIS IS THE BEGINING OF THE LAYOUT
// rootNode.nextW = 0
// rootNode.nextH = 0
// rootNode.redoTabs(true)
case widget.Flag:
// me.rootNode.redoColor(true)
// rootNode.dumpTree(true)
case widget.Window:
// setCurrentWindow(w)
// n.doUserEvent()
case widget.Tab:
// setCurrentTab(w)
case widget.Group:
// n.placeWidgets()
// n.toggleTree()
case widget.Checkbox:
if n.Bool() {
// n.setCheckbox(false)
} else {
// n.setCheckbox(true)
}
// n.doUserEvent()
case widget.Grid:
// rootNode.hideWidgets()
// n.placeGrid()
// n.showWidgets()
case widget.Box:
// n.showWidgetPlacement(logNow, "drawTree()")
if n.Bool() {
log.Log(NOW, "BOX IS HORIZONTAL", n.GetProgName())
} else {
log.Log(NOW, "BOX IS VERTICAL", n.GetProgName())
}
case widget.Button:
// n.doUserEvent()
default:
}
}
*/

25
main.go
View File

@ -9,22 +9,25 @@ package main
import ( import (
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/toolkits/tree"
) )
func init() { var PLUGIN string = "nocui"
func initPlugin() {
log.Log(INFO, "Init()") log.Log(INFO, "Init()")
me.myTree = tree.New() me.myTree = initTree()
me.myTree.PluginName = "nocui" /*
// me.myTree.ActionFromChannel = doAction me.myTree.PluginName = "nocui"
// me.myTree.ActionFromChannel = doAction
me.myTree.NodeAction = newaction // me.myTree.NodeAction = newaction
me.myTree.Add = Add me.myTree.Add = Add
me.myTree.SetTitle = SetTitle me.myTree.SetTitle = SetTitle
me.myTree.SetLabel = SetLabel me.myTree.SetLabel = SetLabel
me.myTree.SetText = SetText me.myTree.SetText = SetText
me.myTree.AddText = AddText me.myTree.AddText = AddText
*/
me.exit = false me.exit = false

85
package-plugin.diff Normal file
View File

@ -0,0 +1,85 @@
diff --git a/Makefile b/Makefile
index 356b929..351f9e9 100644
--- a/Makefile
+++ b/Makefile
@@ -4,6 +4,10 @@ all: plugin
plugin:
go build -v -x -buildmode=plugin -o ../nocui.so
+# for testing custom golang
+custom:
+ GO111MODULE=off go build -v -work
+
check-git-clean:
@git diff-index --quiet HEAD -- || (echo "Git repository is dirty, please commit your changes first"; exit 1)
diff --git a/action.go b/action.go
index a4e5ee6..98c2636 100644
--- a/action.go
+++ b/action.go
@@ -1,4 +1,4 @@
-package main
+package plugin
/*
a simple function to handle widget actions
diff --git a/args.go b/args.go
index 88fcf53..2b61e2b 100644
--- a/args.go
+++ b/args.go
@@ -1,4 +1,4 @@
-package main
+package plugin
/*
this enables command line options from other packages like 'gui' and 'log'
diff --git a/event.go b/event.go
index 9fea1b0..0649aec 100644
--- a/event.go
+++ b/event.go
@@ -1,4 +1,4 @@
-package main
+package plugin
/*
import (
diff --git a/main.go b/main.go
index b5dff47..26933b7 100644
--- a/main.go
+++ b/main.go
@@ -1,4 +1,4 @@
-package main
+package plugin
/*
This is reference code for toolkit developers
diff --git a/stdin.go b/stdin.go
index fc2f2e5..c6c3148 100644
--- a/stdin.go
+++ b/stdin.go
@@ -1,4 +1,4 @@
-package main
+package plugin
import (
"bufio"
diff --git a/structs.go b/structs.go
index 5331219..25e21bb 100644
--- a/structs.go
+++ b/structs.go
@@ -1,4 +1,4 @@
-package main
+package plugin
import (
"go.wit.com/toolkits/tree"
diff --git a/tree.go b/tree.go
index 57f283a..a81bbc4 100644
--- a/tree.go
+++ b/tree.go
@@ -1,4 +1,4 @@
-package main
+package plugin
/*
This is reference code for toolkit developers

View File

@ -9,6 +9,7 @@ import (
"strings" "strings"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/toolkits/tree"
"go.wit.com/widget" "go.wit.com/widget"
) )
@ -37,6 +38,7 @@ func simpleStdin() {
log.Println("Stack trace:") log.Println("Stack trace:")
debug.PrintStack() debug.PrintStack()
me.myTree.SendToolkitPanic() me.myTree.SendToolkitPanic()
os.Exit(0)
return return
} }
}() }()
@ -50,10 +52,10 @@ func simpleStdin() {
switch s { switch s {
case "l": case "l":
log.Log(NOW, "list widgets") log.Log(NOW, "list widgets")
me.treeRoot.ListWidgets() tree.ListWidgets()
case "b": case "b":
log.Log(NOW, "show buttons") log.Log(NOW, "show buttons")
me.treeRoot.ShowButtons() tree.ShowButtons()
case "g": case "g":
me.myTree.SendToolkitLoad("gocui") me.myTree.SendToolkitLoad("gocui")
case "a": case "a":
@ -63,6 +65,7 @@ func simpleStdin() {
case "p": case "p":
debug.PrintStack() debug.PrintStack()
me.myTree.SendToolkitPanic() me.myTree.SendToolkitPanic()
os.Exit(0)
return return
case "q": case "q":
return return
@ -71,7 +74,7 @@ func simpleStdin() {
default: default:
i, _ := strconv.Atoi(s) i, _ := strconv.Atoi(s)
log.Log(NOW, "got input:", i) log.Log(NOW, "got input:", i)
n := me.treeRoot.FindWidgetId(i) n := tree.FindWidgetId(i)
if n != nil { if n != nil {
n.DumpWidget("found node") n.DumpWidget("found node")
for i, s := range n.State.Strings { for i, s := range n.State.Strings {

View File

@ -1,6 +1,8 @@
package main package main
import ( import (
"sync"
"go.wit.com/toolkits/tree" "go.wit.com/toolkits/tree"
) )
@ -13,6 +15,8 @@ type guiWidget struct {
val map[string]int val map[string]int
} }
var initOnce sync.Once // run initPlugin() only once
// It's probably a terrible idea to call this 'me' // It's probably a terrible idea to call this 'me'
var me config var me config

24
tree.go
View File

@ -1,24 +0,0 @@
package main
/*
This is reference code for toolkit developers
*/
import (
"go.wit.com/widget"
)
// Other goroutines must use this to access the GUI
//
// You can not acess / process the GUI thread directly from
// other goroutines. This is due to the nature of how
// Linux, MacOS and Windows work (they all work differently. suprise. surprise.)
//
// this sets the channel to send user events back from the plugin
func Callback(guiCallback chan widget.Action) {
me.myTree.Callback(guiCallback)
}
func PluginChannel() chan widget.Action {
return me.myTree.PluginChannel()
}

72
treeInit.go Normal file
View File

@ -0,0 +1,72 @@
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
/*
DO NOT EDIT THIS FILE
this file is the same for every GUI toolkit plugin
when you are making a new GUI toolkit plugin for
a specific toolkit, you just need to define these
functions.
for example, in the "gocui" toolkit, the functions
below are what triggers the "gocui" GO package
to draw labels, buttons, windows, etc
If you are starting out trying to make a new GUI toolkit,
all you have to do is copy this file over. Then
work on making these functions. addWidget(), setText(), etc.
That's it!
*/
package main
/*
This is reference code for toolkit developers
This is how information is passed in GO back to the application
via the GO 'plugin' concept
TODO: switch this to protocol buffers
*/
import (
"go.wit.com/toolkits/tree"
"go.wit.com/widget"
)
// Other goroutines must use this to access the GUI
//
// You can not acess / process the GUI thread directly from
// other goroutines. This is due to the nature of how
// Linux, MacOS and Windows work (they all work differently. suprise. surprise.)
//
// this sets the channel to send user events back from the plugin
func Callback(guiCallback chan widget.Action) {
me.myTree.Callback(guiCallback)
}
func PluginChannel() chan widget.Action {
initOnce.Do(initPlugin)
return me.myTree.PluginChannel()
}
func initTree() *tree.TreeInfo {
t := tree.New()
t.PluginName = PLUGIN
t.Add = newAdd
t.SetTitle = setTitle
t.SetLabel = setLabel
t.SetText = setText
t.AddText = addText
t.Enable = enableWidget
t.Disable = disableWidget
t.SetChecked = setChecked
t.ToolkitClose = toolkitClose
t.ShowTable = showTable
return t
}