-
-
Notifications
You must be signed in to change notification settings - Fork 278
Improve hotkey rendering in documentation #1479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
b682d2f
68fc6e3
e523a11
3897db4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,12 @@ from collections import defaultdict | |
from pathlib import Path, PurePath | ||
from typing import Dict, List, Tuple | ||
|
||
from zulipterminal.config.keys import HELP_CATEGORIES, KEY_BINDINGS | ||
from zulipterminal.config.keys import ( | ||
HELP_CATEGORIES, | ||
KEY_BINDINGS, | ||
display_keys_for_command, | ||
) | ||
from zulipterminal.config.symbols import ARROW_SYMBOLS | ||
|
||
|
||
KEYS_FILE = ( | ||
|
@@ -69,7 +74,9 @@ def lint_hotkeys_file() -> None: | |
else: | ||
print("No hotkeys linting errors") | ||
if not output_file_matches_string(hotkeys_file_string): | ||
print(f"Run './tools/{SCRIPT_NAME}' to update {OUTPUT_FILE_NAME} file") | ||
print( | ||
f"Run './tools/{SCRIPT_NAME} --fix' to update {OUTPUT_FILE_NAME} file" | ||
) | ||
error_flag = 1 | ||
sys.exit(error_flag) | ||
|
||
|
@@ -85,6 +92,27 @@ def generate_hotkeys_file() -> None: | |
print(f"Hot Keys list saved in {OUTPUT_FILE}") | ||
|
||
|
||
def format_key(key: str) -> str: | ||
""" | ||
Format each key of a hotkey combination for display | ||
""" | ||
if len(key) == 1: | ||
if key.isupper(): | ||
return f"<kbd>Shift</kbd> + <kbd>{key}</kbd>" | ||
return f"<kbd>{key.capitalize()}</kbd>" | ||
return f"<kbd>{key}</kbd>" | ||
|
||
|
||
def format_key_combination(key_combination: str) -> str: | ||
""" | ||
Format a hotkey combination for display | ||
""" | ||
for symbol in ARROW_SYMBOLS: | ||
if symbol in key_combination: | ||
return f"<kbd>{key_combination}</kbd>" | ||
return " + ".join([format_key(key) for key in key_combination.split()]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just added for an alternative option. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Re the point about the arrow keys, again let's keep that for building later. One issue here is how we're defining what a 'key' is for various purposes, ie. surrounding by |
||
|
||
|
||
def get_hotkeys_file_string() -> str: | ||
""" | ||
Construct string in form for output to OUTPUT_FILE based on help text | ||
|
@@ -104,7 +132,7 @@ def get_hotkeys_file_string() -> str: | |
for help_text, key_combinations_list in categories[action]: | ||
various_key_combinations = " / ".join( | ||
[ | ||
" + ".join([f"<kbd>{key}</kbd>" for key in key_combination.split()]) | ||
format_key_combination(key_combination) | ||
for key_combination in key_combinations_list | ||
] | ||
) | ||
|
@@ -114,6 +142,10 @@ def get_hotkeys_file_string() -> str: | |
|
||
|
||
def output_file_matches_string(hotkeys_file_string: str) -> bool: | ||
""" | ||
Read the existing OUTPUT_FILE into a string, | ||
and compare if it matches the input string | ||
""" | ||
neiljp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
with open(OUTPUT_FILE) as output_file: | ||
content_is_identical = hotkeys_file_string == output_file.read() | ||
if content_is_identical: | ||
|
@@ -129,8 +161,10 @@ def read_help_categories() -> Dict[str, List[Tuple[str, List[str]]]]: | |
Get all help categories from KEYS_FILE | ||
""" | ||
categories = defaultdict(list) | ||
for item in KEY_BINDINGS.values(): | ||
categories[item["key_category"]].append((item["help_text"], item["keys"])) | ||
for cmd, item in KEY_BINDINGS.items(): | ||
categories[item["key_category"]].append( | ||
(item["help_text"], display_keys_for_command(cmd)) | ||
) | ||
return categories | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,3 +86,9 @@ | |
bline=_MESSAGE_RECIPIENTS_BOTTOM, | ||
brcorner=_MESSAGE_RECIPIENTS_BOTTOM, | ||
) | ||
|
||
LEFT_ARROW = "←" # LEFTWARDS ARROW, U+2190 | ||
UP_ARROW = "↑" # UPWARDS ARROW, U+2191 | ||
RIGHT_ARROW = "→" # RIGHTWARDS ARROW, U+2192 | ||
DOWN_ARROW = "↓" # DOWNWARDS ARROW, U+2193 | ||
Comment on lines
+90
to
+93
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm inclined to keep this change as something that we choose to do universally, rather than only in the hotkeys doc. We'll definitely want a space between the text and symbols if we do this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Just to clarify, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My main point was that we'll likely want to leave the symbol change to a different PR since I'm not sure we want it only in the docs. Specific symbols can be a separate discussion too - I recall some from the original PR weren't that clear. Then, with the original changes you made I noticed that there wasn't a space, so for that future work the second comment I made was to indicate that we'll want a space if/when we do that. |
||
ARROW_SYMBOLS = [LEFT_ARROW, UP_ARROW, RIGHT_ARROW, DOWN_ARROW] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For convenient use in lint-hotkeys to check if the key_combination contains any of the arrow keys. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
from typing_extensions import Literal | ||
|
||
from zulipterminal.api_types import Composition, Message | ||
from zulipterminal.config.keys import primary_display_key_for_command | ||
from zulipterminal.config.symbols import POPUP_CONTENT_BORDER, POPUP_TOP_LINE | ||
from zulipterminal.config.themes import ThemeSpec | ||
from zulipterminal.config.ui_sizes import ( | ||
|
@@ -51,6 +52,14 @@ | |
|
||
ExceptionInfo = Tuple[Type[BaseException], BaseException, TracebackType] | ||
|
||
SCROLL_PROMPT = ( | ||
"(" | ||
+ primary_display_key_for_command("GO_UP") | ||
+ " / " | ||
+ primary_display_key_for_command("GO_DOWN") | ||
+ " scrolls)" | ||
) | ||
|
||
|
||
class Controller: | ||
""" | ||
|
@@ -246,11 +255,11 @@ def exit_popup(self) -> None: | |
self.loop.widget = self.view | ||
|
||
def show_help(self) -> None: | ||
help_view = HelpView(self, "Help Menu (up/down scrolls)") | ||
help_view = HelpView(self, f"Help Menu {SCROLL_PROMPT}") | ||
self.show_pop_up(help_view, "area:help") | ||
|
||
def show_markdown_help(self) -> None: | ||
markdown_view = MarkdownHelpView(self, "Markdown Help Menu (up/down scrolls)") | ||
markdown_view = MarkdownHelpView(self, "Markdown Help Menu " + SCROLL_PROMPT) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improvements and bugfixes to the doc/linting are fine in a related PR, but this commit looks like a different overall change - useful for consistency as it is 👍 You should be able to cherry-pick it into another branch just fine. I've not tested this yet, but you updated the formatting of other lines but not this one? This also prompts thoughts on ensuring we're consistent with naming of the menu titles and their names in the descriptions of the related hotkeys, which I've not checked recently, and I'm not sure if it's worth checking technically, or manually. |
||
self.show_pop_up(markdown_view, "area:help") | ||
|
||
def show_topic_edit_mode(self, button: Any) -> None: | ||
|
@@ -266,7 +275,7 @@ def show_msg_info( | |
msg_info_view = MsgInfoView( | ||
self, | ||
msg, | ||
"Message Information (up/down scrolls)", | ||
f"Message Information {SCROLL_PROMPT}", | ||
topic_links, | ||
message_links, | ||
time_mentions, | ||
|
@@ -315,7 +324,10 @@ def show_about(self) -> None: | |
def show_user_info(self, user_id: int) -> None: | ||
self.show_pop_up( | ||
UserInfoView( | ||
self, user_id, "User Information (up/down scrolls)", "USER_INFO" | ||
self, | ||
user_id, | ||
f"User Information {SCROLL_PROMPT}", | ||
"USER_INFO", | ||
), | ||
"area:user", | ||
) | ||
|
@@ -325,7 +337,7 @@ def show_msg_sender_info(self, user_id: int) -> None: | |
UserInfoView( | ||
self, | ||
user_id, | ||
"Message Sender Information (up/down scrolls)", | ||
f"Message Sender Information {SCROLL_PROMPT}", | ||
"MSG_SENDER_INFO", | ||
), | ||
"area:user", | ||
|
@@ -345,7 +357,7 @@ def show_full_rendered_message( | |
topic_links, | ||
message_links, | ||
time_mentions, | ||
"Full rendered message (up/down scrolls)", | ||
f"Full rendered message {SCROLL_PROMPT}", | ||
), | ||
"area:msg", | ||
) | ||
|
@@ -364,7 +376,7 @@ def show_full_raw_message( | |
topic_links, | ||
message_links, | ||
time_mentions, | ||
"Full raw message (up/down scrolls)", | ||
f"Full raw message {SCROLL_PROMPT}", | ||
), | ||
"area:msg", | ||
) | ||
|
@@ -383,7 +395,7 @@ def show_edit_history( | |
topic_links, | ||
message_links, | ||
time_mentions, | ||
"Edit History (up/down scrolls)", | ||
f"Edit History {SCROLL_PROMPT}", | ||
), | ||
"area:msg", | ||
) | ||
|
Uh oh!
There was an error while loading. Please reload this page.