summaryrefslogtreecommitdiff
path: root/cmds
diff options
context:
space:
mode:
Diffstat (limited to 'cmds')
-rw-r--r--cmds/gui-demo/Makefile5
-rw-r--r--cmds/gui-demo/demo-window.go33
-rw-r--r--cmds/gui-demo/main.go68
-rw-r--r--cmds/gui-example/Makefile6
-rw-r--r--cmds/gui-example/demo-window.go105
-rw-r--r--cmds/gui-example/main.go68
-rw-r--r--cmds/gui-example/os.go99
-rwxr-xr-xcmds/helloworld/helloworldbin0 -> 3097960 bytes
-rw-r--r--cmds/helloworld/main.go27
9 files changed, 411 insertions, 0 deletions
diff --git a/cmds/gui-demo/Makefile b/cmds/gui-demo/Makefile
new file mode 100644
index 0000000..41fdd10
--- /dev/null
+++ b/cmds/gui-demo/Makefile
@@ -0,0 +1,5 @@
+run: build
+ ./gui-demo
+
+build:
+ go build
diff --git a/cmds/gui-demo/demo-window.go b/cmds/gui-demo/demo-window.go
new file mode 100644
index 0000000..fd8e8f4
--- /dev/null
+++ b/cmds/gui-demo/demo-window.go
@@ -0,0 +1,33 @@
+package main
+
+import "log"
+
+import "git.wit.org/wit/gui"
+
+func demoClick (n *gui.Node) {
+ log.Println("demoClick() Dumping node:")
+ n.Dump()
+}
+
+func addDemoTab(n *gui.Node, title string) {
+ newNode := n.AddTab(title, nil)
+ if (gui.Config.Debug) {
+ newNode.Dump()
+ }
+ newNode.ListChildren(false)
+
+ groupNode1 := newNode.AddGroup("group 1")
+ groupNode1.AddComboBox("demoCombo1", "foo", "bar", "stuff")
+ groupNode1.AddComboBox("demoCombo3", "foo 3", "bar", "stuff")
+
+ groupNode1.Dump()
+
+ butNode1 := groupNode1.AddButton("button1", demoClick)
+ butNode1.Dump()
+
+ butNode2 := groupNode1.AddButton("button2", demoClick)
+ butNode2.Dump()
+
+ groupNode2 := newNode.AddGroup("group 2")
+ groupNode2.AddComboBox("demoCombo2", "more 1", "more 2", "more 3")
+}
diff --git a/cmds/gui-demo/main.go b/cmds/gui-demo/main.go
new file mode 100644
index 0000000..8eae878
--- /dev/null
+++ b/cmds/gui-demo/main.go
@@ -0,0 +1,68 @@
+package main
+
+import (
+ "log"
+ "os"
+ "time"
+
+ "git.wit.org/wit/gui"
+)
+
+// This initializes the first window
+//
+// Then starts a goroutine to demonstrate how to
+// inject things into the GUI
+func main() {
+ log.Println("Starting my Control Panel")
+
+ go gui.Main(initGUI)
+
+ watchGUI()
+}
+
+// This initializes the first window
+func initGUI() {
+ gui.Config.Title = "WIT GUI Window Demo 1"
+ gui.Config.Width = 640
+ gui.Config.Height = 480
+ gui.Config.Exit = myExit
+ node1 := gui.NewWindow()
+ addDemoTab(node1, "A Simple Tab Demo")
+
+ gui.Config.Title = "WIT GUI Window Demo 2"
+ gui.Config.Width = 640
+ gui.Config.Height = 240
+ gui.Config.Exit = myExit
+ node2 := gui.NewWindow()
+ node2.DemoAndlabsUiTab("A Simple andlabs/ui Tab Demo")
+}
+
+// This demonstrates how to properly interact with the GUI
+// You can not involke the GUI from external goroutines in most cases.
+func watchGUI() {
+ var i = 1
+ for {
+ log.Println("Waiting", i, "seconds")
+ i += 1
+ time.Sleep(1 * time.Second)
+ if i == 4 {
+ log.Println("Opening a Debug Window via the gui.Queue()")
+ gui.Config.Width = 800
+ gui.Config.Height = 300
+ gui.Config.Exit = myDebugExit
+ gui.Queue(gui.DebugWindow)
+ }
+ }
+}
+
+func myExit(n *gui.Node) {
+ log.Println()
+ log.Println("Entered myExit() on node.Name =", n.Name)
+ log.Println()
+ os.Exit(0)
+}
+
+func myDebugExit(n *gui.Node) {
+ log.Println("Entered myDebugExit() on node.Name =", n.Name)
+ log.Println("Don't actually os.Exit()")
+}
diff --git a/cmds/gui-example/Makefile b/cmds/gui-example/Makefile
new file mode 100644
index 0000000..638cffc
--- /dev/null
+++ b/cmds/gui-example/Makefile
@@ -0,0 +1,6 @@
+run: build
+ ./gui-example
+
+build:
+ GO111MODULE="off" go -v get .
+ GO111MODULE="off" go build
diff --git a/cmds/gui-example/demo-window.go b/cmds/gui-example/demo-window.go
new file mode 100644
index 0000000..993900d
--- /dev/null
+++ b/cmds/gui-example/demo-window.go
@@ -0,0 +1,105 @@
+package main
+
+import "log"
+import "reflect"
+
+import "git.wit.org/wit/gui"
+
+import "github.com/davecgh/go-spew/spew"
+
+func demoClick (n *gui.Node) {
+ log.Println("demoClick() Dumping node:")
+ n.Dump()
+}
+
+var username = "jcarr"
+var hostname = "fire"
+
+func newClick (n *gui.Node) {
+ var tmp []string
+ junk := "ssh -v " + username + "@" + hostname
+ log.Println("junk = " , junk)
+ xterm(junk)
+ log.Println("tmp = " , reflect.ValueOf(tmp).Kind())
+ // spew.Dump(tmp)
+}
+
+func addDemoTab(n *gui.Node, title string) {
+ newNode := n.AddTab(title, nil)
+ if (gui.Config.Debug) {
+ newNode.Dump()
+ }
+ newNode.ListChildren(false)
+
+ groupNode1 := newNode.AddGroup("group 1")
+ cbNode := groupNode1.AddComboBox("username", "root", "jcarr", "hugo")
+ cbNode.OnChanged(func () {
+ username = cbNode.GetText()
+ })
+ groupNode1.AddComboBox("demoCombo3", "foo 3", "bar", "stuff")
+
+ groupNode1.Dump()
+
+ butNode1 := groupNode1.AddButton("button1", demoClick)
+ butNode1.Dump()
+
+ butNode2 := groupNode1.AddButton("button2", newClick)
+ butNode2.Dump()
+
+ groupNode2 := newNode.AddGroup("group 2")
+ groupNode2.AddComboBox("demoCombo2", "more 1", "more 2", "more 3")
+
+ gNode := newNode.AddGroup("domU")
+ makeSSHbutton(gNode, "hugo@www", "www.wit.org")
+ makeSSHbutton(gNode, "check.lab", "check.lab.wit.org")
+ makeSSHbutton(gNode, "gobuild.lab", "gobuild.lab.wit.org")
+ makeSSHbutton(gNode, "gobuild2.lab", "gobuild2.lab.wit.org")
+
+/////////////////////////////// Column DNS ////////////////////////////////
+ gNode = newNode.AddGroup("dns")
+ makeSSHbutton(gNode, "bind.wit.org", "bind.wit.org")
+ makeSSHbutton(gNode, "ns1.wit.com", "ns1.wit.com")
+ makeSSHbutton(gNode, "ns2.wit.com", "ns2.wit.com")
+ makeSSHbutton(gNode, "coredns", "coredns.lab.wit.org")
+
+/////////////////////////////// PHYS 530 //////////////////////////////////
+ gNode = newNode.AddGroup("phys 530")
+ // makeXtermButton(gNode, "openwrt", "SUBDOMAIN", "ssh -4 -v root@openwrt")
+ gNode.AddButton("openwrt", func (*gui.Node) {
+ stuff := "ssh -4 -v root@openwrt"
+ xterm(stuff)
+ })
+ makeSSHbutton (gNode, "mirrors", "mirrors.wit.org")
+ makeSSHbutton (gNode, "node004", "node004.lab.wit.org")
+ makeSSHbutton (gNode, "lenovo-z70", "lenovo-z70.lab.wit.org")
+
+/////////////////////////////// PHYS 522 //////////////////////////////////
+ gNode = newNode.AddGroup("phys 522")
+ // makeXtermButton(gNode, "openwrt2", "SUBDOMAIN", "ssh -4 -v root@openwrt2")
+ gNode.AddButton("openwrt2", func (*gui.Node) {
+ stuff := "ssh -4 -v root@openwrt2"
+ xterm(stuff)
+ })
+ makeSSHbutton (gNode, "fire.lab", "fire.lab.wit.org")
+ makeSSHbutton (gNode, "predator", "predator.lab.wit.org")
+
+/////////////////////////////// FLOAT /////////////////////////////////////
+ gNode = newNode.AddGroup("float")
+ makeSSHbutton(gNode, "root@asus-n501vw", "asus-n501vw.lab.wit.org")
+}
+
+func makeSSHbutton (n *gui.Node, name string, hostname string) {
+ bNode := n.AddButton(name, func (*gui.Node) {
+ var tmp []string
+ if (username == "") {
+ username = "root"
+ }
+ junk := "ssh -v " + username + "@" + hostname
+ log.Println("junk = " , junk)
+ log.Println("username = '" + username + "'")
+ xterm(junk)
+ log.Println("tmp = " , reflect.ValueOf(tmp).Kind())
+ spew.Dump(tmp)
+ })
+ bNode.Dump()
+}
diff --git a/cmds/gui-example/main.go b/cmds/gui-example/main.go
new file mode 100644
index 0000000..8eae878
--- /dev/null
+++ b/cmds/gui-example/main.go
@@ -0,0 +1,68 @@
+package main
+
+import (
+ "log"
+ "os"
+ "time"
+
+ "git.wit.org/wit/gui"
+)
+
+// This initializes the first window
+//
+// Then starts a goroutine to demonstrate how to
+// inject things into the GUI
+func main() {
+ log.Println("Starting my Control Panel")
+
+ go gui.Main(initGUI)
+
+ watchGUI()
+}
+
+// This initializes the first window
+func initGUI() {
+ gui.Config.Title = "WIT GUI Window Demo 1"
+ gui.Config.Width = 640
+ gui.Config.Height = 480
+ gui.Config.Exit = myExit
+ node1 := gui.NewWindow()
+ addDemoTab(node1, "A Simple Tab Demo")
+
+ gui.Config.Title = "WIT GUI Window Demo 2"
+ gui.Config.Width = 640
+ gui.Config.Height = 240
+ gui.Config.Exit = myExit
+ node2 := gui.NewWindow()
+ node2.DemoAndlabsUiTab("A Simple andlabs/ui Tab Demo")
+}
+
+// This demonstrates how to properly interact with the GUI
+// You can not involke the GUI from external goroutines in most cases.
+func watchGUI() {
+ var i = 1
+ for {
+ log.Println("Waiting", i, "seconds")
+ i += 1
+ time.Sleep(1 * time.Second)
+ if i == 4 {
+ log.Println("Opening a Debug Window via the gui.Queue()")
+ gui.Config.Width = 800
+ gui.Config.Height = 300
+ gui.Config.Exit = myDebugExit
+ gui.Queue(gui.DebugWindow)
+ }
+ }
+}
+
+func myExit(n *gui.Node) {
+ log.Println()
+ log.Println("Entered myExit() on node.Name =", n.Name)
+ log.Println()
+ os.Exit(0)
+}
+
+func myDebugExit(n *gui.Node) {
+ log.Println("Entered myDebugExit() on node.Name =", n.Name)
+ log.Println("Don't actually os.Exit()")
+}
diff --git a/cmds/gui-example/os.go b/cmds/gui-example/os.go
new file mode 100644
index 0000000..ce5db8d
--- /dev/null
+++ b/cmds/gui-example/os.go
@@ -0,0 +1,99 @@
+package main
+
+import "log"
+import "strings"
+import "os"
+import "os/exec"
+import "io/ioutil"
+import "errors"
+// import "bufio"
+
+// import "github.com/davecgh/go-spew/spew"
+
+/*
+import "time"
+import "runtime"
+import "runtime/debug"
+import "runtime/pprof"
+
+import "git.wit.org/wit/gui"
+import "git.wit.org/wit/shell"
+import "github.com/gobuffalo/packr"
+*/
+
+func runSimpleCommand(s string) {
+ cmd := strings.TrimSpace(s) // this is like 'chomp' in perl
+ cmd = strings.TrimSuffix(cmd, "\n") // this is like 'chomp' in perl
+ cmdArgs := strings.Fields(cmd)
+ runLinuxCommand(cmdArgs)
+}
+
+var geom string = "120x30+500+500"
+
+func xterm(cmd string) {
+ var tmp []string
+ var argsXterm = []string{"nohup", "xterm", "-geometry", geom}
+ tmp = append(argsXterm, "-hold", "-e", cmd)
+ log.Println("xterm cmd=", cmd)
+ go runCommand(tmp)
+}
+
+func runCommand(cmdArgs []string) {
+ log.Println("runCommand() START", cmdArgs)
+ process := exec.Command(cmdArgs[0], cmdArgs[1:len(cmdArgs)]...)
+ // process := exec.Command("xterm", "-e", "ping localhost")
+ log.Println("runCommand() process.Start()")
+ process.Start()
+ log.Println("runCommand() process.Wait()")
+ err := process.Wait()
+ lookupError(err)
+ log.Println("runCommand() NEED TO CHECK THE TIME HERE TO SEE IF THIS WORKED")
+ log.Println("runCommand() OTHERWISE INFORM THE USER")
+ log.Println("runCommand() END", cmdArgs)
+}
+
+func lookupError(err error) {
+ var (
+ ee *exec.ExitError
+ pe *os.PathError
+ )
+
+ if errors.As(err, &ee) {
+ log.Println("ran, but non-zero exit code =", ee.ExitCode()) // ran, but non-zero exit code
+ } else if errors.As(err, &pe) {
+ log.Printf("os.PathError = %v", pe) // "no such file ...", "permission denied" etc.
+ } else if err != nil {
+ log.Printf("something really bad happened general err = %v", err) // something really bad happened!
+ if exitError, ok := err.(*exec.ExitError); ok {
+ log.Printf("exitError.ExitCode() is %d\n", exitError.ExitCode())
+ }
+ } else {
+ log.Println("success! // ran without error (exit code zero)")
+ }
+}
+
+func runLinuxCommand(cmdArgs []string) (string, error) {
+ process := exec.Command(cmdArgs[0], cmdArgs[1:len(cmdArgs)]...)
+
+ process.Stdin = os.Stdin
+ process.Stderr = os.Stderr
+
+ stdOut, err := process.StdoutPipe()
+ if err != nil {
+ return "", err
+ }
+
+ if err := process.Start(); err != nil {
+ return "", err
+ }
+
+ bytes, err := ioutil.ReadAll(stdOut)
+ if err != nil {
+ return "", err
+ }
+ err = process.Wait()
+ lookupError(err)
+
+ log.Println(string(bytes))
+ return string(bytes), err
+}
diff --git a/cmds/helloworld/helloworld b/cmds/helloworld/helloworld
new file mode 100755
index 0000000..cc41f78
--- /dev/null
+++ b/cmds/helloworld/helloworld
Binary files differ
diff --git a/cmds/helloworld/main.go b/cmds/helloworld/main.go
new file mode 100644
index 0000000..1cb1bbd
--- /dev/null
+++ b/cmds/helloworld/main.go
@@ -0,0 +1,27 @@
+// This creates a simple hello world window
+package main
+
+import (
+ "git.wit.org/wit/gui"
+)
+
+func main() {
+ gui.Main(initGUI)
+}
+
+// This initializes the first window
+func initGUI() {
+ gui.Config.Title = "Hello World golang wit/gui Window"
+ gui.Config.Width = 640
+ gui.Config.Height = 480
+ node1 := gui.NewWindow()
+ addDemoTab(node1, "A Simple Tab Demo")
+ addDemoTab(node1, "A Second Tab")
+}
+
+func addDemoTab(n *gui.Node, title string) {
+ newNode := n.AddTab(title, nil)
+
+ groupNode1 := newNode.AddGroup("group 1")
+ groupNode1.AddComboBox("demoCombo2", "more 1", "more 2", "more 3")
+}