mirror of https://github.com/gizak/termui.git
Added support for mouse
This commit is contained in:
parent
72304ddb9b
commit
4b7fc0a5fb
31
events.go
31
events.go
|
@ -99,9 +99,7 @@ func crtTermboxEvt(e termbox.Event) Event {
|
|||
ne.Path = "/sys/err"
|
||||
ne.Data = err
|
||||
case termbox.EventMouse:
|
||||
m := EvtMouse{}
|
||||
m.X = e.MouseX
|
||||
m.Y = e.MouseY
|
||||
m := evtMouse(e)
|
||||
ne.Path = "/sys/mouse"
|
||||
ne.Data = m
|
||||
}
|
||||
|
@ -119,6 +117,33 @@ type EvtMouse struct {
|
|||
Press string
|
||||
}
|
||||
|
||||
func evtMouse(e termbox.Event) (te EvtMouse) {
|
||||
te.X = e.MouseX
|
||||
te.Y = e.MouseY
|
||||
|
||||
var m string
|
||||
|
||||
switch e.Key {
|
||||
case termbox.MouseLeft:
|
||||
m = "MouseLeft"
|
||||
case termbox.MouseMiddle:
|
||||
m = "MouseMiddle"
|
||||
case termbox.MouseRight:
|
||||
m = "MouseRight"
|
||||
case termbox.MouseRelease:
|
||||
m = "MouseRelease"
|
||||
case termbox.MouseWheelUp:
|
||||
m = "MouseWheelUp"
|
||||
case termbox.MouseWheelDown:
|
||||
m = "MouseWheelDown"
|
||||
default:
|
||||
m = "Unknown_Mouse_Button"
|
||||
}
|
||||
te.Press = m
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
type EvtErr error
|
||||
|
||||
func hookTermboxEvt() {
|
||||
|
|
Loading…
Reference in New Issue