Module textual.keys
Expand source code
from __future__ import annotations
from enum import Enum
# Adapted from prompt toolkit https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/prompt_toolkit/keys.py
class Keys(str, Enum):
"""
List of keys for use in key bindings.
Note that this is an "StrEnum", all values can be compared against
strings.
"""
value: str
Escape = "escape" # Also Control-[
ShiftEscape = "shift+escape"
Return = "return"
ControlAt = "ctrl+@" # Also Control-Space.
ControlA = "ctrl+a"
ControlB = "ctrl+b"
ControlC = "ctrl+c"
ControlD = "ctrl+d"
ControlE = "ctrl+e"
ControlF = "ctrl+f"
ControlG = "ctrl+g"
ControlH = "ctrl+h"
ControlI = "ctrl+i" # Tab
ControlJ = "ctrl+j" # Newline
ControlK = "ctrl+k"
ControlL = "ctrl+l"
ControlM = "ctrl+m" # Carriage return
ControlN = "ctrl+n"
ControlO = "ctrl+o"
ControlP = "ctrl+p"
ControlQ = "ctrl+q"
ControlR = "ctrl+r"
ControlS = "ctrl+s"
ControlT = "ctrl+t"
ControlU = "ctrl+u"
ControlV = "ctrl+v"
ControlW = "ctrl+w"
ControlX = "ctrl+x"
ControlY = "ctrl+y"
ControlZ = "ctrl+z"
Control1 = "ctrl+1"
Control2 = "ctrl+2"
Control3 = "ctrl+3"
Control4 = "ctrl+4"
Control5 = "ctrl+5"
Control6 = "ctrl+6"
Control7 = "ctrl+7"
Control8 = "ctrl+8"
Control9 = "ctrl+9"
Control0 = "ctrl+0"
ControlShift1 = "ctrl+shift+1"
ControlShift2 = "ctrl+shift+2"
ControlShift3 = "ctrl+shift+3"
ControlShift4 = "ctrl+shift+4"
ControlShift5 = "ctrl+shift+5"
ControlShift6 = "ctrl+shift+6"
ControlShift7 = "ctrl+shift+7"
ControlShift8 = "ctrl+shift+8"
ControlShift9 = "ctrl+shift+9"
ControlShift0 = "ctrl+shift+0"
ControlBackslash = "ctrl+\\"
ControlSquareClose = "ctrl+]"
ControlCircumflex = "ctrl+^"
ControlUnderscore = "ctrl+_"
Left = "left"
Right = "right"
Up = "up"
Down = "down"
Home = "home"
End = "end"
Insert = "insert"
Delete = "delete"
PageUp = "pageup"
PageDown = "pagedown"
ControlLeft = "ctrl+left"
ControlRight = "ctrl+right"
ControlUp = "ctrl+up"
ControlDown = "ctrl+down"
ControlHome = "ctrl+home"
ControlEnd = "ctrl+end"
ControlInsert = "ctrl+insert"
ControlDelete = "ctrl+delete"
ControlPageUp = "ctrl+pageup"
ControlPageDown = "ctrl+pagedown"
ShiftLeft = "shift+left"
ShiftRight = "shift+right"
ShiftUp = "shift+up"
ShiftDown = "shift+down"
ShiftHome = "shift+home"
ShiftEnd = "shift+end"
ShiftInsert = "shift+insert"
ShiftDelete = "shift+delete"
ShiftPageUp = "shift+pageup"
ShiftPageDown = "shift+pagedown"
ControlShiftLeft = "ctrl+shift+left"
ControlShiftRight = "ctrl+shift+right"
ControlShiftUp = "ctrl+shift+up"
ControlShiftDown = "ctrl+shift+down"
ControlShiftHome = "ctrl+shift+home"
ControlShiftEnd = "ctrl+shift+end"
ControlShiftInsert = "ctrl+shift+insert"
ControlShiftDelete = "ctrl+shift+delete"
ControlShiftPageUp = "ctrl+shift+pageup"
ControlShiftPageDown = "ctrl+shift+pagedown"
BackTab = "shift+tab" # shift + tab
F1 = "f1"
F2 = "f2"
F3 = "f3"
F4 = "f4"
F5 = "f5"
F6 = "f6"
F7 = "f7"
F8 = "f8"
F9 = "f9"
F10 = "f10"
F11 = "f11"
F12 = "f12"
F13 = "f13"
F14 = "f14"
F15 = "f15"
F16 = "f16"
F17 = "f17"
F18 = "f18"
F19 = "f19"
F20 = "f20"
F21 = "f21"
F22 = "f22"
F23 = "f23"
F24 = "f24"
ControlF1 = "ctrl+f1"
ControlF2 = "ctrl+f2"
ControlF3 = "ctrl+f3"
ControlF4 = "ctrl+f4"
ControlF5 = "ctrl+f5"
ControlF6 = "ctrl+f6"
ControlF7 = "ctrl+f7"
ControlF8 = "ctrl+f8"
ControlF9 = "ctrl+f9"
ControlF10 = "ctrl+f10"
ControlF11 = "ctrl+f11"
ControlF12 = "ctrl+f12"
ControlF13 = "ctrl+f13"
ControlF14 = "ctrl+f14"
ControlF15 = "ctrl+f15"
ControlF16 = "ctrl+f16"
ControlF17 = "ctrl+f17"
ControlF18 = "ctrl+f18"
ControlF19 = "ctrl+f19"
ControlF20 = "ctrl+f20"
ControlF21 = "ctrl+f21"
ControlF22 = "ctrl+f22"
ControlF23 = "ctrl+f23"
ControlF24 = "ctrl+f24"
# Matches any key.
Any = "<any>"
# Special.
ScrollUp = "<scroll-up>"
ScrollDown = "<scroll-down>"
# For internal use: key which is ignored.
# (The key binding for this key should not do anything.)
Ignore = "<ignore>"
# Some 'Key' aliases (for backwardshift+compatibility).
ControlSpace = "ctrl-at"
Tab = "tab"
Space = "space"
Enter = "enter"
Backspace = "backspace"
# ShiftControl was renamed to ControlShift in
# 888fcb6fa4efea0de8333177e1bbc792f3ff3c24 (20 Feb 2020).
ShiftControlLeft = ControlShiftLeft
ShiftControlRight = ControlShiftRight
ShiftControlHome = ControlShiftHome
ShiftControlEnd = ControlShiftEnd
# Unicode db contains some obscure names
# This mapping replaces them with more common terms
KEY_NAME_REPLACEMENTS = {
"solidus": "slash",
"reverse_solidus": "backslash",
"commercial_at": "at",
"hyphen_minus": "minus",
"plus_sign": "plus",
"low_line": "underscore",
}
REPLACED_KEYS = {value: key for key, value in KEY_NAME_REPLACEMENTS.items()}
# Some keys have aliases. For example, if you press `ctrl+m` on your keyboard,
# it's treated the same way as if you press `enter`. Key handlers `key_ctrl_m` and
# `key_enter` are both valid in this case.
KEY_ALIASES = {
"tab": ["ctrl+i"],
"enter": ["ctrl+m"],
"escape": ["ctrl+left_square_brace"],
"ctrl+at": ["ctrl+space"],
"ctrl+j": ["newline"],
}
def _get_key_aliases(key: str) -> list[str]:
"""Return all aliases for the given key, including the key itself"""
return [key] + KEY_ALIASES.get(key, [])
Classes
class Keys (value, names=None, *, module=None, qualname=None, type=None, start=1)-
List of keys for use in key bindings.
Note that this is an "StrEnum", all values can be compared against strings.
Expand source code
class Keys(str, Enum): """ List of keys for use in key bindings. Note that this is an "StrEnum", all values can be compared against strings. """ value: str Escape = "escape" # Also Control-[ ShiftEscape = "shift+escape" Return = "return" ControlAt = "ctrl+@" # Also Control-Space. ControlA = "ctrl+a" ControlB = "ctrl+b" ControlC = "ctrl+c" ControlD = "ctrl+d" ControlE = "ctrl+e" ControlF = "ctrl+f" ControlG = "ctrl+g" ControlH = "ctrl+h" ControlI = "ctrl+i" # Tab ControlJ = "ctrl+j" # Newline ControlK = "ctrl+k" ControlL = "ctrl+l" ControlM = "ctrl+m" # Carriage return ControlN = "ctrl+n" ControlO = "ctrl+o" ControlP = "ctrl+p" ControlQ = "ctrl+q" ControlR = "ctrl+r" ControlS = "ctrl+s" ControlT = "ctrl+t" ControlU = "ctrl+u" ControlV = "ctrl+v" ControlW = "ctrl+w" ControlX = "ctrl+x" ControlY = "ctrl+y" ControlZ = "ctrl+z" Control1 = "ctrl+1" Control2 = "ctrl+2" Control3 = "ctrl+3" Control4 = "ctrl+4" Control5 = "ctrl+5" Control6 = "ctrl+6" Control7 = "ctrl+7" Control8 = "ctrl+8" Control9 = "ctrl+9" Control0 = "ctrl+0" ControlShift1 = "ctrl+shift+1" ControlShift2 = "ctrl+shift+2" ControlShift3 = "ctrl+shift+3" ControlShift4 = "ctrl+shift+4" ControlShift5 = "ctrl+shift+5" ControlShift6 = "ctrl+shift+6" ControlShift7 = "ctrl+shift+7" ControlShift8 = "ctrl+shift+8" ControlShift9 = "ctrl+shift+9" ControlShift0 = "ctrl+shift+0" ControlBackslash = "ctrl+\\" ControlSquareClose = "ctrl+]" ControlCircumflex = "ctrl+^" ControlUnderscore = "ctrl+_" Left = "left" Right = "right" Up = "up" Down = "down" Home = "home" End = "end" Insert = "insert" Delete = "delete" PageUp = "pageup" PageDown = "pagedown" ControlLeft = "ctrl+left" ControlRight = "ctrl+right" ControlUp = "ctrl+up" ControlDown = "ctrl+down" ControlHome = "ctrl+home" ControlEnd = "ctrl+end" ControlInsert = "ctrl+insert" ControlDelete = "ctrl+delete" ControlPageUp = "ctrl+pageup" ControlPageDown = "ctrl+pagedown" ShiftLeft = "shift+left" ShiftRight = "shift+right" ShiftUp = "shift+up" ShiftDown = "shift+down" ShiftHome = "shift+home" ShiftEnd = "shift+end" ShiftInsert = "shift+insert" ShiftDelete = "shift+delete" ShiftPageUp = "shift+pageup" ShiftPageDown = "shift+pagedown" ControlShiftLeft = "ctrl+shift+left" ControlShiftRight = "ctrl+shift+right" ControlShiftUp = "ctrl+shift+up" ControlShiftDown = "ctrl+shift+down" ControlShiftHome = "ctrl+shift+home" ControlShiftEnd = "ctrl+shift+end" ControlShiftInsert = "ctrl+shift+insert" ControlShiftDelete = "ctrl+shift+delete" ControlShiftPageUp = "ctrl+shift+pageup" ControlShiftPageDown = "ctrl+shift+pagedown" BackTab = "shift+tab" # shift + tab F1 = "f1" F2 = "f2" F3 = "f3" F4 = "f4" F5 = "f5" F6 = "f6" F7 = "f7" F8 = "f8" F9 = "f9" F10 = "f10" F11 = "f11" F12 = "f12" F13 = "f13" F14 = "f14" F15 = "f15" F16 = "f16" F17 = "f17" F18 = "f18" F19 = "f19" F20 = "f20" F21 = "f21" F22 = "f22" F23 = "f23" F24 = "f24" ControlF1 = "ctrl+f1" ControlF2 = "ctrl+f2" ControlF3 = "ctrl+f3" ControlF4 = "ctrl+f4" ControlF5 = "ctrl+f5" ControlF6 = "ctrl+f6" ControlF7 = "ctrl+f7" ControlF8 = "ctrl+f8" ControlF9 = "ctrl+f9" ControlF10 = "ctrl+f10" ControlF11 = "ctrl+f11" ControlF12 = "ctrl+f12" ControlF13 = "ctrl+f13" ControlF14 = "ctrl+f14" ControlF15 = "ctrl+f15" ControlF16 = "ctrl+f16" ControlF17 = "ctrl+f17" ControlF18 = "ctrl+f18" ControlF19 = "ctrl+f19" ControlF20 = "ctrl+f20" ControlF21 = "ctrl+f21" ControlF22 = "ctrl+f22" ControlF23 = "ctrl+f23" ControlF24 = "ctrl+f24" # Matches any key. Any = "<any>" # Special. ScrollUp = "<scroll-up>" ScrollDown = "<scroll-down>" # For internal use: key which is ignored. # (The key binding for this key should not do anything.) Ignore = "<ignore>" # Some 'Key' aliases (for backwardshift+compatibility). ControlSpace = "ctrl-at" Tab = "tab" Space = "space" Enter = "enter" Backspace = "backspace" # ShiftControl was renamed to ControlShift in # 888fcb6fa4efea0de8333177e1bbc792f3ff3c24 (20 Feb 2020). ShiftControlLeft = ControlShiftLeft ShiftControlRight = ControlShiftRight ShiftControlHome = ControlShiftHome ShiftControlEnd = ControlShiftEndAncestors
- builtins.str
- enum.Enum
Class variables
var Anyvar BackTabvar Backspacevar Control0var Control1var Control2var Control3var Control4var Control5var Control6var Control7var Control8var Control9var ControlAvar ControlAtvar ControlBvar ControlBackslashvar ControlCvar ControlCircumflexvar ControlDvar ControlDeletevar ControlDownvar ControlEvar ControlEndvar ControlFvar ControlF1var ControlF10var ControlF11var ControlF12var ControlF13var ControlF14var ControlF15var ControlF16var ControlF17var ControlF18var ControlF19var ControlF2var ControlF20var ControlF21var ControlF22var ControlF23var ControlF24var ControlF3var ControlF4var ControlF5var ControlF6var ControlF7var ControlF8var ControlF9var ControlGvar ControlHvar ControlHomevar ControlIvar ControlInsertvar ControlJvar ControlKvar ControlLvar ControlLeftvar ControlMvar ControlNvar ControlOvar ControlPvar ControlPageDownvar ControlPageUpvar ControlQvar ControlRvar ControlRightvar ControlSvar ControlShift0var ControlShift1var ControlShift2var ControlShift3var ControlShift4var ControlShift5var ControlShift6var ControlShift7var ControlShift8var ControlShift9var ControlShiftDeletevar ControlShiftDownvar ControlShiftEndvar ControlShiftHomevar ControlShiftInsertvar ControlShiftLeftvar ControlShiftPageDownvar ControlShiftPageUpvar ControlShiftRightvar ControlShiftUpvar ControlSpacevar ControlSquareClosevar ControlTvar ControlUvar ControlUnderscorevar ControlUpvar ControlVvar ControlWvar ControlXvar ControlYvar ControlZvar Deletevar Downvar Endvar Entervar Escapevar F1var F10var F11var F12var F13var F14var F15var F16var F17var F18var F19var F2var F20var F21var F22var F23var F24var F3var F4var F5var F6var F7var F8var F9var Homevar Ignorevar Insertvar Leftvar PageDownvar PageUpvar Returnvar Rightvar ScrollDownvar ScrollUpvar ShiftControlEndvar ShiftControlHomevar ShiftControlLeftvar ShiftControlRightvar ShiftDeletevar ShiftDownvar ShiftEndvar ShiftEscapevar ShiftHomevar ShiftInsertvar ShiftLeftvar ShiftPageDownvar ShiftPageUpvar ShiftRightvar ShiftUpvar Spacevar Tabvar Up
Instance variables
var value : str-
The value of the Enum member.
Expand source code
@DynamicClassAttribute def value(self): """The value of the Enum member.""" return self._value_