input.go 1.1 KB

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