this gocui package is really cool
This commit is contained in:
parent
2e0465e44a
commit
3d5ee3f89b
|
@ -9,7 +9,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/awesome-gocui/gocui"
|
"github.com/awesome-gocui/gocui"
|
||||||
|
|
||||||
|
@ -23,37 +22,10 @@ import (
|
||||||
// complicated console handling, it sends events here in a clean way.
|
// complicated console handling, it sends events here in a clean way.
|
||||||
// This is equivalent to the linux command xev (apt install x11-utils)
|
// This is equivalent to the linux command xev (apt install x11-utils)
|
||||||
func gocuiEvent(g *gocui.Gui) error {
|
func gocuiEvent(g *gocui.Gui) error {
|
||||||
me.ecount += 1
|
|
||||||
maxX, maxY := g.Size()
|
|
||||||
mx, my := g.MousePosition()
|
|
||||||
log.Verbose("handleEvent() START", maxX, maxY, mx, my, msgMouseDown)
|
|
||||||
if _, err := g.View("msg"); msgMouseDown && err == nil {
|
|
||||||
moveMsg(g)
|
|
||||||
}
|
|
||||||
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")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.Verbose("output widget already exists", maxX, maxY, mx, my)
|
|
||||||
}
|
|
||||||
mouseMove(g)
|
mouseMove(g)
|
||||||
log.Verbose("handleEvent() END ", maxX, maxY, mx, my, msgMouseDown)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func dragOutputWindow() {
|
|
||||||
log.Log(GOCUI, "todo: make dragOutputWindow")
|
|
||||||
}
|
|
||||||
|
|
||||||
// turns off the frame on the global window
|
// turns off the frame on the global window
|
||||||
func setFrame(b bool) {
|
func setFrame(b bool) {
|
||||||
// TODO: figure out what this might be useful for
|
// TODO: figure out what this might be useful for
|
||||||
|
|
|
@ -1,19 +1,6 @@
|
||||||
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
||||||
// Use of this source code is governed by the GPL 3.0
|
// Use of this source code is governed by the GPL 3.0
|
||||||
|
|
||||||
// NOTE: our code is under the GPL, not BSD
|
|
||||||
|
|
||||||
// note by jcarr@wit.com in 2025: this is one of the coolest
|
|
||||||
// things ever what this does. I've tried to improve
|
|
||||||
// it while I've been working on making a gocui
|
|
||||||
// GO plugin so it can be generalized as a useful
|
|
||||||
// console interface. Well done everyone that has
|
|
||||||
// contributed to this gocui project !!!
|
|
||||||
|
|
||||||
// Copyright 2014 The gocui Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -25,29 +12,7 @@ import (
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// this function uses the mouse position to highlight & unhighlight things
|
// event triggers when you push down on a mouse button
|
||||||
// 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()")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, view := range g.Views() {
|
|
||||||
view.Highlight = false
|
|
||||||
}
|
|
||||||
if v, err := g.ViewByPosition(mx, my); err == nil {
|
|
||||||
v.Highlight = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// I think this lets me drag the debugging window
|
|
||||||
func msgDown(g *gocui.Gui, v *gocui.View) error {
|
func msgDown(g *gocui.Gui, v *gocui.View) error {
|
||||||
initialMouseX, initialMouseY = g.MousePosition()
|
initialMouseX, initialMouseY = g.MousePosition()
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,80 @@
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
func dragOutputWindow() {
|
||||||
|
log.Log(GOCUI, "todo: make dragOutputWindow")
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
1
init.go
1
init.go
|
@ -168,6 +168,7 @@ func gocuiMain() {
|
||||||
|
|
||||||
// register how the 'gocui' will work as a GO toolkit plugin
|
// register how the 'gocui' will work as a GO toolkit plugin
|
||||||
// all applications will use these keys. they are universal.
|
// all applications will use these keys. they are universal.
|
||||||
|
// registered event handlers still have the events sent to gocuiEvent() above
|
||||||
registerHandlers(g)
|
registerHandlers(g)
|
||||||
/*
|
/*
|
||||||
if err := defaultKeybindings(g); err != nil {
|
if err := defaultKeybindings(g); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue