Skip to content

Commit 48f32d1

Browse files
Niloth-pParth576
authored andcommitted
keys: Generate user-friendly representations of hotkey commands.
Since keys_for_command() is used for registering keypresses, separate methods are added for supporting keyboard representations of the urwid keys, without replacing the existing methods. Tests added. Co-authored-by: Parth Shah <[email protected]>
1 parent 72fe01e commit 48f32d1

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

tests/config/test_keys.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict
1+
from typing import Any, Dict, List
22

33
import pytest
44
from pytest_mock import MockerFixture
@@ -139,3 +139,25 @@ def test_updated_urwid_command_map() -> None:
139139
)
140140
def test_display_key_for_urwid_key(urwid_key: str, display_key: str) -> None:
141141
assert keys.display_key_for_urwid_key(urwid_key) == display_key
142+
143+
144+
COMMAND_TO_DISPLAY_KEYS = [
145+
("NEXT_LINE", ["Down", "Ctrl n"]),
146+
("TOGGLE_STAR_STATUS", ["Ctrl s", "*"]),
147+
("ALL_PM", ["P"]),
148+
]
149+
150+
151+
@pytest.mark.parametrize("command, display_keys", COMMAND_TO_DISPLAY_KEYS)
152+
def test_display_keys_for_command(command: str, display_keys: List[str]) -> None:
153+
assert keys.display_keys_for_command(command) == display_keys
154+
155+
156+
@pytest.mark.parametrize("command, display_keys", COMMAND_TO_DISPLAY_KEYS)
157+
def test_primary_display_key_for_command(command: str, display_keys: List[str]) -> None:
158+
assert keys.primary_display_key_for_command(command) == display_keys[0]
159+
160+
161+
def test_display_keys_for_command_invalid_command(invalid_command: str) -> None:
162+
with pytest.raises(keys.InvalidCommand):
163+
keys.display_keys_for_command(invalid_command)

zulipterminal/config/keys.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,22 @@ def display_key_for_urwid_key(urwid_key: str) -> str:
482482
return " ".join(display_key)
483483

484484

485+
def display_keys_for_command(command: str) -> List[str]:
486+
"""
487+
Returns the user-friendly display keys for a given mapped command
488+
"""
489+
return [
490+
display_key_for_urwid_key(urwid_key) for urwid_key in keys_for_command(command)
491+
]
492+
493+
494+
def primary_display_key_for_command(command: str) -> str:
495+
"""
496+
Primary Display Key is the formatted display version of the primary key
497+
"""
498+
return display_key_for_urwid_key(primary_key_for_command(command))
499+
500+
485501
def commands_for_random_tips() -> List[KeyBinding]:
486502
"""
487503
Return list of commands which may be displayed as a random tip

0 commit comments

Comments
 (0)