Skip to content

Commit

Permalink
run: Check sync of readline shortcuts with urwid_readline's keymap.
Browse files Browse the repository at this point in the history
Lint exclusions updated.
  • Loading branch information
Niloth-p committed Jun 13, 2024
1 parent 514db27 commit fa92511
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions tools/lint-hotkeys
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ KEYS_TO_EXCLUDE = ["q", "e", "m", "r"]
EXCLUDED_FILES = [
KEYS_FILE,
ZULIPTERMINAL / "config" / "regexes.py",
ZULIPTERMINAL / "cli" / "run.py",
]


Expand Down
41 changes: 41 additions & 0 deletions zulipterminal/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@

import requests
from urwid import display_common, set_encoding
from urwid_readline import ReadlineEdit

from zulipterminal.api_types import ServerSettings
from zulipterminal.config.keys import KEY_BINDINGS, READLINE_SUFFIX
from zulipterminal.config.themes import (
ThemeError,
aliased_themes,
Expand Down Expand Up @@ -392,6 +394,34 @@ def list_themes() -> str:
)


class ReadlineShortcutError(Exception):
pass


def check_readline_shortcuts_availability() -> None:
readline_edit = ReadlineEdit()
commands_to_exclude = ["PREV_LINE" + READLINE_SUFFIX, "NEXT_LINE" + READLINE_SUFFIX]
filtered_commands = [
command
for command in KEY_BINDINGS
if command.endswith(READLINE_SUFFIX) and command not in commands_to_exclude
]

missing_keys = []
for command in filtered_commands:
for key in KEY_BINDINGS[command]["keys"]:
if key not in readline_edit.keymap:
key_missing_error = (
f'Key "{key}" for command "{KEY_BINDINGS[command]["help_text"]}" '
f"is not found."
)
missing_keys.append(key_missing_error)

if missing_keys:
error_message = "\n".join(missing_keys)
raise ReadlineShortcutError(error_message)


def main(options: Optional[List[str]] = None) -> None:
"""
Launch Zulip Terminal.
Expand Down Expand Up @@ -566,6 +596,17 @@ def print_setting(setting: str, data: SettingData, suffix: str = "") -> None:
for setting, valid_boolean_values in VALID_BOOLEAN_SETTINGS.items():
boolean_settings[setting] = zterm[setting].value == valid_boolean_values[0]

try:
check_readline_shortcuts_availability()
except ReadlineShortcutError as e:
print(
"\nThe following readline shortcuts "
+ "are missing in urwid_readline's keymap.\n"
+ str(e)
+ "\n",
file=sys.stderr,
)

Controller(
config_file=zuliprc_path,
maximum_footlinks=maximum_footlinks,
Expand Down

0 comments on commit fa92511

Please sign in to comment.