Skip to content

Commit

Permalink
keys: Define key-check for primary directional keys.
Browse files Browse the repository at this point in the history
This commit adds a function that checks if a key is one of the
directional keys(i.e. right, left, up or down). This will allow
us to have a more general and concise way of checking for direction
keys during keypress events.
  • Loading branch information
zee-bit committed Mar 23, 2021
1 parent 65b5b5c commit d81c96f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions zulipterminal/config/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ class KeyBinding(TypedDict, total=False):
('msg_compose', 'Composing a Message'),
])

DIRECTIONAL_COMMANDS = [
'GO_UP', 'GO_RIGHT', 'GO_LEFT', 'GO_DOWN'
]


class InvalidCommand(Exception):
pass
Expand Down Expand Up @@ -381,3 +385,12 @@ def commands_for_random_tips() -> List[KeyBinding]:
"""
return [key_binding for key_binding in KEY_BINDINGS.values()
if not key_binding.get('excluded_from_random_tips', False)]


def is_primary_direction_key(key: str) -> bool:
"""
Returns True if the key is one of the directional keys
else False.
"""
return key in [primary_key_for_command(command)
for command in DIRECTIONAL_COMMANDS]

0 comments on commit d81c96f

Please sign in to comment.