micro/internal/action/events.go

43 lines
932 B
Go
Raw Normal View History

2018-08-28 02:53:08 +03:00
package action
2018-08-26 06:06:44 +03:00
2018-08-27 22:53:10 +03:00
import (
2020-01-01 04:15:45 +03:00
"github.com/zyedidia/tcell"
2018-08-27 22:53:10 +03:00
)
2018-08-26 06:06:44 +03:00
2018-08-27 22:53:10 +03:00
type Event interface{}
2018-08-26 06:06:44 +03:00
2018-08-27 22:53:10 +03:00
// RawEvent is simply an escape code
// We allow users to directly bind escape codes
// to get around some of a limitations of terminals
type RawEvent struct {
esc string
}
2018-08-26 06:06:44 +03:00
2018-08-27 22:53:10 +03:00
// KeyEvent is a key event containing a key code,
// some possible modifiers (alt, ctrl, etc...) and
// a rune if it was simply a character press
// Note: to be compatible with tcell events,
// for ctrl keys r=code
type KeyEvent struct {
code tcell.Key
mod tcell.ModMask
r rune
}
2018-08-26 06:06:44 +03:00
2018-08-27 22:53:10 +03:00
// MouseEvent is a mouse event with a mouse button and
// any possible key modifiers
type MouseEvent struct {
btn tcell.ButtonMask
mod tcell.ModMask
}
2018-08-26 06:06:44 +03:00
2018-08-29 01:44:52 +03:00
type KeyAction func(Handler) bool
type MouseAction func(Handler, tcell.EventMouse) bool
2018-08-28 02:53:08 +03:00
// A Handler will take a tcell event and execute it
2018-08-27 22:53:10 +03:00
// appropriately
2018-08-28 02:53:08 +03:00
type Handler interface {
2018-08-27 22:53:10 +03:00
HandleEvent(tcell.Event)
2019-01-11 22:49:22 +03:00
HandleCommand(string)
2018-08-26 06:06:44 +03:00
}