summaryrefslogtreecommitdiff
path: root/cmds/console-ui-helloworld/main.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2022-11-09 08:38:50 -0600
committerJeff Carr <[email protected]>2022-11-09 08:38:50 -0600
commited382bec55be25039e4dcf020d1512139855c9bb (patch)
treefb3a671fd07c03a75cedb8d56b2241108cd792ff /cmds/console-ui-helloworld/main.go
parentb410d0fd083ee89eed410cda2123a22cddcd3f44 (diff)
cleanup of the example commands. more plugin workv0.4.6
add a button in two plugins at the same time! added a button in andlabs/ui & gocui attempt a common widget struct between wit/gui & the plugins start handling missing plugins rename Makefile command examples remote examples used for testing filename improvements golang src code uses lowercase and _ in filenames fix crash when button click function == nil fix wrong name 'gocli' -> 'gocui' keep fighting with goreadme generated README.md Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'cmds/console-ui-helloworld/main.go')
-rw-r--r--cmds/console-ui-helloworld/main.go83
1 files changed, 83 insertions, 0 deletions
diff --git a/cmds/console-ui-helloworld/main.go b/cmds/console-ui-helloworld/main.go
new file mode 100644
index 0000000..d16b805
--- /dev/null
+++ b/cmds/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
+}