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,6 +78,8 @@ 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 // 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 { func theNotsure(g *gocui.Gui, v *gocui.View) error {
log.Info("got to theNotsure(). now what? dark =", me.dark) log.Info("got to theNotsure(). now what? dark =", me.dark)
me.refresh = true
/*
if me.debug { if me.debug {
log.Info("debugging off") log.Info("debugging off")
me.debug = false me.debug = false
@ -90,7 +92,7 @@ func theNotsure(g *gocui.Gui, v *gocui.View) error {
win.dumpWidget("found() win. redrawing window:") win.dumpWidget("found() win. redrawing window:")
win.makeWindowActive() win.makeWindowActive()
} }
*/
return nil return nil
} }

22
init.go
View File

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

View File

@ -41,6 +41,7 @@ type config struct {
currentWindow *guiWidget // this is the current tab or window to show 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 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 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 ctrlDown *tree.Node // shown if you click the mouse when the ctrl key is pressed
helpLabel *gocui.View // ? helpLabel *gocui.View // ?
showHelp bool // toggle boolean for the help menu (deprecate?) showHelp bool // toggle boolean for the help menu (deprecate?)