disable and enable doesn't crash

This commit is contained in:
Jeff Carr 2025-02-11 13:22:23 -06:00
parent 535646335a
commit 733c595c54
3 changed files with 93 additions and 49 deletions

View File

@ -68,12 +68,13 @@ func (tk *guiWidget) updateColor() {
if tk.v == nil { if tk.v == nil {
return return
} }
tk.colorLast.frame = tk.color.frame if tk.color != nil {
tk.colorLast.fg = tk.color.fg tk.colorLast.frame = tk.color.frame
tk.colorLast.bg = tk.color.bg tk.colorLast.fg = tk.color.fg
tk.colorLast.selFg = tk.color.selFg tk.colorLast.bg = tk.color.bg
tk.colorLast.selBg = tk.color.selBg tk.colorLast.selFg = tk.color.selFg
tk.colorLast.selBg = tk.color.selBg
}
tk.activateColor() tk.activateColor()
} }

113
plugin.go
View File

@ -7,6 +7,7 @@ import (
// if you include more than just this 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) // then your plugin might be doing something un-ideal (just a guess from 2023/02/27)
"github.com/awesome-gocui/gocui"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/toolkits/tree" "go.wit.com/toolkits/tree"
"go.wit.com/widget" "go.wit.com/widget"
@ -224,27 +225,57 @@ func (tk *guiWidget) Disable() {
log.Log(NOW, "widget is nil") log.Log(NOW, "widget is nil")
return return
} }
tk.enable = false initTextbox()
tk.node.State.Enable = false tk.prepTextbox()
// log.Info("disable widget in gocui", tk.node.WidgetType, tk.node.ProgName()) r := new(rectType)
switch tk.node.WidgetType { r.w0 = 2
case widget.Box: r.h0 = 1
// log.Info("todo: blank out the window here", tk.String()) r.w1 = r.w0 + 24
r := new(rectType) r.h1 = r.h0 + 2
// startW, startH := tk.Position() me.textbox.tk.forceSizes(r)
r.w0 = 0 me.textbox.tk.Show() // actually makes the gocui view. TODO: redo this
r.h0 = 0 log.Info("textbox should be shown")
r.w1 = r.w0 + 24 // showTextbox("Running...")
r.h1 = r.h0 + 2 me.textbox.tk.dumpWidget("shown?")
me.textbox.tk.forceSizes(r)
showTextbox("Running...") me.textbox.tk.setColorModal()
return me.textbox.tk.v.Clear()
case widget.Button: me.textbox.tk.v.WriteString("Running...")
tk.setColorDisable()
return me.textbox.tk.v.Editable = true
default: me.textbox.tk.v.Wrap = true
tk.dumpWidget("fixme: disable")
} me.baseGui.SetView(me.textbox.tk.cuiName, r.w0, r.h0, r.w1, r.h1, 0)
me.baseGui.SetCurrentView(me.textbox.tk.v.Name())
// bind the enter key to a function so we can close the textbox
me.baseGui.SetKeybinding(me.textbox.tk.v.Name(), gocui.KeyEnter, gocui.ModNone, theCloseTheTextbox)
me.textbox.active = true
/*
tk.enable = false
tk.node.State.Enable = false
// log.Info("disable widget in gocui", tk.node.WidgetType, tk.node.ProgName())
switch tk.node.WidgetType {
case widget.Box:
// log.Info("todo: blank out the window here", tk.String())
r := new(rectType)
// startW, startH := tk.Position()
r.w0 = 0
r.h0 = 0
r.w1 = r.w0 + 24
r.h1 = r.h0 + 2
me.textbox.tk.forceSizes(r)
showTextbox("Running...")
return
case widget.Button:
tk.setColorDisable()
return
default:
tk.dumpWidget("fixme: disable")
}
*/
} }
func (tk *guiWidget) Enable() { func (tk *guiWidget) Enable() {
@ -252,20 +283,28 @@ func (tk *guiWidget) Enable() {
log.Log(NOW, "widget is nil") log.Log(NOW, "widget is nil")
return return
} }
tk.enable = true initTextbox()
tk.node.State.Enable = true tk.prepTextbox()
// log.Info("enable widget in gocui", tk.node.WidgetType, tk.node.ProgName())
switch tk.node.WidgetType { me.textbox.tk.Hide()
case widget.Box: /*
// log.Info("todo: un blank the window here") initTextbox()
me.textbox.tk.Hide()
me.textbox.active = false tk.enable = true
// log.Info("escaped from textbox") tk.node.State.Enable = true
return // log.Info("enable widget in gocui", tk.node.WidgetType, tk.node.ProgName())
case widget.Button: switch tk.node.WidgetType {
tk.restoreEnableColor() case widget.Box:
return // log.Info("todo: un blank the window here")
default: me.textbox.tk.Hide()
tk.dumpWidget("fixme: enable") me.textbox.active = false
} // log.Info("escaped from textbox")
return
case widget.Button:
tk.restoreEnableColor()
return
default:
tk.dumpWidget("fixme: enable")
}
*/
} }

View File

@ -29,14 +29,18 @@ func (tk *guiWidget) forceSizes(r *rectType) {
tk.force.h1 = r.h1 tk.force.h1 = r.h1
} }
func (callertk *guiWidget) prepTextbox() { func initTextbox() {
if me.textbox.tk == nil { if me.textbox.tk == nil {
// should only happen once // should only happen once
me.textbox.tk = makeNewFlagWidget(me.textbox.wId) me.textbox.tk = makeNewFlagWidget(me.textbox.wId)
// me.textbox.tk.dumpWidget("init() textbox") // me.textbox.tk.dumpWidget("init() textbox")
} }
}
func (callertk *guiWidget) prepTextbox() {
initTextbox()
if me.textbox.tk == nil { if me.textbox.tk == nil {
log.Log(GOCUI, "showTextbox() Is Broken") log.Log(GOCUI, "prepTextbox() Is Broken")
return return
} }
@ -51,14 +55,14 @@ func (callertk *guiWidget) prepTextbox() {
me.textbox.callerTK = callertk me.textbox.callerTK = callertk
showTextbox(callertk.String()) // showTextbox(callertk.String())
} }
func showTextbox(callertk string) { func showTextbox(callers string) {
// tk := me.textbox.tk // tk := me.textbox.tk
// me.textbox.tk.dumpWidget("after sizes") // me.textbox.tk.dumpWidget("after sizes")
me.textbox.tk.Show() // actually makes the gocui view. TODO: redo this // me.textbox.tk.Show() // actually makes the gocui view. TODO: redo this
if me.textbox.tk.v == nil { if me.textbox.tk.v == nil {
log.Info("wtf went wrong") log.Info("wtf went wrong")
@ -67,7 +71,7 @@ func showTextbox(callertk string) {
me.textbox.tk.setColorModal() me.textbox.tk.setColorModal()
me.textbox.tk.v.Clear() me.textbox.tk.v.Clear()
cur := strings.TrimSpace(callertk) cur := strings.TrimSpace(callers)
// log.Info("setting textbox string to:", cur) // log.Info("setting textbox string to:", cur)
me.textbox.tk.v.WriteString(cur) me.textbox.tk.v.WriteString(cur)