| 1 | package input |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "strings" |
| 6 | ) |
| 7 | |
| 8 | // Event represents a terminal event. |
| 9 | type Event any |
| 10 | |
| 11 | // UnknownEvent represents an unknown event. |
| 12 | type UnknownEvent string |
| 13 | |
| 14 | // String returns a string representation of the unknown event. |
| 15 | func (e UnknownEvent) String() string { |
| 16 | return fmt.Sprintf("%q", string(e)) |
| 17 | } |
| 18 | |
| 19 | // MultiEvent represents multiple messages event. |
| 20 | type MultiEvent []Event |
| 21 | |
| 22 | // String returns a string representation of the multiple messages event. |
| 23 | func (e MultiEvent) String() string { |
| 24 | var sb strings.Builder |
| 25 | for _, ev := range e { |
| 26 | sb.WriteString(fmt.Sprintf("%v\n", ev)) |
| 27 | } |
| 28 | return sb.String() |
| 29 | } |
| 30 | |
| 31 | // WindowSizeEvent is used to report the terminal size. Note that Windows does |
| 32 | // not have support for reporting resizes via SIGWINCH signals and relies on |
| 33 | // the Windows Console API to report window size changes. |
| 34 | type WindowSizeEvent struct { |
| 35 | Width int |
| 36 | Height int |
| 37 | } |
| 38 | |
| 39 | // WindowOpEvent is a window operation (XTWINOPS) report event. This is used to |
| 40 | // report various window operations such as reporting the window size or cell |
| 41 | // size. |
| 42 | type WindowOpEvent struct { |
| 43 | Op int |
| 44 | Args []int |
| 45 | } |