Skip to content

Commit a2e616e

Browse files
Niloth-pParth576
authored andcommitted
helper/model/ui/boxes/buttons/views: Refine UI display of hotkeys.
Update all the files that display hotkeys to the user, to use the new display functions for consistent output. The internal usage (mainly for keypresses) is left to use the default Urwid representation. Tests updated. Co-authored-by: Parth Shah <[email protected]>
1 parent 48f32d1 commit a2e616e

File tree

8 files changed

+77
-36
lines changed

8 files changed

+77
-36
lines changed

tests/helper/test_helper.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from pytest_mock import MockerFixture
66

77
from zulipterminal.api_types import Composition
8-
from zulipterminal.config.keys import primary_key_for_command
8+
from zulipterminal.config.keys import primary_display_key_for_command
99
from zulipterminal.helper import (
1010
Index,
1111
canonicalize_color,
@@ -469,7 +469,7 @@ def test_notify_if_message_sent_outside_narrow(
469469
notify_if_message_sent_outside_narrow(req, controller)
470470

471471
if footer_updated:
472-
key = primary_key_for_command("NARROW_MESSAGE_RECIPIENT")
472+
key = primary_display_key_for_command("NARROW_MESSAGE_RECIPIENT")
473473
report_success.assert_called_once_with(
474474
[
475475
"Message is sent outside of current narrow."

tests/ui_tools/test_boxes.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
TYPING_STARTED_WAIT_PERIOD,
1313
TYPING_STOPPED_WAIT_PERIOD,
1414
)
15-
from zulipterminal.config.keys import keys_for_command, primary_key_for_command
15+
from zulipterminal.config.keys import (
16+
keys_for_command,
17+
primary_display_key_for_command,
18+
primary_key_for_command,
19+
)
1620
from zulipterminal.config.symbols import (
1721
INVALID_MARKER,
1822
STREAM_MARKER_PRIVATE,
@@ -379,9 +383,12 @@ def test_footer_notification_on_invalid_recipients(
379383
expected_lines = [
380384
"Invalid recipient(s) - " + invalid_recipients,
381385
" - Use ",
382-
("footer_contrast", primary_key_for_command("AUTOCOMPLETE")),
386+
("footer_contrast", primary_display_key_for_command("AUTOCOMPLETE")),
383387
" or ",
384-
("footer_contrast", primary_key_for_command("AUTOCOMPLETE_REVERSE")),
388+
(
389+
"footer_contrast",
390+
primary_display_key_for_command("AUTOCOMPLETE_REVERSE"),
391+
),
385392
" to autocomplete.",
386393
]
387394

@@ -1760,8 +1767,8 @@ class TestPanelSearchBox:
17601767

17611768
@pytest.fixture
17621769
def panel_search_box(self, mocker: MockerFixture) -> PanelSearchBox:
1763-
# X is the return from keys_for_command("UNTESTED_TOKEN")
1764-
mocker.patch(MODULE + ".keys_for_command", return_value="X")
1770+
# X is the return from display_keys_for_command("UNTESTED_TOKEN")
1771+
mocker.patch(MODULE + ".display_keys_for_command", return_value="X")
17651772
panel_view = mocker.Mock()
17661773
update_func = mocker.Mock()
17671774
return PanelSearchBox(panel_view, "UNTESTED_TOKEN", update_func)

zulipterminal/helper.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from typing_extensions import Literal, ParamSpec, TypedDict
3434

3535
from zulipterminal.api_types import Composition, EmojiType, Message
36-
from zulipterminal.config.keys import primary_key_for_command
36+
from zulipterminal.config.keys import primary_display_key_for_command
3737
from zulipterminal.config.regexes import (
3838
REGEX_COLOR_3_DIGIT,
3939
REGEX_COLOR_6_DIGIT,
@@ -700,7 +700,7 @@ def check_narrow_and_notify(
700700
and current_narrow != outer_narrow
701701
and current_narrow != inner_narrow
702702
):
703-
key = primary_key_for_command("NARROW_MESSAGE_RECIPIENT")
703+
key = primary_display_key_for_command("NARROW_MESSAGE_RECIPIENT")
704704

705705
controller.report_success(
706706
[

zulipterminal/model.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
UpdateMessageContentEvent,
5757
UpdateMessagesLocationEvent,
5858
)
59-
from zulipterminal.config.keys import primary_key_for_command
59+
from zulipterminal.config.keys import primary_display_key_for_command
6060
from zulipterminal.config.symbols import STREAM_TOPIC_SEPARATOR
6161
from zulipterminal.config.ui_mappings import EDIT_TOPIC_POLICY, ROLE_BY_ID, STATE_ICON
6262
from zulipterminal.helper import (
@@ -1671,7 +1671,7 @@ def _handle_message_event(self, event: Event) -> None:
16711671
"Press '{}' to close this window."
16721672
)
16731673
notice = notice_template.format(
1674-
failed_command, primary_key_for_command("GO_BACK")
1674+
failed_command, primary_display_key_for_command("GO_BACK")
16751675
)
16761676
self.controller.popup_with_message(notice, width=50)
16771677
self.controller.update_screen()

zulipterminal/ui.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99

1010
import urwid
1111

12-
from zulipterminal.config.keys import commands_for_random_tips, is_command_key
12+
from zulipterminal.config.keys import (
13+
commands_for_random_tips,
14+
display_key_for_urwid_key,
15+
is_command_key,
16+
)
1317
from zulipterminal.config.symbols import (
1418
APPLICATION_TITLE_BAR_LINE,
1519
AUTOHIDE_TAB_LEFT_ARROW,
@@ -102,10 +106,13 @@ def get_random_help(self) -> List[Any]:
102106
if not allowed_commands:
103107
return ["Help(?): "]
104108
random_command = random.choice(allowed_commands)
109+
random_command_display_keys = ", ".join(
110+
[display_key_for_urwid_key(key) for key in random_command["keys"]]
111+
)
105112
return [
106113
"Help(?): ",
107-
("footer_contrast", " " + ", ".join(random_command["keys"]) + " "),
108-
" " + random_command["help_text"],
114+
("footer_contrast", f" {random_command_display_keys} "),
115+
f" {random_command['help_text']}",
109116
]
110117

111118
@asynch

zulipterminal/ui_tools/boxes.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515

1616
from zulipterminal.api_types import Composition, PrivateComposition, StreamComposition
1717
from zulipterminal.config.keys import (
18+
display_keys_for_command,
1819
is_command_key,
19-
keys_for_command,
20+
primary_display_key_for_command,
2021
primary_key_for_command,
2122
)
2223
from zulipterminal.config.regexes import (
@@ -302,11 +303,11 @@ def _tidy_valid_recipients_and_notify_invalid_ones(
302303
invalid_recipients_error = [
303304
"Invalid recipient(s) - " + ", ".join(invalid_recipients),
304305
" - Use ",
305-
("footer_contrast", primary_key_for_command("AUTOCOMPLETE")),
306+
("footer_contrast", primary_display_key_for_command("AUTOCOMPLETE")),
306307
" or ",
307308
(
308309
"footer_contrast",
309-
primary_key_for_command("AUTOCOMPLETE_REVERSE"),
310+
primary_display_key_for_command("AUTOCOMPLETE_REVERSE"),
310311
),
311312
" to autocomplete.",
312313
]
@@ -850,8 +851,10 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
850851
invalid_stream_error = (
851852
"Invalid stream name."
852853
" Use {} or {} to autocomplete.".format(
853-
primary_key_for_command("AUTOCOMPLETE"),
854-
primary_key_for_command("AUTOCOMPLETE_REVERSE"),
854+
primary_display_key_for_command("AUTOCOMPLETE"),
855+
primary_display_key_for_command(
856+
"AUTOCOMPLETE_REVERSE"
857+
),
855858
)
856859
)
857860
self.view.controller.report_error([invalid_stream_error])
@@ -918,7 +921,9 @@ def __init__(self, controller: Any) -> None:
918921
super().__init__(self.main_view())
919922

920923
def main_view(self) -> Any:
921-
search_text = f"Search [{', '.join(keys_for_command('SEARCH_MESSAGES'))}]: "
924+
search_text = (
925+
f"Search [{', '.join(display_keys_for_command('SEARCH_MESSAGES'))}]: "
926+
)
922927
self.text_box = ReadlineEdit(f"{search_text} ")
923928
# Add some text so that when packing,
924929
# urwid doesn't hide the widget.
@@ -967,7 +972,9 @@ def __init__(
967972
) -> None:
968973
self.panel_view = panel_view
969974
self.search_command = search_command
970-
self.search_text = f" Search [{', '.join(keys_for_command(search_command))}]: "
975+
self.search_text = (
976+
f" Search [{', '.join(display_keys_for_command(search_command))}]: "
977+
)
971978
self.search_error = urwid.AttrMap(
972979
urwid.Text([" ", INVALID_MARKER, " No Results"]), "search_error"
973980
)

zulipterminal/ui_tools/buttons.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
from typing_extensions import TypedDict
1212

1313
from zulipterminal.api_types import RESOLVED_TOPIC_PREFIX, EditPropagateMode, Message
14-
from zulipterminal.config.keys import is_command_key, primary_key_for_command
14+
from zulipterminal.config.keys import (
15+
is_command_key,
16+
primary_display_key_for_command,
17+
primary_key_for_command,
18+
)
1519
from zulipterminal.config.regexes import REGEX_INTERNAL_LINK_STREAM_ID
1620
from zulipterminal.config.symbols import (
1721
ALL_MESSAGES_MARKER,
@@ -125,7 +129,9 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
125129

126130
class HomeButton(TopButton):
127131
def __init__(self, *, controller: Any, count: int) -> None:
128-
button_text = f"All messages [{primary_key_for_command('ALL_MESSAGES')}]"
132+
button_text = (
133+
f"All messages [{primary_display_key_for_command('ALL_MESSAGES')}]"
134+
)
129135

130136
super().__init__(
131137
controller=controller,
@@ -139,7 +145,7 @@ def __init__(self, *, controller: Any, count: int) -> None:
139145

140146
class PMButton(TopButton):
141147
def __init__(self, *, controller: Any, count: int) -> None:
142-
button_text = f"Direct messages [{primary_key_for_command('ALL_PM')}]"
148+
button_text = f"Direct messages [{primary_display_key_for_command('ALL_PM')}]"
143149

144150
super().__init__(
145151
controller=controller,
@@ -153,7 +159,9 @@ def __init__(self, *, controller: Any, count: int) -> None:
153159

154160
class MentionedButton(TopButton):
155161
def __init__(self, *, controller: Any, count: int) -> None:
156-
button_text = f"Mentions [{primary_key_for_command('ALL_MENTIONS')}]"
162+
button_text = (
163+
f"Mentions [{primary_display_key_for_command('ALL_MENTIONS')}]"
164+
)
157165

158166
super().__init__(
159167
controller=controller,
@@ -167,7 +175,9 @@ def __init__(self, *, controller: Any, count: int) -> None:
167175

168176
class StarredButton(TopButton):
169177
def __init__(self, *, controller: Any, count: int) -> None:
170-
button_text = f"Starred messages [{primary_key_for_command('ALL_STARRED')}]"
178+
button_text = (
179+
f"Starred messages [{primary_display_key_for_command('ALL_STARRED')}]"
180+
)
171181

172182
super().__init__(
173183
controller=controller,

zulipterminal/ui_tools/views.py

+20-10
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
from zulipterminal.config.keys import (
1515
HELP_CATEGORIES,
1616
KEY_BINDINGS,
17+
display_key_for_urwid_key,
18+
display_keys_for_command,
1719
is_command_key,
18-
keys_for_command,
1920
primary_key_for_command,
2021
)
2122
from zulipterminal.config.markdown_examples import MARKDOWN_ELEMENTS
@@ -1225,9 +1226,14 @@ def __init__(self, controller: Any, title: str) -> None:
12251226
for binding in KEY_BINDINGS.values()
12261227
if binding["key_category"] == category
12271228
)
1228-
key_bindings = []
1229-
for binding in keys_in_category:
1230-
key_bindings.append((binding["help_text"], ", ".join(binding["keys"])))
1229+
key_bindings = [
1230+
(
1231+
binding["help_text"],
1232+
", ".join(map(display_key_for_urwid_key, binding["keys"])),
1233+
)
1234+
for binding in keys_in_category
1235+
]
1236+
12311237
help_menu_content.append((HELP_CATEGORIES[category], key_bindings))
12321238

12331239
popup_width, column_widths = self.calculate_table_widths(
@@ -1379,15 +1385,17 @@ def __init__(self, controller: Any, stream_id: int) -> None:
13791385
if stream["history_public_to_subscribers"]
13801386
else "Not Public to Users"
13811387
)
1382-
member_keys = ", ".join(map(repr, keys_for_command("STREAM_MEMBERS")))
1388+
member_keys = ", ".join(map(repr, display_keys_for_command("STREAM_MEMBERS")))
13831389

13841390
# FIXME: This field was removed from the subscription data in Zulip 7.5 / ZFL226
13851391
# We should use the new /streams/{stream_id}/email_address endpoint instead
13861392
self._stream_email = stream.get("email_address", None)
13871393
if self._stream_email is None:
13881394
stream_copy_text = "< Stream email is unavailable >"
13891395
else:
1390-
email_keys = ", ".join(map(repr, keys_for_command("COPY_STREAM_EMAIL")))
1396+
email_keys = ", ".join(
1397+
map(repr, display_keys_for_command("COPY_STREAM_EMAIL"))
1398+
)
13911399
stream_copy_text = f"Press {email_keys} to copy Stream email address"
13921400

13931401
weekly_traffic = stream["stream_weekly_traffic"]
@@ -1562,14 +1570,14 @@ def __init__(
15621570
msg["timestamp"], show_seconds=True, show_year=True
15631571
)
15641572
view_in_browser_keys = "[{}]".format(
1565-
", ".join(map(str, keys_for_command("VIEW_IN_BROWSER")))
1573+
", ".join(map(str, display_keys_for_command("VIEW_IN_BROWSER")))
15661574
)
15671575

15681576
full_rendered_message_keys = "[{}]".format(
1569-
", ".join(map(str, keys_for_command("FULL_RENDERED_MESSAGE")))
1577+
", ".join(map(str, display_keys_for_command("FULL_RENDERED_MESSAGE")))
15701578
)
15711579
full_raw_message_keys = "[{}]".format(
1572-
", ".join(map(str, keys_for_command("FULL_RAW_MESSAGE")))
1580+
", ".join(map(str, display_keys_for_command("FULL_RAW_MESSAGE")))
15731581
)
15741582
msg_info = [
15751583
(
@@ -1601,7 +1609,9 @@ def __init__(
16011609
if self.show_edit_history_label:
16021610
msg_info[0][1][0] = ("Date & Time (Original)", date_and_time)
16031611

1604-
keys = "[{}]".format(", ".join(map(str, keys_for_command("EDIT_HISTORY"))))
1612+
keys = "[{}]".format(
1613+
", ".join(map(str, display_keys_for_command("EDIT_HISTORY")))
1614+
)
16051615
msg_info[1][1].append(("Edit History", keys))
16061616
# Render the category using the existing table methods if links exist.
16071617
if message_links:

0 commit comments

Comments
 (0)