2024-01-18 00:08:37 -06:00
|
|
|
// 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
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
2024-01-28 02:20:31 -06:00
|
|
|
|
2024-01-18 00:08:37 -06:00
|
|
|
"github.com/awesome-gocui/gocui"
|
|
|
|
|
|
|
|
"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()
|
|
|
|
for _, view := range g.Views() {
|
|
|
|
view.Highlight = false
|
|
|
|
}
|
|
|
|
if v, err := g.ViewByPosition(mx, my); err == nil {
|
|
|
|
v.Highlight = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func msgDown(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
initialMouseX, initialMouseY = g.MousePosition()
|
2024-02-09 03:45:03 -06:00
|
|
|
log.Log(GOCUI, "msgDown() X,Y", initialMouseX, initialMouseY)
|
2024-01-18 00:08:37 -06:00
|
|
|
if vx, vy, _, _, err := g.ViewPosition("msg"); err == nil {
|
|
|
|
xOffset = initialMouseX - vx
|
|
|
|
yOffset = initialMouseY - vy
|
|
|
|
msgMouseDown = true
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func mouseUp(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
w, h := g.MousePosition()
|
|
|
|
|
2024-02-01 20:12:26 -06:00
|
|
|
dropdownUnclicked(w, h)
|
2024-01-18 00:08:37 -06:00
|
|
|
if msgMouseDown {
|
|
|
|
msgMouseDown = false
|
|
|
|
if movingMsg {
|
|
|
|
movingMsg = false
|
|
|
|
return nil
|
|
|
|
} else {
|
|
|
|
g.DeleteView("msg")
|
|
|
|
}
|
|
|
|
} else if globalMouseDown {
|
|
|
|
globalMouseDown = false
|
|
|
|
g.DeleteView("globalDown")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func mouseDown(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
mx, my := g.MousePosition()
|
|
|
|
if vx0, vy0, vx1, vy1, err := g.ViewPosition("msg"); err == nil {
|
|
|
|
if mx >= vx0 && mx <= vx1 && my >= vy0 && my <= vy1 {
|
|
|
|
return msgDown(g, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
globalMouseDown = true
|
|
|
|
maxX, _ := g.Size()
|
2024-02-02 11:07:56 -06:00
|
|
|
findUnderMouse()
|
|
|
|
msg := fmt.Sprintf("mouseDown() Mouse really down at: %d,%d", mx, my)
|
2024-02-02 11:47:32 -06:00
|
|
|
// dropdownClicked(mx, my)
|
2024-01-18 00:08:37 -06:00
|
|
|
x := mx - len(msg)/2
|
|
|
|
if x < 0 {
|
|
|
|
x = 0
|
|
|
|
} else if x+len(msg)+1 > maxX-1 {
|
|
|
|
x = maxX - 1 - len(msg) - 1
|
|
|
|
}
|
2024-02-09 03:45:03 -06:00
|
|
|
log.Log(GOCUI, "mouseDown() about to write out message to 'globalDown' view. msg =", msg)
|
2024-01-18 00:08:37 -06:00
|
|
|
if v, err := g.SetView("globalDown", x, my-1, x+len(msg)+1, my+1, 0); err != nil {
|
|
|
|
if !errors.Is(err, gocui.ErrUnknownView) {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
v.WriteString(msg)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|