github.com/markusbkk/elvish@v0.0.0-20231204143114-91dc52438621/pkg/cli/term/event.go (about) 1 package term 2 3 import "github.com/markusbkk/elvish/pkg/ui" 4 5 // Event represents an event that can be read from the terminal. 6 type Event interface { 7 isEvent() 8 } 9 10 // KeyEvent represents a key press. 11 type KeyEvent ui.Key 12 13 // K constructs a new KeyEvent. 14 func K(r rune, mods ...ui.Mod) KeyEvent { 15 return KeyEvent(ui.K(r, mods...)) 16 } 17 18 // MouseEvent represents a mouse event (either pressing or releasing). 19 type MouseEvent struct { 20 Pos 21 Down bool 22 // Number of the Button, 0-based. -1 for unknown. 23 Button int 24 Mod ui.Mod 25 } 26 27 // CursorPosition represents a report of the current cursor position from the 28 // terminal driver, usually as a response from a cursor position request. 29 type CursorPosition Pos 30 31 // PasteSetting indicates the start or finish of pasted text. 32 type PasteSetting bool 33 34 // FatalErrorEvent represents an error that affects the Reader's ability to 35 // continue reading events. After sending a FatalError, the Reader makes no more 36 // attempts at continuing to read events and wait for Stop to be called. 37 type FatalErrorEvent struct{ Err error } 38 39 // NonfatalErrorEvent represents an error that can be gradually recovered. After 40 // sending a NonfatalError, the Reader will continue to read events. Note that 41 // one anamoly in the terminal might cause multiple NonfatalError events to be 42 // sent. 43 type NonfatalErrorEvent struct{ Err error } 44 45 func (KeyEvent) isEvent() {} 46 func (MouseEvent) isEvent() {} 47 48 func (CursorPosition) isEvent() {} 49 func (PasteSetting) isEvent() {} 50 51 func (FatalErrorEvent) isEvent() {} 52 func (NonfatalErrorEvent) isEvent() {}