From dddef229dcab1cd2c5ab7101dc5a4781478c0a62 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 1 Feb 2024 21:47:31 -0600 Subject: [PATCH] dropdown & combobox's pop up Signed-off-by: Jeff Carr --- add.go | 5 +++++ click.go | 2 ++ dropdown.go | 13 +++++++------ gocui.go | 29 ----------------------------- main.go | 42 +++++++++++++++++++++++++++++++++++++++--- 5 files changed, 53 insertions(+), 38 deletions(-) diff --git a/add.go b/add.go index 9a59dc9..ed43ffa 100644 --- a/add.go +++ b/add.go @@ -49,6 +49,11 @@ func addWidget(n *tree.Node) { nw.color = &colorWindow wRoot := me.treeRoot.TK.(*guiWidget) wRoot.redoWindows(0, 0) + // TODO: record the first window here? + // do initial setup of helper widgets here: + if me.ddview == nil { + me.ddview = makeDropdownView("addWidget() ddview") + } return case widget.Tab: nw.color = &colorTab diff --git a/click.go b/click.go index e41d3b0..9b1f858 100644 --- a/click.go +++ b/click.go @@ -198,9 +198,11 @@ func (w *guiWidget) doWidgetClick() { log.Log(NOW, "ddItem:", w.String(), i, s) ddItems += s + "\n" } + /* if me.ddview == nil { me.ddview = makeDropdownView(ddItems) } + */ showDropdownItems(ddItems) me.ddNode = w.node /* diff --git a/dropdown.go b/dropdown.go index 79bf302..a12a929 100644 --- a/dropdown.go +++ b/dropdown.go @@ -155,12 +155,13 @@ func showDDview() 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 + } +*/ func (w *guiWidget) dropdownClicked(mouseW, mouseH int) { log.Log(NOW, "dropdownClicked() (w,h) =", mouseW, mouseH) w.SetVisible(false) diff --git a/gocui.go b/gocui.go index dec6d20..05672ec 100644 --- a/gocui.go +++ b/gocui.go @@ -12,35 +12,6 @@ import ( "go.wit.com/log" ) -// This initializes the gocui package -// it runs SetManagerFunc which passes every input -// event (keyboard, mouse, etc) to the function "gocuiEvent()" -func gocuiMain() { - g, err := gocui.NewGui(gocui.OutputNormal, true) - if err != nil { - panic(err) - } - defer g.Close() - - me.baseGui = g - - g.Cursor = true - g.Mouse = true - - // this sets the function that is run on every event. For example: - // When you click the mouse, move the mouse, or press a key on the keyboard - // This is equivalent to xev or similar to cat /dev/input on linux - g.SetManagerFunc(gocuiEvent) - - if err := defaultKeybindings(g); err != nil { - panic(err) - } - - if err := g.MainLoop(); err != nil && !errors.Is(err, gocui.ErrQuit) { - panic(err) - } -} - // Thanks to the gocui developers -- your package kicks ass // This function is called on every event. It is a callback function from the gocui package // which has an excellent implementation. While gocui handles things like text highlighting diff --git a/main.go b/main.go index 1e8f9a8..4d4dde4 100644 --- a/main.go +++ b/main.go @@ -5,9 +5,11 @@ package main import ( + "errors" "os" "runtime/debug" + "github.com/awesome-gocui/gocui" "go.wit.com/log" "go.wit.com/toolkits/tree" ) @@ -75,14 +77,19 @@ func mainGogui() { log.Warn("YAHOOOO Recovered in guiMain application:", r) log.Warn("Recovered from panic:", r) me.baseGui.Close() - log.Sleep(3) + + // allow gocui to close if possible, then print stack + log.Sleep(1) os.Stdout = origStdout os.Stderr = origStderr - me.myTree.SendToolkitPanic() log.Warn("Stack trace:") debug.PrintStack() - panic("BUMMER") + + // attempt to switch to the nocui toolkit + log.Sleep(1) + me.myTree.SendToolkitLoad("nocui") + // panic("BUMMER") return } }() @@ -106,3 +113,32 @@ func mainGogui() { os.Stderr = ferr gocuiMain() } + +// This initializes the gocui package +// it runs SetManagerFunc which passes every input +// event (keyboard, mouse, etc) to the function "gocuiEvent()" +func gocuiMain() { + g, err := gocui.NewGui(gocui.OutputNormal, true) + if err != nil { + panic(err) + } + defer g.Close() + + me.baseGui = g + + g.Cursor = true + g.Mouse = true + + // this sets the function that is run on every event. For example: + // When you click the mouse, move the mouse, or press a key on the keyboard + // This is equivalent to xev or similar to cat /dev/input on linux + g.SetManagerFunc(gocuiEvent) + + if err := defaultKeybindings(g); err != nil { + panic(err) + } + + if err := g.MainLoop(); err != nil && !errors.Is(err, gocui.ErrQuit) { + panic(err) + } +}