api_common.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. // termbox is a library for creating cross-platform text-based interfaces
  2. package termbox
  3. // public API, common OS agnostic part
  4. type (
  5. InputMode int
  6. OutputMode int
  7. EventType uint8
  8. Modifier uint8
  9. Key uint16
  10. Attribute uint16
  11. )
  12. // This type represents a termbox event. The 'Mod', 'Key' and 'Ch' fields are
  13. // valid if 'Type' is EventKey. The 'Width' and 'Height' fields are valid if
  14. // 'Type' is EventResize. The 'Err' field is valid if 'Type' is EventError.
  15. type Event struct {
  16. Type EventType // one of Event* constants
  17. Mod Modifier // one of Mod* constants or 0
  18. Key Key // one of Key* constants, invalid if 'Ch' is not 0
  19. Ch rune // a unicode character
  20. Width int // width of the screen
  21. Height int // height of the screen
  22. Err error // error in case if input failed
  23. MouseX int // x coord of mouse
  24. MouseY int // y coord of mouse
  25. N int // number of bytes written when getting a raw event
  26. }
  27. // A cell, single conceptual entity on the screen. The screen is basically a 2d
  28. // array of cells. 'Ch' is a unicode character, 'Fg' and 'Bg' are foreground
  29. // and background attributes respectively.
  30. type Cell struct {
  31. Ch rune
  32. Fg Attribute
  33. Bg Attribute
  34. }
  35. // To know if termbox has been initialized or not
  36. var (
  37. IsInit bool = false
  38. )
  39. // Key constants, see Event.Key field.
  40. const (
  41. KeyF1 Key = 0xFFFF - iota
  42. KeyF2
  43. KeyF3
  44. KeyF4
  45. KeyF5
  46. KeyF6
  47. KeyF7
  48. KeyF8
  49. KeyF9
  50. KeyF10
  51. KeyF11
  52. KeyF12
  53. KeyInsert
  54. KeyDelete
  55. KeyHome
  56. KeyEnd
  57. KeyPgup
  58. KeyPgdn
  59. KeyArrowUp
  60. KeyArrowDown
  61. KeyArrowLeft
  62. KeyArrowRight
  63. key_min // see terminfo
  64. MouseLeft
  65. MouseMiddle
  66. MouseRight
  67. MouseRelease
  68. MouseWheelUp
  69. MouseWheelDown
  70. )
  71. const (
  72. KeyCtrlTilde Key = 0x00
  73. KeyCtrl2 Key = 0x00
  74. KeyCtrlSpace Key = 0x00
  75. KeyCtrlA Key = 0x01
  76. KeyCtrlB Key = 0x02
  77. KeyCtrlC Key = 0x03
  78. KeyCtrlD Key = 0x04
  79. KeyCtrlE Key = 0x05
  80. KeyCtrlF Key = 0x06
  81. KeyCtrlG Key = 0x07
  82. KeyBackspace Key = 0x08
  83. KeyCtrlH Key = 0x08
  84. KeyTab Key = 0x09
  85. KeyCtrlI Key = 0x09
  86. KeyCtrlJ Key = 0x0A
  87. KeyCtrlK Key = 0x0B
  88. KeyCtrlL Key = 0x0C
  89. KeyEnter Key = 0x0D
  90. KeyCtrlM Key = 0x0D
  91. KeyCtrlN Key = 0x0E
  92. KeyCtrlO Key = 0x0F
  93. KeyCtrlP Key = 0x10
  94. KeyCtrlQ Key = 0x11
  95. KeyCtrlR Key = 0x12
  96. KeyCtrlS Key = 0x13
  97. KeyCtrlT Key = 0x14
  98. KeyCtrlU Key = 0x15
  99. KeyCtrlV Key = 0x16
  100. KeyCtrlW Key = 0x17
  101. KeyCtrlX Key = 0x18
  102. KeyCtrlY Key = 0x19
  103. KeyCtrlZ Key = 0x1A
  104. KeyEsc Key = 0x1B
  105. KeyCtrlLsqBracket Key = 0x1B
  106. KeyCtrl3 Key = 0x1B
  107. KeyCtrl4 Key = 0x1C
  108. KeyCtrlBackslash Key = 0x1C
  109. KeyCtrl5 Key = 0x1D
  110. KeyCtrlRsqBracket Key = 0x1D
  111. KeyCtrl6 Key = 0x1E
  112. KeyCtrl7 Key = 0x1F
  113. KeyCtrlSlash Key = 0x1F
  114. KeyCtrlUnderscore Key = 0x1F
  115. KeySpace Key = 0x20
  116. KeyBackspace2 Key = 0x7F
  117. KeyCtrl8 Key = 0x7F
  118. )
  119. // Alt modifier constant, see Event.Mod field and SetInputMode function.
  120. const (
  121. ModAlt Modifier = 1 << iota
  122. ModMotion
  123. )
  124. // Cell colors, you can combine a color with multiple attributes using bitwise
  125. // OR ('|').
  126. const (
  127. ColorDefault Attribute = iota
  128. ColorBlack
  129. ColorRed
  130. ColorGreen
  131. ColorYellow
  132. ColorBlue
  133. ColorMagenta
  134. ColorCyan
  135. ColorWhite
  136. )
  137. // Cell attributes, it is possible to use multiple attributes by combining them
  138. // using bitwise OR ('|'). Although, colors cannot be combined. But you can
  139. // combine attributes and a single color.
  140. //
  141. // It's worth mentioning that some platforms don't support certain attibutes.
  142. // For example windows console doesn't support AttrUnderline. And on some
  143. // terminals applying AttrBold to background may result in blinking text. Use
  144. // them with caution and test your code on various terminals.
  145. const (
  146. AttrBold Attribute = 1 << (iota + 9)
  147. AttrUnderline
  148. AttrReverse
  149. )
  150. // Input mode. See SetInputMode function.
  151. const (
  152. InputEsc InputMode = 1 << iota
  153. InputAlt
  154. InputMouse
  155. InputCurrent InputMode = 0
  156. )
  157. // Output mode. See SetOutputMode function.
  158. const (
  159. OutputCurrent OutputMode = iota
  160. OutputNormal
  161. Output256
  162. Output216
  163. OutputGrayscale
  164. )
  165. // Event type. See Event.Type field.
  166. const (
  167. EventKey EventType = iota
  168. EventResize
  169. EventMouse
  170. EventError
  171. EventInterrupt
  172. EventRaw
  173. EventNone
  174. )