Skip to content

Commit fa92511

Browse files
committed
run: Check sync of readline shortcuts with urwid_readline's keymap.
Lint exclusions updated.
1 parent 514db27 commit fa92511

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

tools/lint-hotkeys

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ KEYS_TO_EXCLUDE = ["q", "e", "m", "r"]
3434
EXCLUDED_FILES = [
3535
KEYS_FILE,
3636
ZULIPTERMINAL / "config" / "regexes.py",
37+
ZULIPTERMINAL / "cli" / "run.py",
3738
]
3839

3940

zulipterminal/cli/run.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515

1616
import requests
1717
from urwid import display_common, set_encoding
18+
from urwid_readline import ReadlineEdit
1819

1920
from zulipterminal.api_types import ServerSettings
21+
from zulipterminal.config.keys import KEY_BINDINGS, READLINE_SUFFIX
2022
from zulipterminal.config.themes import (
2123
ThemeError,
2224
aliased_themes,
@@ -392,6 +394,34 @@ def list_themes() -> str:
392394
)
393395

394396

397+
class ReadlineShortcutError(Exception):
398+
pass
399+
400+
401+
def check_readline_shortcuts_availability() -> None:
402+
readline_edit = ReadlineEdit()
403+
commands_to_exclude = ["PREV_LINE" + READLINE_SUFFIX, "NEXT_LINE" + READLINE_SUFFIX]
404+
filtered_commands = [
405+
command
406+
for command in KEY_BINDINGS
407+
if command.endswith(READLINE_SUFFIX) and command not in commands_to_exclude
408+
]
409+
410+
missing_keys = []
411+
for command in filtered_commands:
412+
for key in KEY_BINDINGS[command]["keys"]:
413+
if key not in readline_edit.keymap:
414+
key_missing_error = (
415+
f'Key "{key}" for command "{KEY_BINDINGS[command]["help_text"]}" '
416+
f"is not found."
417+
)
418+
missing_keys.append(key_missing_error)
419+
420+
if missing_keys:
421+
error_message = "\n".join(missing_keys)
422+
raise ReadlineShortcutError(error_message)
423+
424+
395425
def main(options: Optional[List[str]] = None) -> None:
396426
"""
397427
Launch Zulip Terminal.
@@ -566,6 +596,17 @@ def print_setting(setting: str, data: SettingData, suffix: str = "") -> None:
566596
for setting, valid_boolean_values in VALID_BOOLEAN_SETTINGS.items():
567597
boolean_settings[setting] = zterm[setting].value == valid_boolean_values[0]
568598

599+
try:
600+
check_readline_shortcuts_availability()
601+
except ReadlineShortcutError as e:
602+
print(
603+
"\nThe following readline shortcuts "
604+
+ "are missing in urwid_readline's keymap.\n"
605+
+ str(e)
606+
+ "\n",
607+
file=sys.stderr,
608+
)
609+
569610
Controller(
570611
config_file=zuliprc_path,
571612
maximum_footlinks=maximum_footlinks,

0 commit comments

Comments
 (0)