summaryrefslogtreecommitdiff
path: root/toolkit/gocui/structs.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2023-04-24 06:22:14 -0500
committerJeff Carr <[email protected]>2023-04-24 06:22:14 -0500
commitd38b05d2d5a2c2ff0c66b541f7d80cbd1c250d76 (patch)
tree5c0540c8efac7cf59fefc2624bf8de5654a7393f /toolkit/gocui/structs.go
parentfbe943540106f1c12971932fd92f9395bbe214b3 (diff)
gocui: always show STDOUT
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'toolkit/gocui/structs.go')
-rw-r--r--toolkit/gocui/structs.go54
1 files changed, 48 insertions, 6 deletions
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
+}