diff options
Diffstat (limited to 'gocui')
| -rw-r--r-- | gocui/add.go | 13 | ||||
| -rw-r--r-- | gocui/args.go | 6 | ||||
| -rw-r--r-- | gocui/checkbox.go | 18 | ||||
| -rw-r--r-- | gocui/click.go | 48 | ||||
| -rw-r--r-- | gocui/color.go | 59 | ||||
| -rw-r--r-- | gocui/common.go | 40 | ||||
| -rw-r--r-- | gocui/debug.go | 14 | ||||
| -rw-r--r-- | gocui/fakefile.go | 2 | ||||
| -rw-r--r-- | gocui/gocui.go | 6 | ||||
| -rw-r--r-- | gocui/help.go | 4 | ||||
| -rw-r--r-- | gocui/keybindings.go | 50 | ||||
| -rw-r--r-- | gocui/main.go | 8 | ||||
| -rw-r--r-- | gocui/mouse.go | 30 | ||||
| -rw-r--r-- | gocui/place.go | 26 | ||||
| -rw-r--r-- | gocui/plugin.go | 18 | ||||
| -rw-r--r-- | gocui/showStdout.go | 18 | ||||
| -rw-r--r-- | gocui/structs.go | 68 | ||||
| -rw-r--r-- | gocui/tab.go | 6 | ||||
| -rw-r--r-- | gocui/view.go | 50 | ||||
| -rw-r--r-- | gocui/widget.go | 30 |
20 files changed, 258 insertions, 256 deletions
diff --git a/gocui/add.go b/gocui/add.go index e76b2ee..151d4d2 100644 --- a/gocui/add.go +++ b/gocui/add.go @@ -1,12 +1,13 @@ package main import ( + "go.wit.com/lib/widget" log "go.wit.com/log" - "go.wit.com/gui/widget" ) var fakeStartWidth int = me.FakeW var fakeStartHeight int = me.TabH + me.FramePadH + // setup fake labels for non-visible things off screen func (n *node) setFake() { w := n.tk @@ -16,11 +17,11 @@ func (n *node) setFake() { fakeStartHeight += w.gocuiSize.Height() // TODO: use the actual max hight of the terminal window - if (fakeStartHeight > 24) { + if fakeStartHeight > 24 { fakeStartHeight = me.TabH fakeStartWidth += me.FakeW } - if (true) { + if true { n.showView() } } @@ -70,9 +71,9 @@ func (n *node) addWidget() { return default: /* - if n.IsCurrent() { - n.updateCurrent() - } + if n.IsCurrent() { + n.updateCurrent() + } */ } n.showWidgetPlacement(true, "addWidget()") diff --git a/gocui/args.go b/gocui/args.go index 916728a..eca1db9 100644 --- a/gocui/args.go +++ b/gocui/args.go @@ -4,7 +4,7 @@ package main this enables command line options from other packages like 'gui' and 'log' */ -import ( +import ( "go.wit.com/log" ) @@ -22,10 +22,10 @@ func init() { full := "toolkit/nocui" short := "nocui" - NOW = log.NewFlag( "NOW", true, full, short, "temp debugging stuff") + NOW = log.NewFlag("NOW", true, full, short, "temp debugging stuff") INFO = log.NewFlag("INFO", false, full, short, "normal debugging stuff") - WARN = log.NewFlag("WARN", true, full, short, "bad things") + WARN = log.NewFlag("WARN", true, full, short, "bad things") SPEW = log.NewFlag("SPEW", false, full, short, "spew stuff") ERROR = log.NewFlag("ERROR", false, full, short, "toolkit errors") diff --git a/gocui/checkbox.go b/gocui/checkbox.go index 18dd8fa..76b4377 100644 --- a/gocui/checkbox.go +++ b/gocui/checkbox.go @@ -1,13 +1,13 @@ package main import ( -// "github.com/awesome-gocui/gocui" - "go.wit.com/gui/widget" + // "github.com/awesome-gocui/gocui" + "go.wit.com/lib/widget" ) func (n *node) setCheckbox(b any) { w := n.tk - if (n.WidgetType != widget.Checkbox) { + if n.WidgetType != widget.Checkbox { return } if widget.GetBool(b) { @@ -20,13 +20,13 @@ func (n *node) setCheckbox(b any) { t := len(n.tk.label) + 1 w.gocuiSize.w1 = w.gocuiSize.w0 + t -// w.realWidth = w.gocuiSize.Width() + me.PadW -// w.realHeight = w.gocuiSize.Height() + me.PadH + // w.realWidth = w.gocuiSize.Width() + me.PadW + // w.realHeight = w.gocuiSize.Height() + me.PadH -// if w.frame { -// w.realWidth += me.FramePadW -// w.realHeight += me.FramePadH -// } + // if w.frame { + // w.realWidth += me.FramePadW + // w.realHeight += me.FramePadH + // } n.deleteView() n.showView() diff --git a/gocui/click.go b/gocui/click.go index c59fc0f..6d8b20a 100644 --- a/gocui/click.go +++ b/gocui/click.go @@ -3,8 +3,8 @@ package main import ( "fmt" "github.com/awesome-gocui/gocui" + "go.wit.com/lib/widget" "go.wit.com/log" - "go.wit.com/gui/widget" ) // set isCurrent = false everywhere @@ -92,15 +92,15 @@ func (n *node) doWidgetClick() { case widget.Root: // THIS IS THE BEGINING OF THE LAYOUT log.Log(NOW, "doWidgetClick()", n.progname) - redoWindows(0,0) + redoWindows(0, 0) case widget.Flag: log.Log(NOW, "doWidgetClick() FLAG widget name =", n.progname) log.Log(NOW, "doWidgetClick() if this is the dropdown menu, handle it here?") case widget.Window: - if (me.currentWindow == n) { + if me.currentWindow == n { return } - if (me.currentWindow != nil) { + if me.currentWindow != nil { unsetCurrent(me.currentWindow) me.currentWindow.setColor(&colorWindow) me.currentWindow.hideWidgets() @@ -111,7 +111,7 @@ func (n *node) doWidgetClick() { n.setColor(&colorActiveW) n.redoTabs(me.TabW, me.TabH) for _, child := range n.children { - if (child.currentTab == true) { + if child.currentTab == true { log.Log(NOW, "FOUND CURRENT TAB", child.progname) setCurrentTab(child) child.placeWidgets(me.RawW, me.RawH) @@ -124,12 +124,12 @@ func (n *node) doWidgetClick() { } */ case widget.Tab: - if (n.IsCurrent()) { + if n.IsCurrent() { return // do nothing if you reclick on the already selected tab } // find the window and disable the active tab p := n.parent - if (p != nil) { + if p != nil { p.hideWidgets() p.redoTabs(me.TabW, me.TabH) unsetCurrent(p) @@ -149,7 +149,7 @@ func (n *node) doWidgetClick() { // n.placeWidgets(p.tk.startH, newH) n.toggleTree() case widget.Checkbox: - if (widget.GetBool(n.value)) { + if widget.GetBool(n.value) { n.setCheckbox(false) } else { n.setCheckbox(true) @@ -166,7 +166,7 @@ func (n *node) doWidgetClick() { n.showWidgets() case widget.Box: // w.showWidgetPlacement(logNow, "drawTree()") - if (n.direction == widget.Horizontal) { + if n.direction == widget.Horizontal { log.Log(NOW, "BOX IS HORIZONTAL", n.progname) } else { log.Log(NOW, "BOX IS VERTICAL", n.progname) @@ -177,7 +177,7 @@ func (n *node) doWidgetClick() { n.doUserEvent() case widget.Dropdown: log.Log(NOW, "do the dropdown here") - if (me.ddview == nil) { + if me.ddview == nil { me.ddview = addDropdown() tk := me.ddview.tk tk.gocuiSize.w0 = 20 @@ -189,7 +189,7 @@ func (n *node) doWidgetClick() { tk.gocuiSize.h0, tk.gocuiSize.w1, tk.gocuiSize.h1, 0) - if (tk.v == nil) { + if tk.v == nil { return } tk.v.Wrap = true @@ -200,7 +200,7 @@ func (n *node) doWidgetClick() { return } log.Log(NOW, "doWidgetClick() visible =", me.ddview.Visible()) - if (me.ddview.Visible()) { + if me.ddview.Visible() { me.ddview.SetVisible(false) me.baseGui.DeleteView("ddview") me.ddview.tk.v = nil @@ -224,8 +224,9 @@ func (n *node) doWidgetClick() { } var toggle bool = true + func (n *node) toggleTree() { - if (toggle) { + if toggle { n.drawTree(toggle) toggle = false } else { @@ -234,15 +235,14 @@ func (n *node) toggleTree() { } } - // display the widgets in the binary tree func (n *node) drawTree(draw bool) { w := n.tk - if (w == nil) { + if w == nil { return } n.showWidgetPlacement(true, "drawTree()") - if (draw) { + if draw { // w.textResize() n.showView() } else { @@ -261,9 +261,9 @@ func click(g *gocui.Gui, v *gocui.View) error { log.Log(INFO, "click() START", v.Name()) // n := me.rootNode.findWidgetName(v.Name()) n := findUnderMouse() - if (n != nil) { + if n != nil { log.Log(NOW, "click() Found widget =", n.WidgetId, n.progname, ",", n.label) - if (n.progname == "DropBox") { + if n.progname == "DropBox" { log.Log(NOW, "click() this is the dropdown menu. set a flag here what did I click? where is the mouse?") log.Log(NOW, "click() set a global dropdown clicked flag=true here") me.ddClicked = true @@ -285,7 +285,7 @@ func click(g *gocui.Gui, v *gocui.View) error { func findUnderMouse() *node { var found *node var widgets []*node - var f func (n *node) + var f func(n *node) w, h := me.baseGui.MousePosition() // find buttons that are below where the mouse button click @@ -293,13 +293,13 @@ func findUnderMouse() *node { widget := n.tk // ignore widgets that are not visible if n.Visible() { - if ((widget.gocuiSize.w0 <= w) && (w <= widget.gocuiSize.w1) && - (widget.gocuiSize.h0 <= h) && (h <= widget.gocuiSize.h1)) { + if (widget.gocuiSize.w0 <= w) && (w <= widget.gocuiSize.w1) && + (widget.gocuiSize.h0 <= h) && (h <= widget.gocuiSize.h1) { widgets = append(widgets, n) found = n } } - if (n == me.ddview) { + if n == me.ddview { log.Log(NOW, "findUnderMouse() found ddview") if n.Visible() { log.Log(NOW, "findUnderMouse() and ddview is visable. hide it here. TODO: find highlighted row") @@ -331,14 +331,14 @@ func ctrlDown(g *gocui.Gui, v *gocui.View) error { // var widgets []*node // var f func (n *node) found = findUnderMouse() - if (me.ctrlDown == nil) { + if me.ctrlDown == nil { setupCtrlDownWidget() me.ctrlDown.label = found.progname me.ctrlDown.tk.cuiName = "ctrlDown" // me.ctrlDown.parent = me.rootNode } cd := me.ctrlDown.tk - if (found == nil) { + if found == nil { found = me.rootNode } me.ctrlDown.label = found.progname diff --git a/gocui/color.go b/gocui/color.go index ca4301f..45600c3 100644 --- a/gocui/color.go +++ b/gocui/color.go @@ -1,8 +1,8 @@ package main import ( - "math/rand" "github.com/awesome-gocui/gocui" + "math/rand" "go.wit.com/log" ) @@ -13,18 +13,18 @@ import ( type colorT struct { frame gocui.Attribute - fg gocui.Attribute - bg gocui.Attribute + fg gocui.Attribute + bg gocui.Attribute selFg gocui.Attribute selBg gocui.Attribute - name string + name string } var none gocui.Attribute = gocui.AttrNone -var lightPurple gocui.Attribute = gocui.GetColor("#DDDDDD") // light purple -var darkPurple gocui.Attribute = gocui.GetColor("#FFAA55") // Dark Purple -var heavyPurple gocui.Attribute = gocui.GetColor("#88AA55") // heavy purple -var powdererBlue gocui.Attribute = gocui.GetColor("#B0E0E6") // w3c 'powerder blue' +var lightPurple gocui.Attribute = gocui.GetColor("#DDDDDD") // light purple +var darkPurple gocui.Attribute = gocui.GetColor("#FFAA55") // Dark Purple +var heavyPurple gocui.Attribute = gocui.GetColor("#88AA55") // heavy purple +var powdererBlue gocui.Attribute = gocui.GetColor("#B0E0E6") // w3c 'powerder blue' var superLightGrey gocui.Attribute = gocui.GetColor("#55AAFF") // super light grey // Standard defined colors from gocui: @@ -37,28 +37,29 @@ var superLightGrey gocui.Attribute = gocui.GetColor("#55AAFF") // super light gr // v.BgColor = gocui.GetColor("#55AAFF") // super light grey // v.BgColor = gocui.GetColor("#FFC0CB") // 'w3c pink' yellow -// Normal Text On mouseover -// Widget Frame Text background Text background -var colorWindow colorT = colorT{ none , gocui.ColorBlue, none , none , powdererBlue , "normal window"} -var colorActiveW colorT = colorT{ none , none , powdererBlue , none , powdererBlue , "active window"} +// Normal Text On mouseover +// +// Widget Frame Text background Text background +var colorWindow colorT = colorT{none, gocui.ColorBlue, none, none, powdererBlue, "normal window"} +var colorActiveW colorT = colorT{none, none, powdererBlue, none, powdererBlue, "active window"} -var colorTab colorT = colorT{gocui.ColorBlue, gocui.ColorBlue, none , none , powdererBlue , "normal tab"} -var colorActiveT colorT = colorT{gocui.ColorBlue, none , powdererBlue , none , powdererBlue , "active tab"} +var colorTab colorT = colorT{gocui.ColorBlue, gocui.ColorBlue, none, none, powdererBlue, "normal tab"} +var colorActiveT colorT = colorT{gocui.ColorBlue, none, powdererBlue, none, powdererBlue, "active tab"} -var colorButton colorT = colorT{gocui.ColorGreen, none , gocui.ColorWhite, gocui.ColorGreen, gocui.ColorBlack, "normal button"} -var colorLabel colorT = colorT{ none , none , superLightGrey , none , superLightGrey , "normal label"} -var colorGroup colorT = colorT{ none , none , superLightGrey , none , superLightGrey , "normal group"} +var colorButton colorT = colorT{gocui.ColorGreen, none, gocui.ColorWhite, gocui.ColorGreen, gocui.ColorBlack, "normal button"} +var colorLabel colorT = colorT{none, none, superLightGrey, none, superLightGrey, "normal label"} +var colorGroup colorT = colorT{none, none, superLightGrey, none, superLightGrey, "normal group"} // widget debugging colors. these widgets aren't displayed unless you are debugging -var colorRoot colorT = colorT{gocui.ColorRed , none , powdererBlue , none , gocui.ColorBlue, "debug root"} -var colorFlag colorT = colorT{gocui.ColorRed , none , powdererBlue , none , gocui.ColorGreen, "debug flag"} -var colorBox colorT = colorT{gocui.ColorRed , none , lightPurple , none , gocui.ColorCyan, "debug box"} -var colorGrid colorT = colorT{gocui.ColorRed , none , lightPurple , none , gocui.ColorRed, "debug grid"} -var colorNone colorT = colorT{ none , none , none , none , none , "debug none"} +var colorRoot colorT = colorT{gocui.ColorRed, none, powdererBlue, none, gocui.ColorBlue, "debug root"} +var colorFlag colorT = colorT{gocui.ColorRed, none, powdererBlue, none, gocui.ColorGreen, "debug flag"} +var colorBox colorT = colorT{gocui.ColorRed, none, lightPurple, none, gocui.ColorCyan, "debug box"} +var colorGrid colorT = colorT{gocui.ColorRed, none, lightPurple, none, gocui.ColorRed, "debug grid"} +var colorNone colorT = colorT{none, none, none, none, none, "debug none"} -// actually sets the colors for the gocui element +// actually sets the colors for the gocui element // the user will see the colors change when this runs -// TODO: add black/white only flag for ttyS0 +// TODO: add black/white only flag for ttyS0 // TODO: or fix kvm/qemu serial console & SIGWINCH. // TODO: and minicom and uboot and 5 million other things. // TODO: maybe enough of us could actually do that if we made it a goal. @@ -66,15 +67,15 @@ var colorNone colorT = colorT{ none , none , non // TODO: so just a small little 'todo' item here func (n *node) setColor(newColor *colorT) { tk := n.tk - if (tk.color == newColor) { + if tk.color == newColor { // nothing to do since the colors have nto changed return } tk.color = newColor - if (tk.v == nil) { + if tk.v == nil { return } - if (tk.color == nil) { + if tk.color == nil { log.Log(NOW, "Set the node to color = nil") tk.color = &colorNone } @@ -88,7 +89,7 @@ func (n *node) setDefaultWidgetColor() { func (n *node) setDefaultHighlight() { w := n.tk - if (w.v == nil) { + if w.v == nil { log.Log(ERROR, "SetColor() failed on view == nil") return } @@ -105,7 +106,7 @@ func randColor() gocui.Attribute { func (n *node) redoColor(draw bool) { w := n.tk - if (w == nil) { + if w == nil { return } diff --git a/gocui/common.go b/gocui/common.go index 3c67133..267277f 100644 --- a/gocui/common.go +++ b/gocui/common.go @@ -12,8 +12,8 @@ package main */ import ( + "go.wit.com/lib/widget" "go.wit.com/log" - "go.wit.com/gui/widget" ) // this is the channel we send user events like @@ -24,20 +24,20 @@ var callback chan widget.Action var pluginChan chan widget.Action type node struct { - parent *node + parent *node children []*node - WidgetId int // widget ID - WidgetType widget.WidgetType - ParentId int // parent ID + WidgetId int // widget ID + WidgetType widget.WidgetType + ParentId int // parent ID - state widget.State + state widget.State // a reference name for programming and debuggign. Must be unique - progname string + progname string // the text used for button labesl, window titles, checkbox names, etc - label string + label string // horizontal means layout widgets like books on a bookshelf // vertical means layout widgets like books in a stack @@ -51,20 +51,20 @@ type node struct { strings []string // This is used for things like a slider(0,100) - X int - Y int + X int + Y int // This is for the grid size & widget position - W int - H int - AtW int - AtH int + W int + H int + AtW int + AtH int vals []string // dropdown menu items // horizontal bool `default:false` - hasTabs bool // does the window have tabs? + hasTabs bool // does the window have tabs? currentTab bool // the visible tab // the internal plugin toolkit structure @@ -75,7 +75,7 @@ type node struct { // searches the binary tree for a WidgetId func (n *node) findWidgetId(id int) *node { - if (n == nil) { + if n == nil { return nil } @@ -85,7 +85,7 @@ func (n *node) findWidgetId(id int) *node { for _, child := range n.children { newN := child.findWidgetId(id) - if (newN != nil) { + if newN != nil { return newN } } @@ -93,7 +93,7 @@ func (n *node) findWidgetId(id int) *node { } func (n *node) doUserEvent() { - if (callback == nil) { + if callback == nil { log.Log(ERROR, "doUserEvent() callback == nil", n.WidgetId) return } @@ -196,12 +196,12 @@ func addNode(a *widget.Action) *node { n.tk = initWidget(n) // n.tk = new(guiWidget) - if (a.WidgetType == widget.Root) { + if a.WidgetType == widget.Root { log.Log(INFO, "addNode() Root") return n } - if (me.rootNode.findWidgetId(a.WidgetId) != nil) { + if me.rootNode.findWidgetId(a.WidgetId) != nil { log.Log(ERROR, "addNode() WidgetId already exists", a.WidgetId) return me.rootNode.findWidgetId(a.WidgetId) } diff --git a/gocui/debug.go b/gocui/debug.go index fe51943..ee58727 100644 --- a/gocui/debug.go +++ b/gocui/debug.go @@ -2,13 +2,13 @@ package main import ( "fmt" + "go.wit.com/lib/widget" "go.wit.com/log" - "go.wit.com/gui/widget" ) func (n *node) dumpTree(draw bool) { w := n.tk - if (w == nil) { + if w == nil { return } n.showWidgetPlacement(true, "dumpTree()") @@ -19,7 +19,7 @@ func (n *node) dumpTree(draw bool) { } func (n *node) showWidgetPlacement(b bool, s string) { - if (n == nil) { + if n == nil { log.Log(ERROR, "WTF w == nil") return } @@ -27,7 +27,7 @@ func (n *node) showWidgetPlacement(b bool, s string) { var s1 string var pId int - if (n.parent == nil) { + if n.parent == nil { log.Log(INFO, "showWidgetPlacement() parent == nil", n.WidgetId, w.cuiName) pId = 0 } else { @@ -41,8 +41,8 @@ func (n *node) showWidgetPlacement(b bool, s string) { } else { s1 += fmt.Sprintf(" ") } - if (n.parent != nil) { - if (n.parent.WidgetType == widget.Grid) { + if n.parent != nil { + if n.parent.WidgetType == widget.Grid { s1 += fmt.Sprintf("At(%2d,%2d) ", n.AtW, n.AtH) } } @@ -55,7 +55,7 @@ func (n *node) dumpWidget(pad string) { } func (n *node) listWidgets() { - if (n == nil) { + if n == nil { return } diff --git a/gocui/fakefile.go b/gocui/fakefile.go index c6b8877..47ef529 100644 --- a/gocui/fakefile.go +++ b/gocui/fakefile.go @@ -2,8 +2,8 @@ package main import ( "bytes" - "io" "errors" + "io" ) type FakeFile struct { diff --git a/gocui/gocui.go b/gocui/gocui.go index 1c2e8f7..6d924f8 100644 --- a/gocui/gocui.go +++ b/gocui/gocui.go @@ -56,7 +56,7 @@ func gocuiEvent(g *gocui.Gui) error { if widgetView, _ := g.View("msg"); widgetView == nil { log.Log(NOW, "handleEvent() create output widget now", maxX, maxY, mx, my) makeOutputWidget(g, "this is a create before a mouse click") - if (me.logStdout != nil) { + if me.logStdout != nil { // setOutput(me.logStdout) } } else { @@ -75,7 +75,7 @@ func setFrame(b bool) { // TODO: figure out what this might be useful for // what is this do? I made it just 2 lines for now. Is this useful for something? v := SetView("global", 5, 10, 5, 10, 0) // x0, x1, y1, y2, overlap - if (v == nil) { + if v == nil { log.Log(ERROR, "setFrame() global failed") } v.Frame = b @@ -86,7 +86,7 @@ func quit(g *gocui.Gui, v *gocui.View) error { } func SetView(name string, x0, y0, x1, y1 int, overlaps byte) *gocui.View { - if (me.baseGui == nil) { + if me.baseGui == nil { log.Log(ERROR, "SetView() ERROR: me.baseGui == nil") return nil } diff --git a/gocui/help.go b/gocui/help.go index 82d5cc5..832b397 100644 --- a/gocui/help.go +++ b/gocui/help.go @@ -42,13 +42,13 @@ func helplayout() error { maxX, _ := g.Size() var newW int = 8 - for _, s := range(helpText) { + for _, s := range helpText { if newW < len(s) { newW = len(s) } } - help, err := g.SetView("help", maxX-(newW + me.FramePadW), 0, maxX-1, len(helpText) + me.FramePadH, 0) + help, err := g.SetView("help", maxX-(newW+me.FramePadW), 0, maxX-1, len(helpText)+me.FramePadH, 0) if err != nil { if !errors.Is(err, gocui.ErrUnknownView) { return err diff --git a/gocui/keybindings.go b/gocui/keybindings.go index 8a4d194..79666fa 100644 --- a/gocui/keybindings.go +++ b/gocui/keybindings.go @@ -7,8 +7,8 @@ package main import ( "github.com/awesome-gocui/gocui" + "go.wit.com/lib/widget" "go.wit.com/log" - "go.wit.com/gui/widget" ) func defaultKeybindings(g *gocui.Gui) error { @@ -30,13 +30,13 @@ func defaultKeybindings(g *gocui.Gui) error { if err := g.SetKeybinding("", gocui.MouseLeft, gocui.ModMouseCtrl, ctrlDown); err != nil { return err } -// if err := g.SetKeybinding(w.v.Name(), gocui.MouseLeft, gocui.ModNone, click); err != nil { -// return err -// } + // if err := g.SetKeybinding(w.v.Name(), gocui.MouseLeft, gocui.ModNone, click); err != nil { + // return err + // } /* - if err := g.SetKeybinding("", gocui.MouseLeft, gocui.ModNone, globalDown); err != nil { - return err - } + if err := g.SetKeybinding("", gocui.MouseLeft, gocui.ModNone, globalDown); err != nil { + return err + } */ if err := g.SetKeybinding("msg", gocui.MouseLeft, gocui.ModNone, msgDown); err != nil { return err @@ -51,7 +51,7 @@ func addDebugKeys(g *gocui.Gui) { func(g *gocui.Gui, v *gocui.View) error { fakeStartWidth = me.FakeW fakeStartHeight = me.TabH + me.FramePadH - if (showDebug) { + if showDebug { me.rootNode.showFake() showDebug = false } else { @@ -59,12 +59,12 @@ func addDebugKeys(g *gocui.Gui) { showDebug = true } return nil - }) + }) // display the help menu g.SetKeybinding("", '?', gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { - if (showHelp) { + if showHelp { helplayout() showHelp = false } else { @@ -72,48 +72,48 @@ func addDebugKeys(g *gocui.Gui) { showHelp = true } return nil - }) + }) // redraw all the widgets g.SetKeybinding("", 'r', gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { - if (redoWidgets) { - redoWindows(0,0) + if redoWidgets { + redoWindows(0, 0) redoWidgets = false } else { me.rootNode.hideWidgets() redoWidgets = true } return nil - }) + }) // hide all widgets g.SetKeybinding("", 'h', gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { me.rootNode.hideWidgets() return nil - }) + }) // show all widgets g.SetKeybinding("", 's', gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { me.rootNode.showWidgets() return nil - }) + }) // list all widgets g.SetKeybinding("", 'L', gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { me.rootNode.listWidgets() return nil - }) + }) // list all widgets with positions g.SetKeybinding("", 'M', gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { me.rootNode.dumpTree(true) return nil - }) + }) // log to output window g.SetKeybinding("", 'o', gocui.ModNone, @@ -127,33 +127,33 @@ func addDebugKeys(g *gocui.Gui) { // setOutput(me.logStdout.tk) } return nil - }) + }) // exit g.SetKeybinding("", 'q', gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { standardExit() return nil - }) + }) g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { standardExit() return nil - }) + }) g.SetKeybinding("", gocui.KeyCtrlD, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { - if (showDebug) { + if showDebug { var a widget.Action a.Value = true a.ActionType = widget.EnableDebug callback <- a } return nil - }) + }) g.SetKeybinding("", gocui.KeyCtrlV, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { return nil - }) + }) // panic g.SetKeybinding("", 'p', gocui.ModNone, @@ -161,5 +161,5 @@ func addDebugKeys(g *gocui.Gui) { standardExit() panic("forced panic in gocui") return nil - }) + }) } diff --git a/gocui/main.go b/gocui/main.go index 72bad7c..37eed29 100644 --- a/gocui/main.go +++ b/gocui/main.go @@ -7,8 +7,8 @@ package main import ( "os" + "go.wit.com/lib/widget" "go.wit.com/log" - "go.wit.com/gui/widget" ) // sets defaults and establishes communication @@ -38,9 +38,9 @@ func catchActionChannel() { log.Log(INFO, "catchActionChannel() START") for { log.Log(INFO, "catchActionChannel() infinite for() loop restarted select on channel") - select { + select { case a := <-pluginChan: - if (me.baseGui == nil) { + if me.baseGui == nil { // something went wrong initializing the gocui log.Log(ERROR, "ERROR: console did not initialize") continue @@ -84,7 +84,7 @@ func main() { var err error log.Log(INFO, "main() start Init()") - outf, err = os.OpenFile("/tmp/witgui.log", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666) + outf, err = os.OpenFile("/tmp/witgui.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) if err != nil { log.Error(err, "error opening file: %v") os.Exit(0) diff --git a/gocui/mouse.go b/gocui/mouse.go index 9d8dd8d..02efc0d 100644 --- a/gocui/mouse.go +++ b/gocui/mouse.go @@ -38,10 +38,10 @@ func msgDown(g *gocui.Gui, v *gocui.View) error { func hideDDview() error { w, h := me.baseGui.MousePosition() log.Log(NOW, "hide dropdown menu() view msgMouseDown (w,h) =", w, h) - if (me.ddview == nil) { + if me.ddview == nil { return gocui.ErrUnknownView } - if (me.ddview.tk.v == nil) { + if me.ddview.tk.v == nil { return gocui.ErrUnknownView } me.ddview.SetVisible(false) @@ -51,10 +51,10 @@ func hideDDview() error { func showDDview() error { w, h := me.baseGui.MousePosition() log.Log(NOW, "show dropdown menu() view msgMouseDown (w,h) =", w, h) - if (me.ddview == nil) { + if me.ddview == nil { return gocui.ErrUnknownView } - if (me.ddview.tk.v == nil) { + if me.ddview.tk.v == nil { return gocui.ErrUnknownView } me.ddview.SetVisible(true) @@ -64,27 +64,27 @@ func showDDview() error { func mouseUp(g *gocui.Gui, v *gocui.View) error { w, h := g.MousePosition() log.Log(NOW, "mouseUp() view msgMouseDown (check here for dropdown menu click) (w,h) =", w, h) - if (me.ddClicked) { + if me.ddClicked { me.ddClicked = false log.Log(NOW, "mouseUp() ddview is the thing that was clicked", w, h) log.Log(NOW, "mouseUp() find out what the string is here", w, h, me.ddview.tk.gocuiSize.h1) var newZone string = "" - if (me.ddNode != nil) { + if me.ddNode != nil { value := h - me.ddview.tk.gocuiSize.h0 - 1 log.Log(NOW, "mouseUp() me.ddview.tk.gocuiSize.h1 =", me.ddview.tk.gocuiSize.h1) log.Log(NOW, "mouseUp() me.ddNode.vals =", me.ddNode.vals) valsLen := len(me.ddNode.vals) log.Log(NOW, "mouseUp() value =", value, "valsLen =", valsLen) log.Log(NOW, "mouseUp() me.ddNode.vals =", me.ddNode.vals) - if ((value >= 0) && (value < valsLen)) { + if (value >= 0) && (value < valsLen) { newZone = me.ddNode.vals[value] log.Log(NOW, "mouseUp() value =", value, "newZone =", newZone) } } hideDDview() - if (newZone != "") { - if (me.ddNode != nil) { + if newZone != "" { + if me.ddNode != nil { me.ddNode.SetText(newZone) me.ddNode.value = newZone me.ddNode.doUserEvent() @@ -93,10 +93,10 @@ func mouseUp(g *gocui.Gui, v *gocui.View) error { return nil } /* - // if there is a drop down view active, treat it like a dialog box and close it - if (hideDDview() == nil) { - return nil - } + // if there is a drop down view active, treat it like a dialog box and close it + if (hideDDview() == nil) { + return nil + } */ if msgMouseDown { msgMouseDown = false @@ -124,8 +124,8 @@ func mouseDown(g *gocui.Gui, v *gocui.View) error { maxX, _ := g.Size() test := findUnderMouse() msg := fmt.Sprintf("Mouse really down at: %d,%d", mx, my) + "foobar" - if (test == me.ddview) { - if (me.ddview.Visible()) { + if test == me.ddview { + if me.ddview.Visible() { log.Log(NOW, "hide DDview() Mouse really down at:", mx, my) hideDDview() } else { diff --git a/gocui/place.go b/gocui/place.go index 8780bbe..4bdcd42 100644 --- a/gocui/place.go +++ b/gocui/place.go @@ -3,12 +3,12 @@ package main import ( "strings" + "go.wit.com/lib/widget" "go.wit.com/log" - "go.wit.com/gui/widget" ) func (n *node) placeBox(startW int, startH int) { - if (n.WidgetType != widget.Box) { + if n.WidgetType != widget.Box { return } n.showWidgetPlacement(true, "boxS()") @@ -21,7 +21,7 @@ func (n *node) placeBox(startW int, startH int) { newR := child.realGocuiSize() w := newR.w1 - newR.w0 h := newR.h1 - newR.h0 - if (n.direction == widget.Horizontal) { + if n.direction == widget.Horizontal { log.Log(NOW, "BOX IS HORIZONTAL", n.progname, "newWH()", newW, newH, "child()", w, h, child.progname) // expand based on the child width newW += w @@ -39,10 +39,10 @@ func (n *node) placeBox(startW int, startH int) { } func (n *node) placeWidgets(startW int, startH int) { - if (n == nil) { + if n == nil { return } - if (me.rootNode == nil) { + if me.rootNode == nil { return } @@ -87,7 +87,7 @@ func (n *node) placeWidgets(startW int, startH int) { func (n *node) placeGrid(startW int, startH int) { w := n.tk n.showWidgetPlacement(true, "grid0:") - if (n.WidgetType != widget.Grid) { + if n.WidgetType != widget.Grid { return } @@ -98,10 +98,10 @@ func (n *node) placeGrid(startW int, startH int) { childH := newR.h1 - newR.h0 // set the child's realWidth, and grid offset - if (w.widths[child.AtW] < childW) { + if w.widths[child.AtW] < childW { w.widths[child.AtW] = childW } - if (w.heights[child.AtH] < childH) { + if w.heights[child.AtH] < childH { w.heights[child.AtH] = childH } // child.showWidgetPlacement(logInfo, "grid: ") @@ -114,12 +114,12 @@ func (n *node) placeGrid(startW int, startH int) { var totalW, totalH int for i, w := range w.widths { - if (i < child.AtW) { + if i < child.AtW { totalW += w } } for i, h := range w.heights { - if (i < child.AtH) { + if i < child.AtH { totalH += h } } @@ -137,7 +137,7 @@ func (n *node) placeGrid(startW int, startH int) { // computes the real, actual size of all the gocli objects in a widget func (n *node) realGocuiSize() *rectType { - var f func (n *node, r *rectType) + var f func(n *node, r *rectType) newR := new(rectType) // initialize the values to opposite newR.w0 = 80 @@ -153,7 +153,7 @@ func (n *node) realGocuiSize() *rectType { // expand the rectangle to the biggest thing displayed f = func(n *node, r *rectType) { newR := n.tk.gocuiSize - if ! n.tk.isFake { + if !n.tk.isFake { if r.w0 > newR.w0 { r.w0 = newR.w0 } @@ -179,7 +179,7 @@ func (n *node) textSize() (int, int) { var width, height int for _, s := range strings.Split(widget.GetString(n.value), "\n") { - if (width < len(s)) { + if width < len(s) { width = len(s) } height += 1 diff --git a/gocui/plugin.go b/gocui/plugin.go index 3a122e3..c0a925f 100644 --- a/gocui/plugin.go +++ b/gocui/plugin.go @@ -3,20 +3,20 @@ package main import ( // if you include more than just this import // then your plugin might be doing something un-ideal (just a guess from 2023/02/27) + "go.wit.com/lib/widget" "go.wit.com/log" - "go.wit.com/gui/widget" ) func action(a *widget.Action) { log.Log(INFO, "action() START", a.WidgetId, a.ActionType, a.WidgetType, a.ProgName) n := me.rootNode.findWidgetId(a.WidgetId) var w *guiWidget - if (n != nil) { + if n != nil { w = n.tk } switch a.ActionType { case widget.Add: - if (w == nil) { + if w == nil { n := addNode(a) // w = n.tk n.addWidget() @@ -37,7 +37,7 @@ func action(a *widget.Action) { log.Log(NOW, "TODO: set flag here", a.ActionType, a.WidgetType, a.ProgName) log.Log(NOW, "TODO: n.WidgetType =", n.WidgetType, "n.progname =", a.ProgName) } else { - if (a.Value == nil) { + if a.Value == nil { log.Log(ERROR, "TODO: Set here. a == nil id =", a.WidgetId, "type =", a.WidgetType, "Name =", a.ProgName) log.Log(ERROR, "TODO: Set here. id =", a.WidgetId, "n.progname =", n.progname) } else { @@ -74,7 +74,7 @@ func action(a *widget.Action) { } func (n *node) AddText(text string) { - if (n == nil) { + if n == nil { log.Log(NOW, "widget is nil") return } @@ -87,7 +87,7 @@ func (n *node) AddText(text string) { func (n *node) SetText(text string) { var changed bool = false - if (n == nil) { + if n == nil { log.Log(NOW, "widget is nil") return } @@ -95,11 +95,11 @@ func (n *node) SetText(text string) { n.value = text changed = true } - if (! changed) { + if !changed { return } - if (n.Visible()) { + if n.Visible() { n.textResize() n.deleteView() n.showView() @@ -111,7 +111,7 @@ func (n *node) Set(val any) { log.Log(INFO, "Set() value =", val) n.value = val - if (n.WidgetType != widget.Checkbox) { + if n.WidgetType != widget.Checkbox { n.setCheckbox(val) } } diff --git a/gocui/showStdout.go b/gocui/showStdout.go index 06d5dbb..c628f4a 100644 --- a/gocui/showStdout.go +++ b/gocui/showStdout.go @@ -6,8 +6,8 @@ import ( "github.com/awesome-gocui/gocui" + "go.wit.com/lib/widget" "go.wit.com/log" - "go.wit.com/gui/widget" ) var outputW int = 180 @@ -18,7 +18,7 @@ func moveMsg(g *gocui.Gui) { if !movingMsg && (mx != initialMouseX || my != initialMouseY) { movingMsg = true } - g.SetView("msg", mx-xOffset, my-yOffset, mx-xOffset+outputW, my-yOffset+outputH + me.FramePadH, 0) + g.SetView("msg", mx-xOffset, my-yOffset, mx-xOffset+outputW, my-yOffset+outputH+me.FramePadH, 0) g.SetViewOnBottom("msg") } @@ -43,12 +43,12 @@ func showMsg(g *gocui.Gui, v *gocui.View) error { func makeOutputWidget(g *gocui.Gui, stringFromMouseClick string) *gocui.View { maxX, maxY := g.Size() - if (me.rootNode == nil) { + if me.rootNode == nil { // keep skipping this until the binary tree is initialized return nil } - if (me.logStdout == nil) { + if me.logStdout == nil { a := new(widget.Action) a.ProgName = "stdout" a.WidgetType = widget.Stdout @@ -57,12 +57,12 @@ func makeOutputWidget(g *gocui.Gui, stringFromMouseClick string) *gocui.View { n := addNode(a) me.logStdout = n me.logStdout.tk.gocuiSize.w0 = maxX - 32 - me.logStdout.tk.gocuiSize.h0 = maxY/2 + me.logStdout.tk.gocuiSize.h0 = maxY / 2 me.logStdout.tk.gocuiSize.w1 = me.logStdout.tk.gocuiSize.w0 + outputW me.logStdout.tk.gocuiSize.h1 = me.logStdout.tk.gocuiSize.h0 + outputH } v, err := g.View("msg") - if (v == nil) { + if v == nil { log.Log(NOW, "makeoutputwindow() this is supposed to happen. v == nil", err) } else { log.Log(NOW, "makeoutputwindow() msg != nil. WTF now? err =", err) @@ -76,12 +76,12 @@ func makeOutputWidget(g *gocui.Gui, stringFromMouseClick string) *gocui.View { log.Log(NOW, "makeoutputwindow() this is supposed to happen?", err) } - if (err != nil) { + if err != nil { log.Log(NOW, "makeoutputwindow() create output window failed", err) return nil } - if (v == nil) { + if v == nil { log.Log(NOW, "makeoutputwindow() msg == nil. WTF now? err =", err) return nil } else { @@ -91,7 +91,7 @@ func makeOutputWidget(g *gocui.Gui, stringFromMouseClick string) *gocui.View { v.Clear() v.SelBgColor = gocui.ColorCyan v.SelFgColor = gocui.ColorBlack - fmt.Fprintln(v, "figure out how to capture STDOUT to here\n" + stringFromMouseClick) + fmt.Fprintln(v, "figure out how to capture STDOUT to here\n"+stringFromMouseClick) g.SetViewOnBottom("msg") // g.SetViewOnBottom(v.Name()) return v diff --git a/gocui/structs.go b/gocui/structs.go index a3ca566..e899f78 100644 --- a/gocui/structs.go +++ b/gocui/structs.go @@ -10,11 +10,11 @@ package main import ( "fmt" + "github.com/awesome-gocui/gocui" "reflect" "strconv" - "sync" "strings" - "github.com/awesome-gocui/gocui" + "sync" "go.wit.com/log" ) @@ -30,24 +30,24 @@ var redoWidgets bool = true var currentWindow *node type config struct { - baseGui *gocui.Gui // the main gocui handle - rootNode *node // the base of the binary tree. it should have id == 0 + baseGui *gocui.Gui // the main gocui handle + rootNode *node // the base of the binary tree. it should have id == 0 - ctrlDown *node // shown if you click the mouse when the ctrl key is pressed + ctrlDown *node // shown if you click the mouse when the ctrl key is pressed currentWindow *node // this is the current tab or window to show - logStdout *node // where to show STDOUT - helpLabel *gocui.View - ddview *node // the gocui view to select dropdrown lists - ddClicked bool // the dropdown menu view was clicked - ddNode *node // the dropdown menu is for this widget + logStdout *node // where to show STDOUT + helpLabel *gocui.View + ddview *node // the gocui view to select dropdrown lists + ddClicked bool // the dropdown menu view was clicked + ddNode *node // the dropdown menu is for this widget /* - // this is the channel we send user events like - // mouse clicks or keyboard events back to the program - callback chan toolkit.Action + // this is the channel we send user events like + // mouse clicks or keyboard events back to the program + callback chan toolkit.Action - // this is the channel we get requests to make widgets - pluginChan chan toolkit.Action + // this is the channel we get requests to make widgets + pluginChan chan toolkit.Action */ // When the widget has a frame, like a button, it adds 2 lines runes on each side @@ -62,12 +62,12 @@ type config struct { // how far down to start Window or Tab headings WindowW int `default:"8" dense:"0"` WindowH int `default:"-1"` - TabW int `default:"5" dense:"0"` - TabH int `default:"1" dense:"0"` + TabW int `default:"5" dense:"0"` + TabH int `default:"1" dense:"0"` // additional amount of space to put between window & tab widgets WindowPadW int `default:"8" dense:"0"` - TabPadW int `default:"4" dense:"0"` + TabPadW int `default:"4" dense:"0"` // additional amount of space to indent on a group GroupPadW int `default:"6" dense:"2"` @@ -79,12 +79,12 @@ type config struct { // offset for the hidden widgets FakeW int `default:"20"` - padded bool // add space between things like buttons + padded bool // add space between things like buttons 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 - menubar bool // for windows - stretchy bool // expand things like buttons to the maximum size - margin bool // add space around the frames of windows + canvas bool // if set to true, the windows are a raw canvas + menubar bool // for windows + stretchy bool // expand things like buttons to the maximum size + margin bool // add space around the frames of windows // writeMutex protects locks the write process writeMutex sync.Mutex @@ -96,13 +96,13 @@ type config struct { // deprecate these var ( initialMouseX, initialMouseY, xOffset, yOffset int - globalMouseDown, msgMouseDown, movingMsg bool + globalMouseDown, msgMouseDown, movingMsg bool ) // this is the gocui way // corner starts at in the upper left corner type rectType struct { - w0, h0, w1, h1 int // left top right bottom + w0, h0, w1, h1 int // left top right bottom } func (r *rectType) Width() int { @@ -115,11 +115,11 @@ func (r *rectType) Height() int { type guiWidget struct { // the gocui package variables - v *gocui.View // this is nil if the widget is not displayed - cuiName string // what gocui uses to reference the widget + v *gocui.View // this is nil if the widget is not displayed + cuiName string // what gocui uses to reference the widget // the actual text to display in the console - label string + label string // the logical size of the widget // For example, 40x12 would be the center of a normal terminal @@ -130,14 +130,14 @@ type guiWidget struct { gocuiSize rectType isCurrent bool // is this the currently displayed Window or Tab? - isFake bool // widget types like 'box' are 'false' + isFake bool // widget types like 'box' are 'false' // used to track the size of grids - widths map[int]int // how tall each row in the grid is + widths map[int]int // how tall each row in the grid is heights map[int]int // how wide each column in the grid is tainted bool - frame bool + frame bool // for a window, this is currently selected tab selectedTab *node @@ -156,13 +156,13 @@ func (w *guiWidget) Write(p []byte) (n int, err error) { w.tainted = true me.writeMutex.Lock() defer me.writeMutex.Unlock() - if (me.logStdout.tk.v == nil) { + if me.logStdout.tk.v == nil { // optionally write the output to /tmp s := fmt.Sprint(string(p)) s = strings.TrimSuffix(s, "\n") fmt.Fprintln(outf, s) v, _ := me.baseGui.View("msg") - if (v != nil) { + if v != nil { // fmt.Fprintln(outf, "found msg") me.logStdout.tk.v = v } @@ -174,7 +174,7 @@ func (w *guiWidget) Write(p []byte) (n int, err error) { s = strings.TrimSuffix(s, "\n") tmp := strings.Split(s, "\n") outputS = append(outputS, tmp...) - if (len(outputS) > outputH) { + if len(outputS) > outputH { l := len(outputS) - outputH outputS = outputS[l:] } diff --git a/gocui/tab.go b/gocui/tab.go index 14f6203..f0fc563 100644 --- a/gocui/tab.go +++ b/gocui/tab.go @@ -5,8 +5,8 @@ package main import ( "strings" + "go.wit.com/lib/widget" "go.wit.com/log" - "go.wit.com/gui/widget" ) func (w *guiWidget) Width() int { @@ -58,11 +58,11 @@ func redoWindows(nextW int, nextH int) { w := n.tk var tabs bool for _, child := range n.children { - if (child.WidgetType == widget.Tab) { + if child.WidgetType == widget.Tab { tabs = true } } - if (tabs) { + if tabs { // window is tabs. Don't show it as a standard button w.frame = false n.hasTabs = true diff --git a/gocui/view.go b/gocui/view.go index 912cf21..b2bc81b 100644 --- a/gocui/view.go +++ b/gocui/view.go @@ -1,15 +1,15 @@ package main import ( - "fmt" - "errors" "bufio" + "errors" + "fmt" "strings" "github.com/awesome-gocui/gocui" + "go.wit.com/lib/widget" "go.wit.com/log" - "go.wit.com/gui/widget" ) func splitLines(s string) []string { @@ -28,20 +28,20 @@ func (n *node) textResize() bool { for i, s := range splitLines(n.tk.label) { log.Log(INFO, "textResize() len =", len(s), i, s) - if (width < len(s)) { + if width < len(s) { width = len(s) } height += 1 } - if (w.gocuiSize.w1 != w.gocuiSize.w0 + width + me.FramePadW) { + if w.gocuiSize.w1 != w.gocuiSize.w0+width+me.FramePadW { w.gocuiSize.w1 = w.gocuiSize.w0 + width + me.FramePadW changed = true } - if (w.gocuiSize.h1 != w.gocuiSize.h0 + height + me.FramePadH) { + if w.gocuiSize.h1 != w.gocuiSize.h0+height+me.FramePadH { w.gocuiSize.h1 = w.gocuiSize.h0 + height + me.FramePadH changed = true } - if (changed) { + if changed { n.showWidgetPlacement(true, "textResize() changed") } return changed @@ -57,22 +57,22 @@ func (n *node) showView() { var err error w := n.tk - if (w.cuiName == "") { + if w.cuiName == "" { log.Log(ERROR, "showView() w.cuiName was not set for widget", w) w.cuiName = string(n.WidgetId) } // if the gocui element doesn't exist, create it - if (w.v == nil) { + if w.v == nil { n.recreateView() - } + } x0, y0, x1, y1, err := me.baseGui.ViewPosition(w.cuiName) log.Log(INFO, "showView() w.v already defined for widget", n.progname, err) // n.smartGocuiSize() changed := n.textResize() - if (changed) { + if changed { log.Log(NOW, "showView() textResize() changed. Should recreateView here wId =", w.cuiName) } else { log.Log(NOW, "showView() Clear() and Fprint() here wId =", w.cuiName) @@ -85,21 +85,21 @@ func (n *node) showView() { // if the gocui element has changed where it is supposed to be on the screen // recreate it - if (x0 != w.gocuiSize.w0) { + if x0 != w.gocuiSize.w0 { n.recreateView() return } - if (y0 != w.gocuiSize.h0) { + if y0 != w.gocuiSize.h0 { log.Log(ERROR, "showView() start hight mismatch id=", w.cuiName, "gocui h vs computed h =", w.gocuiSize.h0, y0) n.recreateView() return } - if (x1 != w.gocuiSize.w1) { + if x1 != w.gocuiSize.w1 { log.Log(ERROR, "showView() too wide", w.cuiName, "w,w", w.gocuiSize.w1, x1) n.recreateView() return } - if (y1 != w.gocuiSize.h1) { + if y1 != w.gocuiSize.h1 { log.Log(ERROR, "showView() too high", w.cuiName, "h,h", w.gocuiSize.h1, y1) n.recreateView() return @@ -114,7 +114,7 @@ func (n *node) recreateView() { var err error w := n.tk log.Log(ERROR, "recreateView() START", n.WidgetType, n.progname) - if (me.baseGui == nil) { + if me.baseGui == nil { log.Log(ERROR, "recreateView() ERROR: me.baseGui == nil", w) return } @@ -123,11 +123,11 @@ func (n *node) recreateView() { me.baseGui.DeleteView(w.cuiName) w.v = nil - if (n.progname == "CLOUDFLARE_EMAIL") { - n.showWidgetPlacement(true, "n.progname=" + n.progname + " n.tk.label=" + n.tk.label + " " + w.cuiName) + if n.progname == "CLOUDFLARE_EMAIL" { + n.showWidgetPlacement(true, "n.progname="+n.progname+" n.tk.label="+n.tk.label+" "+w.cuiName) n.dumpWidget("jwc") n.textResize() - n.showWidgetPlacement(true, "n.progname=" + n.progname + " n.tk.label=" + n.tk.label + " " + w.cuiName) + n.showWidgetPlacement(true, "n.progname="+n.progname+" n.tk.label="+n.tk.label+" "+w.cuiName) } a := w.gocuiSize.w0 @@ -166,15 +166,15 @@ func (n *node) recreateView() { // n.dumpWidget("jwc 2") // if you don't do this here, it will be black & white only - if (w.color != nil) { + if w.color != nil { w.v.FrameColor = w.color.frame w.v.FgColor = w.color.fg w.v.BgColor = w.color.bg w.v.SelFgColor = w.color.selFg w.v.SelBgColor = w.color.selBg } - if (n.progname == "CLOUDFLARE_EMAIL") { - n.showWidgetPlacement(true, "n.progname=" + n.progname + " n.tk.label=" + n.tk.label + " " + w.cuiName) + if n.progname == "CLOUDFLARE_EMAIL" { + n.showWidgetPlacement(true, "n.progname="+n.progname+" n.tk.label="+n.tk.label+" "+w.cuiName) n.dumpTree(true) } log.Log(ERROR, "recreateView() END") @@ -199,7 +199,7 @@ func (n *node) hideWidgets() { func (n *node) hideFake() { w := n.tk - if (w.isFake) { + if w.isFake { n.hideView() } for _, child := range n.children { @@ -209,7 +209,7 @@ func (n *node) hideFake() { func (n *node) showFake() { w := n.tk - if (w.isFake) { + if w.isFake { n.setFake() n.showWidgetPlacement(true, "showFake:") n.showView() @@ -221,7 +221,7 @@ func (n *node) showFake() { func (n *node) showWidgets() { w := n.tk - if (w.isFake) { + if w.isFake { // don't display by default } else { n.showWidgetPlacement(true, "current:") diff --git a/gocui/widget.go b/gocui/widget.go index e739993..ff8df1b 100644 --- a/gocui/widget.go +++ b/gocui/widget.go @@ -1,8 +1,8 @@ package main import ( + "go.wit.com/lib/widget" "go.wit.com/log" - "go.wit.com/gui/widget" ) func initWidget(n *node) *guiWidget { @@ -22,8 +22,8 @@ func initWidget(n *node) *guiWidget { return w } - if (n.WidgetType == widget.Grid) { - w.widths = make(map[int]int) // how tall each row in the grid is + if n.WidgetType == widget.Grid { + w.widths = make(map[int]int) // how tall each row in the grid is w.heights = make(map[int]int) // how wide each column in the grid is } @@ -43,7 +43,7 @@ func setupCtrlDownWidget() { func (n *node) deleteView() { w := n.tk - if (w.v != nil) { + if w.v != nil { w.v.Visible = false return } @@ -54,7 +54,7 @@ func (n *node) deleteView() { // searches the binary tree for a WidgetId func (n *node) findWidgetName(name string) *node { - if (n == nil) { + if n == nil { return nil } @@ -64,7 +64,7 @@ func (n *node) findWidgetName(name string) *node { for _, child := range n.children { newN := child.findWidgetName(name) - if (newN != nil) { + if newN != nil { return newN } } @@ -73,39 +73,39 @@ func (n *node) findWidgetName(name string) *node { func (n *node) IsCurrent() bool { w := n.tk - if (n.WidgetType == widget.Tab) { + if n.WidgetType == widget.Tab { return w.isCurrent } - if (n.WidgetType == widget.Window) { + if n.WidgetType == widget.Window { return w.isCurrent } - if (n.WidgetType == widget.Root) { + if n.WidgetType == widget.Root { return false } return n.parent.IsCurrent() } func (n *node) Visible() bool { - if (n == nil) { + if n == nil { return false } - if (n.tk == nil) { + if n.tk == nil { return false } - if (n.tk.v == nil) { + if n.tk.v == nil { return false } return n.tk.v.Visible } func (n *node) SetVisible(b bool) { - if (n == nil) { + if n == nil { return } - if (n.tk == nil) { + if n.tk == nil { return } - if (n.tk.v == nil) { + if n.tk.v == nil { return } n.tk.v.Visible = b |
