summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/buttons/Makefile26
-rwxr-xr-xexamples/buttons/buttonpluginbin0 -> 6062120 bytes
-rwxr-xr-xexamples/buttons/buttonsbin0 -> 6062120 bytes
-rw-r--r--examples/buttons/log.go78
-rw-r--r--examples/buttons/main.go104
-rw-r--r--examples/cloudflare/Makefile18
-rw-r--r--examples/cloudflare/argv.go30
-rw-r--r--examples/cloudflare/dns.go132
-rw-r--r--examples/cloudflare/main.go84
-rw-r--r--examples/console-ui-helloworld/Makefile15
-rw-r--r--examples/console-ui-helloworld/keybindings.go130
-rw-r--r--examples/console-ui-helloworld/log.go35
-rw-r--r--examples/console-ui-helloworld/main.go83
-rw-r--r--examples/console-ui-helloworld/newJ.go46
-rw-r--r--examples/console-ui-helloworld/views.go114
-rw-r--r--examples/example_test.go45
-rw-r--r--examples/helloworld/Makefile14
-rw-r--r--examples/helloworld/main.go23
18 files changed, 977 insertions, 0 deletions
diff --git a/examples/buttons/Makefile b/examples/buttons/Makefile
new file mode 100644
index 0000000..74b7728
--- /dev/null
+++ b/examples/buttons/Makefile
@@ -0,0 +1,26 @@
+# with andlabs plugin loaded:
+# PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
+# 180006 jcarr 20 0 1918460 41688 31152 S 0.7 0.3 0:00.27 buttonplugin
+
+# with gocui plugin loaded:
+# 180365 jcarr 20 0 1392668 24364 12596 S 2.0 0.2 0:00.09 buttonplugin
+#
+
+run: build
+ ./buttons --gui andlabs
+
+build-release:
+ go get -v -u -x .
+ go build
+ ./buttons
+
+build:
+ GO111MODULE="off" go get -v -x .
+ GO111MODULE="off" go build
+
+update:
+ GO111MODULE="off" go get -v -u -x .
+
+log:
+ reset
+ tail -f /tmp/witgui.* /tmp/guilogfile
diff --git a/examples/buttons/buttonplugin b/examples/buttons/buttonplugin
new file mode 100755
index 0000000..3f4dee3
--- /dev/null
+++ b/examples/buttons/buttonplugin
Binary files differ
diff --git a/examples/buttons/buttons b/examples/buttons/buttons
new file mode 100755
index 0000000..01ea9aa
--- /dev/null
+++ b/examples/buttons/buttons
Binary files differ
diff --git a/examples/buttons/log.go b/examples/buttons/log.go
new file mode 100644
index 0000000..7d65d05
--- /dev/null
+++ b/examples/buttons/log.go
@@ -0,0 +1,78 @@
+// This creates a simple hello world window
+package main
+
+import (
+ "fmt"
+ arg "github.com/alexflint/go-arg"
+ "git.wit.org/wit/gui"
+ log "git.wit.org/wit/gui/log"
+)
+
+
+var args struct {
+ Foo string
+ Bar bool
+ User string `arg:"env:USER"`
+ Demo bool `help:"run a demo"`
+ gui.GuiArgs
+ log.LogArgs
+}
+
+/*
+var f1 *os.File
+var f2 *os.File
+var err error
+*/
+
+func init() {
+ arg.MustParse(&args)
+ fmt.Println(args.Foo, args.Bar, args.User)
+
+ if (args.Gui != "") {
+ gui.GuiArg.Gui = args.Gui
+ }
+ log.Log(true, "INIT() args.GuiArg.Gui =", gui.GuiArg.Gui)
+
+/*
+ log.Println()
+ log.Println("STDOUT is now at /tmp/guilogfile")
+ log.Println("STDOUT is now at /tmp/guilogfile")
+ log.Println()
+ f1, err = os.OpenFile(outfile, os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)
+ if err != nil {
+ log.Fatalf("error opening file: %v", err)
+ }
+ // hmm. is there a trick here or must this be in main()
+ // defer f.Close()
+
+ log.SetOutput(f1)
+ log.Println("This is a test log entry")
+*/
+}
+
+/*
+func captureSTDOUT() {
+ f2, _ = os.OpenFile("/tmp/my.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0664)
+ multiWriter := io.MultiWriter(os.Stderr, f2)
+ rd, wr, err := os.Pipe()
+ if err != nil {
+ os.Exit(1)
+ }
+
+ // overwrite os.Stdout
+ os.Stderr = wr
+
+ go func() {
+ scanner := bufio.NewScanner(rd)
+ for scanner.Scan() {
+ stdoutLine := scanner.Text()
+ multiWriter.Write([]byte(stdoutLine + "\n"))
+ }
+ }()
+
+ fmt.Println("foobar")
+
+ // hacky sleep to ensure the go routine can write before program exits
+ time.Sleep(time.Second)
+}
+*/
diff --git a/examples/buttons/main.go b/examples/buttons/main.go
new file mode 100644
index 0000000..3200e9e
--- /dev/null
+++ b/examples/buttons/main.go
@@ -0,0 +1,104 @@
+// This is a simple example
+package main
+
+import (
+ "fmt"
+ "log"
+ "strconv"
+ "git.wit.org/wit/gui"
+)
+
+var title string = "Demo Plugin Window"
+var outfile string = "/tmp/guilogfile"
+var myGui *gui.Node
+
+var buttonCounter int = 5
+var gridW int = 5
+var gridH int = 3
+
+func main() {
+ // This will turn on all debugging
+ // gui.SetDebug(true)
+
+ myGui = gui.New().Default()
+ buttonWindow()
+
+ // This is just a optional goroutine to watch that things are alive
+ gui.Watchdog()
+ gui.StandardExit()
+}
+
+// This creates a window
+func buttonWindow() {
+ var w, t, g, more, more2 *gui.Node
+
+ log.Println("buttonWindow() START")
+
+ w = myGui.NewWindow(title).SetText("Nueva Ventana de Botones")
+ t = w.NewTab("buttonTab is this thing")
+ g = t.NewGroup("buttonGroup")
+ g1 := t.NewGroup("buttonGroup 2")
+ more = g1.NewGroup("more")
+ g1.NewButton("hello2", func () {
+ log.Println("world2")
+ })
+ more2 = g1.NewGrid("gridnuts", gridW, gridH)
+
+ more2.NewLabel("more2")
+
+ g.NewButton("this app is useful for plugin debuggin", func () {
+ })
+ g.NewLabel("STDOUT is set to: " + outfile)
+
+ g.NewButton("hello", func () {
+ log.Println("world")
+ })
+
+ g.NewButton("Load 'gocui'", func () {
+ // this set the xterm and mate-terminal window title. maybe works generally?
+ fmt.Println("\033]0;" + title + "blah \007")
+ myGui.LoadToolkit("gocui")
+ })
+
+ g.NewButton("Load 'andlabs'", func () {
+ myGui.LoadToolkit("andlabs")
+ })
+
+ g.NewButton("NewButton(more)", func () {
+ name := "foobar " + strconv.Itoa(buttonCounter)
+ log.Println("NewButton(more) Adding button", name)
+ buttonCounter += 1
+ more.NewButton(name, func () {
+ log.Println("Got all the way to main() name =", name)
+ })
+ })
+
+ g.NewButton("NewButton(more2)", func () {
+ name := "foobar " + strconv.Itoa(buttonCounter)
+ log.Println("NewButton(more2) Adding button", name)
+ buttonCounter += 1
+ more2.NewButton(name, func () {
+ log.Println("Got all the way to main() name =", name)
+ })
+ })
+
+ g.NewButton("NewButton(more2 d)", func () {
+ name := "d" + strconv.Itoa(buttonCounter)
+ log.Println("NewButton(more2 d) Adding button", name)
+ buttonCounter += 1
+ more2.NewButton(name, func () {
+ log.Println("Got all the way to main() name =", name)
+ })
+ })
+
+ g.NewButton("NewGroup()", func () {
+ name := "neat " + strconv.Itoa(buttonCounter)
+ log.Println("NewGroup() Adding button", name)
+ buttonCounter += 1
+ more.NewGroup(name)
+ })
+
+ g.NewButton("gui.DebugWindow()", func () {
+ gui.DebugWindow()
+ })
+}
diff --git a/examples/cloudflare/Makefile b/examples/cloudflare/Makefile
new file mode 100644
index 0000000..bcd88c6
--- /dev/null
+++ b/examples/cloudflare/Makefile
@@ -0,0 +1,18 @@
+run: build
+ ./cloudflare
+
+build-release:
+ go get -v -u -x .
+ go build
+ ./cloudflare
+
+build:
+ GO111MODULE="off" go get -v -x .
+ GO111MODULE="off" go build
+
+update:
+ GO111MODULE="off" go get -v -u -x .
+
+log:
+ reset
+ tail -f /tmp/witgui.* /tmp/guilogfile
diff --git a/examples/cloudflare/argv.go b/examples/cloudflare/argv.go
new file mode 100644
index 0000000..38579c7
--- /dev/null
+++ b/examples/cloudflare/argv.go
@@ -0,0 +1,30 @@
+// This creates a simple hello world window
+package main
+
+import (
+ "fmt"
+ arg "github.com/alexflint/go-arg"
+ "git.wit.org/wit/gui"
+ log "git.wit.org/wit/gui/log"
+)
+
+
+var args struct {
+ Foo string
+ Bar bool
+ User string `arg:"env:USER"`
+ Demo bool `help:"run a demo"`
+ gui.GuiArgs
+ log.LogArgs
+}
+
+func init() {
+ arg.MustParse(&args)
+ fmt.Println(args.Foo, args.Bar, args.User)
+
+ if (args.Gui != "") {
+ gui.GuiArg.Gui = args.Gui
+ }
+ log.Log(true, "INIT() args.GuiArg.Gui =", gui.GuiArg.Gui)
+
+}
diff --git a/examples/cloudflare/dns.go b/examples/cloudflare/dns.go
new file mode 100644
index 0000000..eb8de23
--- /dev/null
+++ b/examples/cloudflare/dns.go
@@ -0,0 +1,132 @@
+// This is a simple example
+package main
+
+import (
+ "os"
+ "log"
+ "encoding/json"
+ "fmt"
+ "io/ioutil"
+ "net/http"
+ "strconv"
+)
+
+// Define a struct to match the JSON structure of the response.
+// This structure should be adjusted based on the actual format of the response.
+type DNSRecords struct {
+ Result []struct {
+ ID string `json:"id"`
+ Type string `json:"type"`
+ Name string `json:"name"`
+ Content string `json:"content"`
+ Proxied bool `json:"proxied"`
+ Proxiable bool `json:"proxiable"`
+ TTL int `json:"ttl"`
+ } `json:"result"`
+}
+
+// var domain string = "wit.org"
+// var os.Getenv("CLOUDFLARE_DOMAIN")
+
+func loadDNS(hostname string) {
+ log.Println("adding DNS record")
+
+ newt := mainWindow.NewTab(hostname)
+ newg := newt.NewGroup("more")
+ grid := newg.NewGrid("gridnuts", 5, gridH)
+
+// grid.NewButton("Type", func () {
+// log.Println("sort by Type")
+// })
+ typedrop := grid.NewDropdown("type")
+ typedrop.AddText("A")
+ typedrop.AddText("AAAA")
+ typedrop.AddText("CNAME")
+ typedrop.Custom = func () {
+ log.Println("custom dropdown() a =", typedrop.Name, typedrop.S)
+ }
+ grid.NewButton("Name", func () {
+ log.Println("sort by Name")
+ })
+ grid.NewButton("Protection", func () {
+ log.Println("sort proxied")
+ })
+ grid.NewButton("TTL", func () {
+ log.Println("sort by TTL")
+ })
+ grid.NewButton("Value", func () {
+ log.Println("sort by Value")
+ })
+
+ newt.NewButton("Save", func () {
+ log.Println("save stuff to cloudflare")
+ })
+
+ records := getRecords()
+ for _, record := range records.Result {
+ grid.NewLabel(record.Type)
+ textbox := grid.NewTextbox(record.Name)
+ textbox.SetText(record.Name)
+ if (record.Proxied) {
+ grid.NewLabel("Proxied")
+ } else {
+ grid.NewLabel("DNS")
+ }
+ var ttl, short string
+ if (record.TTL == 1) {
+ ttl = "Auto"
+ } else {
+ ttl = strconv.Itoa(record.TTL)
+ }
+ grid.NewLabel(ttl)
+ // short = fmt.Sprintf("%80s", record.Content)
+ short = record.Content
+ if len(short) > 40 {
+ short = short[:40] // Slice the first 20 characters
+ }
+
+ namebox := grid.NewTextbox(short)
+ namebox.SetText(short)
+
+ fmt.Printf("ID: %s, Type: %s, Name: %s, short Content: %s\n", record.ID, record.Type, record.Name, short)
+ fmt.Printf("\tproxied: %b, %b, string TTL: %i\n", record.Proxied, record.Proxiable, ttl)
+ }
+}
+
+func getRecords() *DNSRecords {
+ var url string = os.Getenv("CLOUDFLARE_URL")
+ req, err := http.NewRequest("GET", url, nil)
+ if err != nil {
+ fmt.Println(err)
+ return nil
+ }
+
+ var authKey string = os.Getenv("CLOUDFLARE_AUTHKEY")
+ var email string = os.Getenv("CLOUDFLARE_EMAIL")
+
+ // Set headers
+ req.Header.Set("X-Auth-Key", authKey)
+ req.Header.Set("X-Auth-Email", email)
+
+ client := &http.Client{}
+ resp, err := client.Do(req)
+ if err != nil {
+ fmt.Println(err)
+ return nil
+ }
+ defer resp.Body.Close()
+
+ body, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ fmt.Println(err)
+ return nil
+ }
+
+ var records DNSRecords
+ if err := json.Unmarshal(body, &records); err != nil {
+ fmt.Println(err)
+ return nil
+ }
+
+ return &records
+}
diff --git a/examples/cloudflare/main.go b/examples/cloudflare/main.go
new file mode 100644
index 0000000..b83d276
--- /dev/null
+++ b/examples/cloudflare/main.go
@@ -0,0 +1,84 @@
+// This is a simple example
+package main
+
+import (
+ "os"
+ "fmt"
+ "log"
+ "git.wit.org/wit/gui"
+)
+
+var title string = "Cloudflare DNS Control Panel"
+var outfile string = "/tmp/guilogfile"
+var myGui *gui.Node
+
+var buttonCounter int = 5
+var gridW int = 5
+var gridH int = 3
+
+var mainWindow, more, more2 *gui.Node
+
+func main() {
+ myGui = gui.New().Default()
+ buttonWindow()
+
+ // This is just a optional goroutine to watch that things are alive
+ gui.Watchdog()
+ gui.StandardExit()
+}
+
+// This creates a window
+func buttonWindow() {
+ var t, g *gui.Node
+
+ log.Println("buttonWindow() START")
+
+ mainWindow = myGui.NewWindow(title).SetText(title)
+ t = mainWindow.NewTab("Cloudflare")
+ g = t.NewGroup("buttons")
+ g1 := t.NewGroup("buttonGroup 2")
+
+ more = g1.NewGroup("more")
+ showCloudflareCredentials(more)
+
+ // more2 = g1.NewGrid("gridnuts", gridW, gridH)
+
+ var domain string = os.Getenv("CLOUDFLARE_DOMAIN")
+ if (domain == "") {
+ domain = "example.org"
+ }
+
+ g.NewButton("Load " + domain + " DNS", func () {
+ loadDNS(domain)
+ })
+
+ g.NewButton("Load 'gocui'", func () {
+ // this set the xterm and mate-terminal window title. maybe works generally?
+ fmt.Println("\033]0;" + title + "blah \007")
+ myGui.LoadToolkit("gocui")
+ })
+
+ g.NewButton("Load 'andlabs'", func () {
+ myGui.LoadToolkit("andlabs")
+ })
+
+ g.NewButton("gui.DebugWindow()", func () {
+ gui.DebugWindow()
+ })
+}
+
+func showCloudflareCredentials(box *gui.Node) {
+ grid := box.NewGrid("credsGrid", 2, 4) // width = 2
+
+ grid.NewLabel("Domain")
+ grid.NewLabel(os.Getenv("CLOUDFLARE_DOMAIN"))
+
+ grid.NewLabel("Auth Key")
+ grid.NewLabel(os.Getenv("CLOUDFLARE_AUTHKEY"))
+
+ grid.NewLabel("Email")
+ grid.NewLabel(os.Getenv("CLOUDFLARE_EMAIL"))
+
+ grid.NewLabel("URL")
+ grid.NewLabel(os.Getenv("CLOUDFLARE_URL"))
+}
diff --git a/examples/console-ui-helloworld/Makefile b/examples/console-ui-helloworld/Makefile
new file mode 100644
index 0000000..f63c8a9
--- /dev/null
+++ b/examples/console-ui-helloworld/Makefile
@@ -0,0 +1,15 @@
+run: build
+ ./console-ui-helloworld
+ reset
+ ldd ./console-ui-helloworld
+
+build-release:
+ go get -v -u -x .
+ go build
+
+build:
+ GO111MODULE="off" go get -v -x .
+ GO111MODULE="off" go build
+
+update:
+ GO111MODULE="off" go get -v -u -x .
diff --git a/examples/console-ui-helloworld/keybindings.go b/examples/console-ui-helloworld/keybindings.go
new file mode 100644
index 0000000..8c4623b
--- /dev/null
+++ b/examples/console-ui-helloworld/keybindings.go
@@ -0,0 +1,130 @@
+// Copyright 2014 The gocui Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+// "errors"
+// "fmt"
+ "log"
+// "strings"
+
+ "github.com/awesome-gocui/gocui"
+)
+
+func initKeybindings(g *gocui.Gui) error {
+ log.Println("got to initKeybindings")
+ if err := g.SetKeybinding("", 'q', gocui.ModNone,
+ func(g *gocui.Gui, v *gocui.View) error {
+ return gocui.ErrQuit
+ }); err != nil {
+ return err
+ }
+ if err := g.SetKeybinding("", 'Q', gocui.ModNone,
+ func(g *gocui.Gui, v *gocui.View) error {
+ return gocui.ErrQuit
+ }); err != nil {
+ return err
+ }
+ if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone,
+ func(g *gocui.Gui, v *gocui.View) error {
+ return gocui.ErrQuit
+ }); err != nil {
+ return err
+ }
+ if err := g.SetKeybinding("", gocui.KeySpace, gocui.ModNone,
+ func(g *gocui.Gui, v *gocui.View) error {
+ return newView(g)
+ }); err != nil {
+ return err
+ }
+ if err := g.SetKeybinding("", gocui.KeyBackspace, gocui.ModNone,
+ func(g *gocui.Gui, v *gocui.View) error {
+ return delView(g)
+ }); err != nil {
+ return err
+ }
+ if err := g.SetKeybinding("", gocui.KeyBackspace2, gocui.ModNone,
+ func(g *gocui.Gui, v *gocui.View) error {
+ return delView(g)
+ }); err != nil {
+ return err
+ }
+ if err := g.SetKeybinding("", gocui.KeyTab, gocui.ModNone,
+ func(g *gocui.Gui, v *gocui.View) error {
+ log.Println("tab", v.Name())
+ return nextView(g, true)
+ }); err != nil {
+ return err
+ }
+ if err := g.SetKeybinding("", gocui.KeyArrowLeft, gocui.ModNone,
+ func(g *gocui.Gui, v *gocui.View) error {
+ return moveView(g, v, -delta, 0)
+ }); err != nil {
+ return err
+ }
+ if err := g.SetKeybinding("", gocui.KeyArrowRight, gocui.ModNone,
+ func(g *gocui.Gui, v *gocui.View) error {
+ return moveView(g, v, delta, 0)
+ }); err != nil {
+ return err
+ }
+ if err := g.SetKeybinding("", gocui.KeyArrowDown, gocui.ModNone,
+ func(g *gocui.Gui, v *gocui.View) error {
+ log.Println("down", v.Name())
+ return moveView(g, v, 0, delta)
+ }); err != nil {
+ return err
+ }
+ if err := g.SetKeybinding("", gocui.KeyArrowUp, gocui.ModNone,
+ func(g *gocui.Gui, v *gocui.View) error {
+ log.Println("up", v.Name())
+ return moveView(g, v, 0, -delta)
+ }); err != nil {
+ return err
+ }
+ if err := g.SetKeybinding("", gocui.KeyEnter, gocui.ModNone,
+ func(g *gocui.Gui, v *gocui.View) error {
+ log.Println("enter", v.Name())
+ return nil
+ }); err != nil {
+ return err
+ }
+ if err := g.SetKeybinding("", 't', gocui.ModNone,
+ func(g *gocui.Gui, v *gocui.View) error {
+ _, err := g.SetViewOnTop(views[curView])
+ return err
+ }); err != nil {
+ return err
+ }
+ if err := g.SetKeybinding("", 'b', gocui.ModNone,
+ func(g *gocui.Gui, v *gocui.View) error {
+ _, err := g.SetViewOnBottom(views[curView])
+ return err
+ }); err != nil {
+ return err
+ }
+ if err := g.SetKeybinding("", 'j', gocui.ModNone,
+ func(g *gocui.Gui, v *gocui.View) error {
+ return newJ(g)
+ }); err != nil {
+ return err
+ }
+ if err := g.SetKeybinding("", 'h', gocui.ModNone,
+ func(g *gocui.Gui, v *gocui.View) error {
+ log.Println("help", v.Name())
+ tmp, _ := g.SetViewOnTop("help")
+ log.Println("help 2", tmp.Name())
+// g.SetView("help", 2, 2, 30, 15, 0);
+ g.SetCurrentView("help")
+// moveView(g, tmp, 0, -delta)
+ if err := g.DeleteView("help"); err != nil {
+ panic(err)
+ }
+ return nil
+ }); err != nil {
+ return err
+ }
+ return nil
+}
diff --git a/examples/console-ui-helloworld/log.go b/examples/console-ui-helloworld/log.go
new file mode 100644
index 0000000..b05beaf
--- /dev/null
+++ b/examples/console-ui-helloworld/log.go
@@ -0,0 +1,35 @@
+// This creates a simple hello world window
+package main
+
+import (
+ "log"
+ "fmt"
+ "os"
+ arg "github.com/alexflint/go-arg"
+)
+
+
+var args struct {
+ Foo string
+ Bar bool
+ User string `arg:"env:USER"`
+ Demo bool `help:"run a demo"`
+}
+
+var f *os.File
+var err error
+
+func init() {
+ arg.MustParse(&args)
+ fmt.Println(args.Foo, args.Bar, args.User)
+
+ f, err = os.OpenFile("/tmp/guilogfile", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)
+ if err != nil {
+ log.Fatalf("error opening file: %v", err)
+ }
+ // hmm. is there a trick here or must this be in main()
+ // defer f.Close()
+
+ log.SetOutput(f)
+ log.Println("This is a test log entry")
+}
diff --git a/examples/console-ui-helloworld/main.go b/examples/console-ui-helloworld/main.go
new file mode 100644
index 0000000..d16b805
--- /dev/null
+++ b/examples/console-ui-helloworld/main.go
@@ -0,0 +1,83 @@
+// Copyright 2014 The gocui Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+ "errors"
+ "fmt"
+ "log"
+
+ "github.com/awesome-gocui/gocui"
+)
+
+const delta = 1
+
+var (
+ views = []string{}
+ curView = -1
+ idxView = 0
+ currentX = 5
+ currentY = 2
+ groupSize = 0
+ baseGui *gocui.Gui
+)
+
+var helpLabel *gocui.View
+
+func main() {
+ // setup log to write to a file
+// logInit()
+
+ g, err := gocui.NewGui(gocui.OutputNormal, true)
+ baseGui = g
+ if err != nil {
+ log.Panicln(err)
+ }
+ defer g.Close()
+
+ g.Highlight = true
+ g.SelFgColor = gocui.ColorRed
+ g.SelFrameColor = gocui.ColorRed
+
+ g.SetManagerFunc(layout)
+
+ if err := initKeybindings(g); err != nil {
+ log.Panicln(err)
+ }
+ if err := newView(g); err != nil {
+ log.Panicln(err)
+ }
+
+ addButton("hello")
+
+ addGroup("blank")
+ addButton("world")
+
+ if err := g.MainLoop(); err != nil && !errors.Is(err, gocui.ErrQuit) {
+ log.Panicln(err)
+ }
+}
+
+func layout(g *gocui.Gui) error {
+ var err error
+ maxX, _ := g.Size()
+ helpLabel, err = g.SetView("help", maxX-32, 0, maxX-1, 11, 0)
+ if err != nil {
+ if !errors.Is(err, gocui.ErrUnknownView) {
+ return err
+ }
+ fmt.Fprintln(helpLabel, "KEYBINDINGS")
+ fmt.Fprintln(helpLabel, "Enter: Click Button")
+ fmt.Fprintln(helpLabel, "Tab/Space: Switch Buttons")
+ fmt.Fprintln(helpLabel, "")
+ fmt.Fprintln(helpLabel, "h: Help")
+ fmt.Fprintln(helpLabel, "Backspace: Delete Button")
+ fmt.Fprintln(helpLabel, "Arrow keys: Move Button")
+ fmt.Fprintln(helpLabel, "t: Move Button to the top")
+ fmt.Fprintln(helpLabel, "b: Move Button to the button")
+ fmt.Fprintln(helpLabel, "Ctrl-C or Q: Exit")
+ }
+ return nil
+}
diff --git a/examples/console-ui-helloworld/newJ.go b/examples/console-ui-helloworld/newJ.go
new file mode 100644
index 0000000..47c7439
--- /dev/null
+++ b/examples/console-ui-helloworld/newJ.go
@@ -0,0 +1,46 @@
+// Copyright 2014 The gocui Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+ "errors"
+ "fmt"
+ "log"
+ "strings"
+
+ "github.com/awesome-gocui/gocui"
+)
+
+var topX int = 2
+var bottomX int = 20
+var topY int = 2
+var bottomY int = 7
+
+func newJ(g *gocui.Gui) error {
+ // maxX, maxY := g.Size()
+ name := fmt.Sprintf("jcarr %v test ", idxView)
+ v, err := g.SetView(name, topX, topY, bottomX, bottomY, 0)
+ if err == nil {
+ return err
+ }
+ if !errors.Is(err, gocui.ErrUnknownView) {
+ return err
+ }
+
+ v.Wrap = true
+ fmt.Fprintln(v, name)
+ fmt.Fprintln(v, strings.Repeat("foo\n", 2))
+ // fmt.Fprintln(v, strings.Repeat(name+" ", 30))
+ log.Println("newJ added a new view", v.Name())
+
+ if _, err := g.SetCurrentView(name); err != nil {
+ return err
+ }
+
+ views = append(views, name)
+ curView = len(views) - 1
+ idxView += 1
+ return nil
+}
diff --git a/examples/console-ui-helloworld/views.go b/examples/console-ui-helloworld/views.go
new file mode 100644
index 0000000..50287c2
--- /dev/null
+++ b/examples/console-ui-helloworld/views.go
@@ -0,0 +1,114 @@
+// Copyright 2014 The gocui Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+ "errors"
+ "fmt"
+ "log"
+ "strings"
+
+ "github.com/awesome-gocui/gocui"
+)
+
+func addGroup(name string) {
+ log.Println("addGroup()", name)
+ currentY = 2
+ currentX += groupSize + 6
+}
+
+func addButton(name string) error {
+ t := len(name)
+ v, err := baseGui.SetView(name, currentX, currentY, currentX+t+3, currentY+2, 0)
+ if err == nil {
+ return err
+ }
+ if !errors.Is(err, gocui.ErrUnknownView) {
+ return err
+ }
+
+ v.Wrap = true
+ fmt.Fprintln(v, " " + name)
+ fmt.Fprintln(v, strings.Repeat("foo\n", 2))
+
+ if _, err := baseGui.SetCurrentView(name); err != nil {
+ return err
+ }
+
+ views = append(views, name)
+ curView = len(views) - 1
+ idxView += 1
+ currentY += 3
+ if (groupSize < len(views)) {
+ groupSize = len(views)
+ }
+ return nil
+}
+
+func newView(g *gocui.Gui) error {
+ maxX, maxY := g.Size()
+ name := fmt.Sprintf("v%v", idxView)
+ v, err := g.SetView(name, maxX/2-5, maxY/2-5, maxX/2+5, maxY/2+5, 0)
+ if err == nil {
+ return err
+ }
+ if !errors.Is(err, gocui.ErrUnknownView) {
+ return err
+ }
+
+ v.Wrap = true
+ fmt.Fprintln(v, strings.Repeat(name+" ", 30))
+
+ if _, err := g.SetCurrentView(name); err != nil {
+ return err
+ }
+
+ views = append(views, name)
+ curView = len(views) - 1
+ idxView += 1
+ return nil
+}
+
+func delView(g *gocui.Gui) error {
+ if len(views) <= 1 {
+ return nil
+ }
+
+ if err := g.DeleteView(views[curView]); err != nil {
+ return err
+ }
+ views = append(views[:curView], views[curView+1:]...)
+
+ return nextView(g, false)
+}
+
+func nextView(g *gocui.Gui, disableCurrent bool) error {
+ next := curView + 1
+ if next > len(views)-1 {
+ next = 0
+ }
+
+ if _, err := g.SetCurrentView(views[next]); err != nil {
+ return err
+ }
+
+ curView = next
+ return nil
+}
+
+func moveView(g *gocui.Gui, v *gocui.View, dx, dy int) error {
+ name := v.Name()
+ x0, y0, x1, y1, err := g.ViewPosition(name)
+ if err != nil {
+ return err
+ }
+ log.Println(x0, y0, x1, y1)
+ if _, err := g.SetView(name, x0+dx, y0+dy, x1+dx, y1+dy, 0); err != nil {
+ return err
+ }
+ x0, y0, x1, y1, err = g.ViewPosition(name)
+ log.Println(x0, y0, x1, y1)
+ return nil
+}
diff --git a/examples/example_test.go b/examples/example_test.go
new file mode 100644
index 0000000..f65cad1
--- /dev/null
+++ b/examples/example_test.go
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2013-2016 Dave Collins <[email protected]>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package gui_test
+
+import (
+ "git.wit.org/wit/gui"
+)
+
+// This example demonstrates how to create a NewWindow()
+//
+// Interacting with a GUI in a cross platform fashion adds some
+// unusual problems. To obvuscate those, andlabs/ui starts a
+// goroutine that interacts with the native gui toolkits
+// on the Linux, MacOS, Windows, etc.
+//
+// Because of this oddity, to initialize a new window, the
+// function is not passed any arguements and instead passes
+// the information via the Config type.
+//
+func ExampleNewWindow() {
+ // Define the name and size
+ gui.Config.Title = "WIT GUI Window 1"
+ gui.Config.Width = 640
+ gui.Config.Height = 480
+
+ // Create the Window
+ gui.NewWindow()
+
+ // Output:
+ // You get a window
+}
diff --git a/examples/helloworld/Makefile b/examples/helloworld/Makefile
new file mode 100644
index 0000000..961ed8c
--- /dev/null
+++ b/examples/helloworld/Makefile
@@ -0,0 +1,14 @@
+run: build
+ ./helloworld
+
+build-release:
+ go get -v -u -x .
+ go build
+ ./helloworld
+
+build:
+ GO111MODULE="off" go get -v -x .
+ GO111MODULE="off" go build
+
+update:
+ GO111MODULE="off" go get -v -u -x .
diff --git a/examples/helloworld/main.go b/examples/helloworld/main.go
new file mode 100644
index 0000000..3d8ba40
--- /dev/null
+++ b/examples/helloworld/main.go
@@ -0,0 +1,23 @@
+// This is a simple example
+package main
+
+import (
+ "log"
+ "git.wit.org/wit/gui"
+)
+
+func main() {
+ helloworld()
+ // This is just a optional goroutine to watch that things are alive
+ gui.Watchdog()
+}
+
+// This creates a window
+func helloworld() {
+ myGui := gui.New().Default()
+ myWindow := myGui.NewWindow("helloworld golang wit/gui window")
+
+ myWindow.NewButton("hello", func () {
+ log.Println("world")
+ })
+}