1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
// 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"
"go.wit.com/widget"
)
var currentDrag *guiWidget
// 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) {
w, h := g.MousePosition()
if me.supermouse {
for _, tk := range findByXY(w, h) {
s := fmt.Sprintf("SM (%3d,%3d)", w, h)
tk.dumpWidget(s)
}
}
if me.globalMouseDown {
// log.Info("msgMouseDown == true")
// plugin will segfault if you don't keep this inside a check for msgMouseDown
// don't move this code out of here
var found bool = false
if currentDrag != nil {
currentDrag.moveNew()
return
}
// first look for windows
for _, tk := range findByXY(w, h) {
if tk.node.WidgetType == widget.Window {
currentDrag = tk
return
}
}
// now look for the STDOUT window
for _, tk := range findByXY(w, h) {
if tk.node.WidgetType == widget.Flag {
currentDrag = tk
// tk.moveNew()
return
}
}
for _, tk := range findByXY(w, h) {
if tk.node.WidgetType == widget.Stdout {
currentDrag = tk
// tk.moveNew()
return
}
/*
if tk.node.WidgetType == widget.Label {
currentDrag = tk
// tk.moveNew()
return
}
*/
found = true
}
if !found {
log.Info(fmt.Sprintf("findByXY() empty. nothing to move at (%d,%d)", w, h))
}
}
if widgetView, _ := g.View("msg"); widgetView == nil {
if createStdout(g) {
return
}
return
}
for _, view := range g.Views() {
view.Highlight = false
}
if v, err := g.ViewByPosition(w, h); err == nil {
v.Highlight = true
}
}
// this is how the window gets dragged around
func (tk *guiWidget) moveNew() {
w, h := me.baseGui.MousePosition()
if tk.node.WidgetType == widget.Window {
tk.redrawWindow(w-tk.dragW, h-tk.dragH) // TODO: fix these hard coded things with offsets
setThingsOnTop() // sets help, Stdout, etc on the top after windows have been redrawn
return
}
if tk.node.WidgetType == widget.Flag {
me.baseGui.SetView(tk.cuiName, w-3, h-3, w+20, h+20, 0)
// tk.verifyRect()
s := fmt.Sprintf("move(%dx%d) %s ###", w, h, tk.cuiName)
tk.dumpWidget(s)
return
} else {
me.stdout.lastW = w - me.stdout.mouseOffsetW
me.stdout.lastH = h - me.stdout.mouseOffsetH
tk.relocateStdout(me.stdout.lastW, me.stdout.lastH)
/*
// log.Info("NOT MOVE FLAG. PASSING MOVE TO MSG", tk.node.WidgetType)
// tk.dumpWidget("moveNew() MSG" + tk.cuiName)
w0 := w - me.stdout.offsetW
h0 := h - me.stdout.offsetH
w1 := w - me.stdout.offsetW + me.stdout.w
h1 := h - me.stdout.offsetH + me.stdout.h
me.baseGui.SetView("msg", w0, h0, w1, h1, 0)
// me.startOutputW = w - me.stdout.offsetW
// me.startOutputH = h - me.stdout.offsetH
me.baseGui.SetViewOnBottom("msg")
tk.gocuiSize.w0 = w0
tk.gocuiSize.w1 = w1
tk.gocuiSize.h0 = h0
tk.gocuiSize.h1 = h1
tk.full.w0 = w0
tk.full.w1 = w1
tk.full.h0 = h0
tk.full.h1 = h1
*/
}
// always place the help menu on top
setThingsOnTop() // sets help, Stdout, etc on the top after windows have been redrawn
}
func createStdout(g *gocui.Gui) bool {
makeOutputWidget(g, "this is a create before a mouse click")
if me.stdout.tk != nil {
msg := fmt.Sprintf("test out gocuiEvent() %d\n", me.ecount)
// me.logStdout.v.Write([]byte(msg))
me.stdout.tk.Write([]byte(msg))
log.Log(NOW, "logStdout test out")
}
return true
}
|