From d38b05d2d5a2c2ff0c66b541f7d80cbd1c250d76 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 24 Apr 2023 06:22:14 -0500 Subject: gocui: always show STDOUT Signed-off-by: Jeff Carr --- toolkit/andlabs/Makefile | 3 +++ toolkit/gocui/main.go | 18 ++++++++----- toolkit/gocui/mouse.go | 29 +++++++++------------ toolkit/gocui/showMsg.go | 51 ------------------------------------- toolkit/gocui/showStdout.go | 62 +++++++++++++++++++++++++++++++++++++++++++++ toolkit/gocui/structs.go | 54 ++++++++++++++++++++++++++++++++++----- 6 files changed, 136 insertions(+), 81 deletions(-) delete mode 100644 toolkit/gocui/showMsg.go create mode 100644 toolkit/gocui/showStdout.go (limited to 'toolkit') diff --git a/toolkit/andlabs/Makefile b/toolkit/andlabs/Makefile index 8b0502c..65bd8f0 100644 --- a/toolkit/andlabs/Makefile +++ b/toolkit/andlabs/Makefile @@ -2,3 +2,6 @@ all: plugin plugin: GO111MODULE="off" go build -buildmode=plugin -o ../andlabs.so + +goget: + GO111MODULE="off" go get -v -t -u diff --git a/toolkit/gocui/main.go b/toolkit/gocui/main.go index 7f9958f..c3418a6 100644 --- a/toolkit/gocui/main.go +++ b/toolkit/gocui/main.go @@ -13,12 +13,9 @@ import ( // to this toolkit from the wit/gui golang package func init() { log(logInfo, "Init() of awesome-gocui") - me.defaultWidth = 10 - me.defaultHeight = 2 // this means by default one line of text in a button + Set(&me, "default") me.defaultBehavior = true - me.horizontalPadding = 20 - me.horizontalPadding = 20 me.groupPadding = 4 me.buttonPadding = 3 @@ -29,14 +26,21 @@ func init() { me.padW = 3 me.padH = 3 + // todo, remove all of these + me.defaultWidth = 10 + me.defaultHeight = 2 // this means by default one line of text in a button + + me.horizontalPadding = 20 + me.horizontalPadding = 20 + // todo, remove all of these + me.pluginChan = make(chan toolkit.Action) log(logNow, "Init() start pluginChan") go catchActionChannel() - sleep(.1) + sleep(.1) // probably not needed, but in here for now under development go main() - // probably not needed, but in here for now under development - sleep(.1) + sleep(.1) // probably not needed, but in here for now under development } // this sets the channel to send user events back from the plugin diff --git a/toolkit/gocui/mouse.go b/toolkit/gocui/mouse.go index 4337f42..0ad8e29 100644 --- a/toolkit/gocui/mouse.go +++ b/toolkit/gocui/mouse.go @@ -35,33 +35,28 @@ func MouseMain() { func layout(g *gocui.Gui) error { maxX, maxY := g.Size() + mx, my := g.MousePosition() if _, err := g.View("msg"); msgMouseDown && err == nil { moveMsg(g) } - if v, err := g.SetView("global", -1, -1, maxX, maxY, 0); err != nil { + // if v, err := g.SetView("global", -1, -1, maxX, maxY, 0); err != nil { + // what is this do? I made it just the top 2 lines for now. Is this useful for something? + if v, err := g.SetView("global", -1, -1, maxX, 2, 10); err != nil { if !errors.Is(err, gocui.ErrUnknownView) { + log("global failed", maxX, maxY) return err } v.Frame = false } - /* - if v, err := g.SetView("but1", 2, 2, 22, 7, 0); err != nil { - if !errors.Is(err, gocui.ErrUnknownView) { - return err - } - v.SelBgColor = gocui.ColorGreen - v.SelFgColor = gocui.ColorBlack - fmt.Fprintln(v, "Button 1 - line 1") - fmt.Fprintln(v, "Button 1 - line 2") - fmt.Fprintln(v, "Button 1 - line 3") - fmt.Fprintln(v, "Button 1 - line 4") - if _, err := g.SetCurrentView("but1"); err != nil { - return err - } - } - */ helplayout(g) + if widgetView, _ := g.View("msg"); widgetView == nil { + log(logInfo, "create output widget now", maxX, maxY, mx, my) + makeOutputWidget(g, "this is a create before a mouse click") + } else { + log(logInfo, "output widget already exists", maxX, maxY, mx, my) + } updateHighlightedView(g) + log(logInfo, "layout() END", maxX, maxY, mx, my) return nil } diff --git a/toolkit/gocui/showMsg.go b/toolkit/gocui/showMsg.go deleted file mode 100644 index e749834..0000000 --- a/toolkit/gocui/showMsg.go +++ /dev/null @@ -1,51 +0,0 @@ -// 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" - - "github.com/awesome-gocui/gocui" -) - -var outputW int = 80 -var outputH int = 24 - -func moveMsg(g *gocui.Gui) { - mx, my := g.MousePosition() - if !movingMsg && (mx != initialMouseX || my != initialMouseY) { - movingMsg = true - } - g.SetView("msg", mx-xOffset, my-yOffset, mx-xOffset+outputW, my-yOffset+outputH, 0) -} - -func showMsg(g *gocui.Gui, v *gocui.View) error { - var l string - var err error - - if _, err := g.SetCurrentView(v.Name()); err != nil { - return err - } - - _, cy := v.Cursor() - if l, err = v.Line(cy); err != nil { - l = "" - } - // setOutput(me.rootNode) - - maxX, maxY := g.Size() - if v, err := g.SetView("msg", maxX/2, maxY/2, maxX/2+outputW, maxY/2+outputH, 0); err == nil || errors.Is(err, gocui.ErrUnknownView) { - v.Clear() - v.SelBgColor = gocui.ColorCyan - v.SelFgColor = gocui.ColorBlack - l += "foo\n" + "bar\n" - fmt.Fprintln(v, l) - } - // g.SetViewOnTop("msg") - g.SetViewBeneath("msg", "help", 24) - // g.SetViewOnBottom("msg") - return nil -} diff --git a/toolkit/gocui/showStdout.go b/toolkit/gocui/showStdout.go new file mode 100644 index 0000000..c367ab9 --- /dev/null +++ b/toolkit/gocui/showStdout.go @@ -0,0 +1,62 @@ +// 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" + + "github.com/awesome-gocui/gocui" +) + +var outputW int = 80 +var outputH int = 24 + +func moveMsg(g *gocui.Gui) { + mx, my := g.MousePosition() + if !movingMsg && (mx != initialMouseX || my != initialMouseY) { + movingMsg = true + } + g.SetView("msg", mx-xOffset, my-yOffset, mx-xOffset+outputW, my-yOffset+outputH, 0) +} + +func showMsg(g *gocui.Gui, v *gocui.View) error { + var l string + var err error + + if _, err := g.SetCurrentView(v.Name()); err != nil { + return err + } + + _, cy := v.Cursor() + if l, err = v.Line(cy); err != nil { + l = "" + } + // setOutput(me.rootNode) + + makeOutputWidget(g, l) + return nil +} + +func makeOutputWidget(g *gocui.Gui, stringFromMouseClick string) { + maxX, maxY := g.Size() + v, err := g.SetView("msg", maxX-32, maxY/2, maxX/2+outputW, maxY/2+outputH, 0) + // help, err := g.SetView("help", maxX-32, 0, maxX-1, 13, 0) + if errors.Is(err, gocui.ErrUnknownView) { + log("this is supposed to happen?", err) + } + + if (err != nil) { + log("create output window failed", err) + return + } + + v.Clear() + v.SelBgColor = gocui.ColorCyan + v.SelFgColor = gocui.ColorBlack + fmt.Fprintln(v, "figure out how to capture STDOUT to here\n" + stringFromMouseClick) + g.SetViewOnBottom("msg") + return +} diff --git a/toolkit/gocui/structs.go b/toolkit/gocui/structs.go index e8e8172..4ee74c7 100644 --- a/toolkit/gocui/structs.go +++ b/toolkit/gocui/structs.go @@ -10,6 +10,8 @@ package main import ( "fmt" + "reflect" + "strconv" "sync" "github.com/awesome-gocui/gocui" "git.wit.org/wit/gui/toolkit" @@ -37,12 +39,12 @@ type config struct { defaultHeight int // nextW int // where the next window or tab flag should go - padW int + padW int `default:"3" dense:"2"` padH int - // where the raw corner is - rawW int - rawH int + // the raw beginning of each window (or tab) + rawW int `default:"7"` + rawH int `default:"3"` bookshelf bool // do you want things arranged in the box like a bookshelf or a stack? canvas bool // if set to true, the windows are a raw canvas @@ -52,8 +54,8 @@ type config struct { margin bool // add space around the frames of windows horizontalPadding int - groupPadding int - buttonPadding int + groupPadding int `default:"6" dense:"2"` // this is supposed to be how far to indent to the left + buttonPadding int `default:"4" dense:"3"` // if 3, buttons slightly overlap } var ( @@ -156,3 +158,43 @@ func (w *cuiWidget) Write(p []byte) (n int, err error) { return len(p), nil } + +func Set(ptr interface{}, tag string) error { + if reflect.TypeOf(ptr).Kind() != reflect.Ptr { + return fmt.Errorf("Not a pointer") + } + + v := reflect.ValueOf(ptr).Elem() + t := v.Type() + + for i := 0; i < t.NumField(); i++ { + if defaultVal := t.Field(i).Tag.Get(tag); defaultVal != "-" { + if err := setField(v.Field(i), defaultVal); err != nil { + return err + } + + } + } + return nil +} + +func setField(field reflect.Value, defaultVal string) error { + + if !field.CanSet() { + log("Can't set value\n") + return fmt.Errorf("Can't set value\n") + } + + switch field.Kind() { + case reflect.Int: + if val, err := strconv.ParseInt(defaultVal, 1, 64); err == nil { + field.Set(reflect.ValueOf(int(val)).Convert(field.Type())) + } + case reflect.String: + field.Set(reflect.ValueOf(defaultVal).Convert(field.Type())) + case reflect.Bool: + field.Set(reflect.ValueOf(defaultVal).Convert(field.Type())) + } + + return nil +} -- cgit v1.2.3