// Copyright 2017-2025 WIT.COM Inc. All rights reserved. // Use of this source code is governed by the GPL 3.0 // 2025 note by jcarr: // this is one of the coolest things ever worked with. // Personally, I've been working on making a gocui GO plugin // so I can use it as a generalized console GUI toolkit. // // Well done everyone that has contributed to this gocui project !!! // I am in your debt. Happy hacking & peace. package main import ( "fmt" "github.com/awesome-gocui/gocui" log "go.wit.com/log" ) // this function uses the mouse position to highlight & unhighlight things // this is run every time the user moves the mouse over the terminal window func mouseMove(g *gocui.Gui) { mx, my := g.MousePosition() w := mx h := my if me.supermouse { for _, tk := range findByXY(w, h) { tk.dumpWidget("mouseMove()") } } if mouseMoveOld(g) { return } for _, view := range g.Views() { view.Highlight = false } if v, err := g.ViewByPosition(mx, my); err == nil { v.Highlight = true } } // this is how the window gets dragged around func moveMsg(g *gocui.Gui) { mx, my := g.MousePosition() if !me.movingMsg && (mx != initialMouseX || my != initialMouseY) { me.movingMsg = true } g.SetView("msg", mx-xOffset, my-yOffset, mx-xOffset+outputW, my-yOffset+outputH+me.FramePadH, 0) me.startOutputW = mx - xOffset me.startOutputH = my - yOffset g.SetViewOnBottom("msg") } // this somehow is letting me drag around the stdout window func mouseMoveOld(g *gocui.Gui) bool { me.ecount += 1 maxX, maxY := g.Size() mx, my := g.MousePosition() // log.Log(NOW, "handleEvent() START", maxX, maxY, mx, my, msgMouseDown) if _, err := g.View("msg"); msgMouseDown && err == nil { moveMsg(g) return true } 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 { // setOutput(me.logStdout) // me.logStdout.Write("test out") w := me.logStdout.TK.(*guiWidget) msg := fmt.Sprintf("test out gocuiEvent() %d\n", me.ecount) w.Write([]byte(msg)) // log.CaptureMode(w) log.Log(NOW, "logStdout test out") } return true } else { log.Log(NOW, "output widget already exists", maxX, maxY, mx, my) } // log.Log(NOW, "handleEvent() END ", maxX, maxY, mx, my, msgMouseDown) return false }