keys.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. from __future__ import annotations
  2. from enum import Enum
  3. __all__ = [
  4. "Keys",
  5. "ALL_KEYS",
  6. ]
  7. class Keys(str, Enum):
  8. """
  9. List of keys for use in key bindings.
  10. Note that this is an "StrEnum", all values can be compared against
  11. strings.
  12. """
  13. value: str
  14. Escape = "escape" # Also Control-[
  15. ShiftEscape = "s-escape"
  16. ControlAt = "c-@" # Also Control-Space.
  17. ControlA = "c-a"
  18. ControlB = "c-b"
  19. ControlC = "c-c"
  20. ControlD = "c-d"
  21. ControlE = "c-e"
  22. ControlF = "c-f"
  23. ControlG = "c-g"
  24. ControlH = "c-h"
  25. ControlI = "c-i" # Tab
  26. ControlJ = "c-j" # Newline
  27. ControlK = "c-k"
  28. ControlL = "c-l"
  29. ControlM = "c-m" # Carriage return
  30. ControlN = "c-n"
  31. ControlO = "c-o"
  32. ControlP = "c-p"
  33. ControlQ = "c-q"
  34. ControlR = "c-r"
  35. ControlS = "c-s"
  36. ControlT = "c-t"
  37. ControlU = "c-u"
  38. ControlV = "c-v"
  39. ControlW = "c-w"
  40. ControlX = "c-x"
  41. ControlY = "c-y"
  42. ControlZ = "c-z"
  43. Control1 = "c-1"
  44. Control2 = "c-2"
  45. Control3 = "c-3"
  46. Control4 = "c-4"
  47. Control5 = "c-5"
  48. Control6 = "c-6"
  49. Control7 = "c-7"
  50. Control8 = "c-8"
  51. Control9 = "c-9"
  52. Control0 = "c-0"
  53. ControlShift1 = "c-s-1"
  54. ControlShift2 = "c-s-2"
  55. ControlShift3 = "c-s-3"
  56. ControlShift4 = "c-s-4"
  57. ControlShift5 = "c-s-5"
  58. ControlShift6 = "c-s-6"
  59. ControlShift7 = "c-s-7"
  60. ControlShift8 = "c-s-8"
  61. ControlShift9 = "c-s-9"
  62. ControlShift0 = "c-s-0"
  63. ControlBackslash = "c-\\"
  64. ControlSquareClose = "c-]"
  65. ControlCircumflex = "c-^"
  66. ControlUnderscore = "c-_"
  67. Left = "left"
  68. Right = "right"
  69. Up = "up"
  70. Down = "down"
  71. Home = "home"
  72. End = "end"
  73. Insert = "insert"
  74. Delete = "delete"
  75. PageUp = "pageup"
  76. PageDown = "pagedown"
  77. ControlLeft = "c-left"
  78. ControlRight = "c-right"
  79. ControlUp = "c-up"
  80. ControlDown = "c-down"
  81. ControlHome = "c-home"
  82. ControlEnd = "c-end"
  83. ControlInsert = "c-insert"
  84. ControlDelete = "c-delete"
  85. ControlPageUp = "c-pageup"
  86. ControlPageDown = "c-pagedown"
  87. ShiftLeft = "s-left"
  88. ShiftRight = "s-right"
  89. ShiftUp = "s-up"
  90. ShiftDown = "s-down"
  91. ShiftHome = "s-home"
  92. ShiftEnd = "s-end"
  93. ShiftInsert = "s-insert"
  94. ShiftDelete = "s-delete"
  95. ShiftPageUp = "s-pageup"
  96. ShiftPageDown = "s-pagedown"
  97. ControlShiftLeft = "c-s-left"
  98. ControlShiftRight = "c-s-right"
  99. ControlShiftUp = "c-s-up"
  100. ControlShiftDown = "c-s-down"
  101. ControlShiftHome = "c-s-home"
  102. ControlShiftEnd = "c-s-end"
  103. ControlShiftInsert = "c-s-insert"
  104. ControlShiftDelete = "c-s-delete"
  105. ControlShiftPageUp = "c-s-pageup"
  106. ControlShiftPageDown = "c-s-pagedown"
  107. BackTab = "s-tab" # shift + tab
  108. F1 = "f1"
  109. F2 = "f2"
  110. F3 = "f3"
  111. F4 = "f4"
  112. F5 = "f5"
  113. F6 = "f6"
  114. F7 = "f7"
  115. F8 = "f8"
  116. F9 = "f9"
  117. F10 = "f10"
  118. F11 = "f11"
  119. F12 = "f12"
  120. F13 = "f13"
  121. F14 = "f14"
  122. F15 = "f15"
  123. F16 = "f16"
  124. F17 = "f17"
  125. F18 = "f18"
  126. F19 = "f19"
  127. F20 = "f20"
  128. F21 = "f21"
  129. F22 = "f22"
  130. F23 = "f23"
  131. F24 = "f24"
  132. ControlF1 = "c-f1"
  133. ControlF2 = "c-f2"
  134. ControlF3 = "c-f3"
  135. ControlF4 = "c-f4"
  136. ControlF5 = "c-f5"
  137. ControlF6 = "c-f6"
  138. ControlF7 = "c-f7"
  139. ControlF8 = "c-f8"
  140. ControlF9 = "c-f9"
  141. ControlF10 = "c-f10"
  142. ControlF11 = "c-f11"
  143. ControlF12 = "c-f12"
  144. ControlF13 = "c-f13"
  145. ControlF14 = "c-f14"
  146. ControlF15 = "c-f15"
  147. ControlF16 = "c-f16"
  148. ControlF17 = "c-f17"
  149. ControlF18 = "c-f18"
  150. ControlF19 = "c-f19"
  151. ControlF20 = "c-f20"
  152. ControlF21 = "c-f21"
  153. ControlF22 = "c-f22"
  154. ControlF23 = "c-f23"
  155. ControlF24 = "c-f24"
  156. # Matches any key.
  157. Any = "<any>"
  158. # Special.
  159. ScrollUp = "<scroll-up>"
  160. ScrollDown = "<scroll-down>"
  161. CPRResponse = "<cursor-position-response>"
  162. Vt100MouseEvent = "<vt100-mouse-event>"
  163. WindowsMouseEvent = "<windows-mouse-event>"
  164. BracketedPaste = "<bracketed-paste>"
  165. SIGINT = "<sigint>"
  166. # For internal use: key which is ignored.
  167. # (The key binding for this key should not do anything.)
  168. Ignore = "<ignore>"
  169. # Some 'Key' aliases (for backwards-compatibility).
  170. ControlSpace = ControlAt
  171. Tab = ControlI
  172. Enter = ControlM
  173. Backspace = ControlH
  174. # ShiftControl was renamed to ControlShift in
  175. # 888fcb6fa4efea0de8333177e1bbc792f3ff3c24 (20 Feb 2020).
  176. ShiftControlLeft = ControlShiftLeft
  177. ShiftControlRight = ControlShiftRight
  178. ShiftControlHome = ControlShiftHome
  179. ShiftControlEnd = ControlShiftEnd
  180. ALL_KEYS: list[str] = [k.value for k in Keys]
  181. # Aliases.
  182. KEY_ALIASES: dict[str, str] = {
  183. "backspace": "c-h",
  184. "c-space": "c-@",
  185. "enter": "c-m",
  186. "tab": "c-i",
  187. # ShiftControl was renamed to ControlShift.
  188. "s-c-left": "c-s-left",
  189. "s-c-right": "c-s-right",
  190. "s-c-home": "c-s-home",
  191. "s-c-end": "c-s-end",
  192. }