|
15 | 15 |
|
16 | 16 | import requests
|
17 | 17 | from urwid import display_common, set_encoding
|
| 18 | +from urwid_readline import ReadlineEdit |
18 | 19 |
|
19 | 20 | from zulipterminal.api_types import ServerSettings
|
| 21 | +from zulipterminal.config.keys import KEY_BINDINGS, READLINE_SUFFIX |
20 | 22 | from zulipterminal.config.themes import (
|
21 | 23 | ThemeError,
|
22 | 24 | aliased_themes,
|
@@ -392,6 +394,34 @@ def list_themes() -> str:
|
392 | 394 | )
|
393 | 395 |
|
394 | 396 |
|
| 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 | + |
395 | 425 | def main(options: Optional[List[str]] = None) -> None:
|
396 | 426 | """
|
397 | 427 | Launch Zulip Terminal.
|
@@ -566,6 +596,17 @@ def print_setting(setting: str, data: SettingData, suffix: str = "") -> None:
|
566 | 596 | for setting, valid_boolean_values in VALID_BOOLEAN_SETTINGS.items():
|
567 | 597 | boolean_settings[setting] = zterm[setting].value == valid_boolean_values[0]
|
568 | 598 |
|
| 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 | + |
569 | 610 | Controller(
|
570 | 611 | config_file=zuliprc_path,
|
571 | 612 | maximum_footlinks=maximum_footlinks,
|
|
0 commit comments