can refresh manually

This commit is contained in:
Jeff Carr 2025-03-02 18:04:08 -06:00
parent 3e7287baea
commit dc329ed18c
3 changed files with 30 additions and 21 deletions

View File

@ -78,19 +78,21 @@ func theSuperMouse(g *gocui.Gui, v *gocui.View) error {
// use this to test code ideas // put whatever you want here and hit '2' to activate it
func theNotsure(g *gocui.Gui, v *gocui.View) error {
log.Info("got to theNotsure(). now what? dark =", me.dark)
if me.debug {
log.Info("debugging off")
me.debug = false
} else {
log.Info("debugging on")
me.debug = true
}
win := findWindowUnderMouse()
if win != nil {
win.dumpWidget("found() win. redrawing window:")
win.makeWindowActive()
}
me.refresh = true
/*
if me.debug {
log.Info("debugging off")
me.debug = false
} else {
log.Info("debugging on")
me.debug = true
}
win := findWindowUnderMouse()
if win != nil {
win.dumpWidget("found() win. redrawing window:")
win.makeWindowActive()
}
*/
return nil
}

22
init.go
View File

@ -197,12 +197,6 @@ func main() {
// this hack is to wait for the application to send something
// before trying to do anything. todo: rethink this someday
func waitOK() {
defer func() {
if r := recover(); r != nil {
fmt.Fprintln(outf, "INIT PLUGIN recovered in r", r)
return
}
}()
for {
if me.ok {
return
@ -238,12 +232,24 @@ func refreshGocui() {
}()
var lastRefresh time.Time
lastRefresh = time.Now()
me.refresh = false
for {
time.Sleep(100 * time.Millisecond)
// log.Info("refresh checking ok")
if !me.ok {
continue
}
// redraw the windows if something has changed
if time.Since(lastRefresh) > 1000*time.Millisecond {
if me.refresh {
log.Info("refresh triggered")
me.newWindowTrigger <- me.treeRoot.TK.(*guiWidget)
me.refresh = false
}
}
// this code updates the clock
if time.Since(lastRefresh) > 1000*time.Millisecond {
// artificially pause clock while dragging.
// this is a reminder to make this refresh code smarter
@ -289,9 +295,9 @@ func newWindowTrigger() {
select {
case tk := <-me.newWindowTrigger:
// log.Log(NOW, "newWindowTrigger() got new window", tk.cuiName)
time.Sleep(200 * time.Millisecond)
// time.Sleep(200 * time.Millisecond)
waitOK()
time.Sleep(200 * time.Millisecond)
// time.Sleep(200 * time.Millisecond)
redoWindows(me.FirstWindowW, me.FirstWindowH)
me.firstWindowOk = true
if !me.stdout.init {

View File

@ -41,6 +41,7 @@ type config struct {
currentWindow *guiWidget // this is the current tab or window to show
ok bool // if the user doesn't hit a key or move the mouse, gocui doesn't really start
firstWindowOk bool // allows the init to wait for the first window from the application
refresh bool // redraw everything?
ctrlDown *tree.Node // shown if you click the mouse when the ctrl key is pressed
helpLabel *gocui.View // ?
showHelp bool // toggle boolean for the help menu (deprecate?)