forked from Mirrors/bubbletea
Rename MouseButton type to more accurate MouseEventType
This commit is contained in:
parent
591fcabdd4
commit
a4f26594b2
|
@ -9,7 +9,7 @@ require (
|
|||
github.com/charmbracelet/bubbletea v0.10.3
|
||||
github.com/fogleman/ease v0.0.0-20170301025033-8da417bf1776
|
||||
github.com/mattn/go-runewidth v0.0.9
|
||||
github.com/muesli/termenv v0.7.0
|
||||
github.com/muesli/termenv v0.7.2
|
||||
)
|
||||
|
||||
replace github.com/charmbracelet/bubbles => ../../bubbles
|
||||
|
|
|
@ -10,20 +10,20 @@ github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHX
|
|||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/muesli/termenv v0.7.0 h1:KcLfgg/KICGxOxNr+P9gmkrJ5azxOm3WzkfXMePGTq4=
|
||||
github.com/muesli/termenv v0.7.0/go.mod h1:SohX91w6swWA4AYU+QmPx+aSgXhWO0juiyID9UZmbpA=
|
||||
github.com/muesli/termenv v0.5.3-0.20200625163851-04b5c30e4c04/go.mod h1:O1/I6sw+6KcrgAmcs6uiUVr7Lui+DNVbHTzt9Lm/PlI=
|
||||
github.com/muesli/termenv v0.7.2 h1:r1raklL3uKE7rOvWgSenmEm2px+dnc33OTisZ8YR1fw=
|
||||
github.com/muesli/termenv v0.7.2/go.mod h1:ct2L5N2lmix82RaY3bMWwVu/jUFc9Ule0KGDCiKYPh8=
|
||||
github.com/pkg/term v0.0.0-20200520122047-c3ffed290a03 h1:pd4YKIqCB0U7O2I4gWHgEUA2mCEOENmco0l/bM957bU=
|
||||
github.com/pkg/term v0.0.0-20200520122047-c3ffed290a03/go.mod h1:Z9+Ul5bCbBKnbCvdOWbLqTHhJiYV414CURZJba6L8qA=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899 h1:DZhuSZLsGlFL4CmhA8BcRA0mnthyA/nZ00AqCUo7vHg=
|
||||
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de h1:ikNHVSjEfnvz6sxdSPCaPt572qowuyMDMJLLm3Db3ig=
|
||||
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200819171115-d785dc25833f h1:KJuwZVtZBVzDmEDtB2zro9CXkD9O0dpCv4o2LHbQIAw=
|
||||
golang.org/x/sys v0.0.0-20200819171115-d785dc25833f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200821140526-fda516888d29 h1:mNuhGagCf3lDDm5C0376C/sxh6V7fy9WbdEu/YDNA04=
|
||||
golang.org/x/sys v0.0.0-20200821140526-fda516888d29/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
|
|
39
mouse.go
39
mouse.go
|
@ -2,17 +2,16 @@ package tea
|
|||
|
||||
import "errors"
|
||||
|
||||
// MouseMsg contains information about a mouse event.
|
||||
type MouseMsg MouseEvent
|
||||
|
||||
// MouseEvent represents a mouse event, which could be a click, a scroll wheel
|
||||
// movement, a cursor movement, or a combination.
|
||||
type MouseEvent struct {
|
||||
X int
|
||||
Y int
|
||||
Button MouseButton
|
||||
Alt bool
|
||||
Ctrl bool
|
||||
X int
|
||||
Y int
|
||||
Type MouseEventType
|
||||
Alt bool
|
||||
Ctrl bool
|
||||
}
|
||||
|
||||
// String returns a string representation of a mouse event.
|
||||
|
@ -23,15 +22,15 @@ func (m MouseEvent) String() (s string) {
|
|||
if m.Alt {
|
||||
s += "alt+"
|
||||
}
|
||||
s += mouseButtonNames[m.Button]
|
||||
s += mouseEventTypes[m.Type]
|
||||
return s
|
||||
}
|
||||
|
||||
// MouseButton represents a mouse button event.
|
||||
type MouseButton int
|
||||
// MouseEventType indicates the type of mouse event occurring.
|
||||
type MouseEventType int
|
||||
|
||||
const (
|
||||
MouseUnknown MouseButton = iota
|
||||
MouseUnknown MouseEventType = iota
|
||||
MouseLeft
|
||||
MouseRight
|
||||
MouseMiddle
|
||||
|
@ -41,7 +40,7 @@ const (
|
|||
MouseMotion
|
||||
)
|
||||
|
||||
var mouseButtonNames = map[MouseButton]string{
|
||||
var mouseEventTypes = map[MouseEventType]string{
|
||||
MouseUnknown: "unknown",
|
||||
MouseLeft: "left",
|
||||
MouseRight: "right",
|
||||
|
@ -68,29 +67,29 @@ func parseX10MouseEvent(buf []byte) (m MouseEvent, err error) {
|
|||
|
||||
switch e {
|
||||
case 35:
|
||||
m.Button = MouseMotion
|
||||
m.Type = MouseMotion
|
||||
case 64:
|
||||
m.Button = MouseWheelUp
|
||||
m.Type = MouseWheelUp
|
||||
case 65:
|
||||
m.Button = MouseWheelDown
|
||||
m.Type = MouseWheelDown
|
||||
default:
|
||||
switch e & 3 {
|
||||
case 0:
|
||||
if e&64 != 0 {
|
||||
m.Button = MouseWheelUp
|
||||
m.Type = MouseWheelUp
|
||||
} else {
|
||||
m.Button = MouseLeft
|
||||
m.Type = MouseLeft
|
||||
}
|
||||
case 1:
|
||||
if e&64 != 0 {
|
||||
m.Button = MouseWheelDown
|
||||
m.Type = MouseWheelDown
|
||||
} else {
|
||||
m.Button = MouseMiddle
|
||||
m.Type = MouseMiddle
|
||||
}
|
||||
case 2:
|
||||
m.Button = MouseRight
|
||||
m.Type = MouseRight
|
||||
case 3:
|
||||
m.Button = MouseRelease
|
||||
m.Type = MouseRelease
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue