Skip to content

Commit b55adac

Browse files
committed
tools: Automate generation of Hot Keys section.
Generates markdown file hotkeys.md using `KEY_BINDINGS` and `HELP_CATEGORIES` from `keys.py`. This ensures that changes to command keys are reflected automatically in the documentation when the user runs the `generate_hotkeys.py` script. Fixes #126.
1 parent 640d669 commit b55adac

File tree

2 files changed

+124
-84
lines changed

2 files changed

+124
-84
lines changed

docs/hotkeys.md

Lines changed: 88 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,93 @@
1-
## Hot Keys
2-
### General
3-
| Command | Key Combination |
4-
| ----------------------------------------------------- | --------------------------------------------- |
5-
| Show/hide help menu | <kbd>?</kbd> |
6-
| Show/hide about menu | <kbd>Meta</kbd> + <kbd>?</kbd> |
7-
| Go back | <kbd>esc</kbd> |
8-
| Open draft message saved in this session | <kbd>d</kbd> |
9-
| Redraw screen | <kbd>Ctrl</kbd> + <kbd>l</kbd> |
10-
| Quit | <kbd>Ctrl</kbd> + <kbd>C</kbd> |
1+
<!--- Generated automatically by tools/generate_hotkeys.py -->
2+
<!--- Do not modify -->
113

12-
### Navigation
13-
| Command | Key Combination |
14-
| ----------------------------------------------------- | --------------------------------------------- |
15-
| Previous message | <kbd>Up</kbd> / <kbd>k</kbd> |
16-
| Next message | <kbd>Down</kbd> / <kbd>j</kbd> |
17-
| Go left | <kbd>left</kbd> / <kbd>h</kbd> |
18-
| Go right | <kbd>right</kbd> / <kbd>l</kbd> |
19-
| Scroll up | <kbd>PgUp</kbd> / <kbd>K</kbd> |
20-
| Scroll down | <kbd>PgDn</kbd> / <kbd>J</kbd> |
21-
| Go to the last message | <kbd>G</kbd> / <kbd>end</kbd> |
22-
| Narrow to all messages | <kbd>a</kbd> / <kbd>esc</kbd> |
23-
| Narrow to all private messages | <kbd>P</kbd> |
24-
| Narrow to all starred messages | <kbd>f</kbd> |
25-
| Narrow to messages in which you're mentioned | <kbd>#</kbd> |
26-
| Next unread topic | <kbd>n</kbd> |
27-
| Next unread private message | <kbd>p</kbd> |
4+
# Hot Keys
5+
## General
6+
|Command|Key Combination|
7+
| :--- | :---: |
8+
|Show/hide help menu|<kbd>?</kbd>|
9+
|Show/hide about menu|<kbd>meta</kbd> + <kbd>?</kbd>|
10+
|Go Back|<kbd>esc</kbd>|
11+
|Open draft message saved in this session|<kbd>d</kbd>|
12+
|Redraw screen|<kbd>ctrl</kbd> + <kbd>l</kbd>|
13+
|Quit|<kbd>ctrl</kbd> + <kbd>c</kbd>|
2814

29-
### Searching
30-
| Command | Key Combination |
31-
| ----------------------------------------------------- | --------------------------------------------- |
32-
| Search users | <kbd>w</kbd> |
33-
| Search messages | <kbd>/</kbd> |
34-
| Search streams | <kbd>q</kbd> |
35-
| Search topics in a stream | <kbd>q</kbd> |
15+
## Navigation
16+
|Command|Key Combination|
17+
| :--- | :---: |
18+
|Previous message|<kbd>Up</kbd> / <kbd>k</kbd>|
19+
|Next message|<kbd>Down</kbd> / <kbd>j</kbd>|
20+
|Go left|<kbd>Left</kbd> / <kbd>h</kbd>|
21+
|Go right|<kbd>Right</kbd> / <kbd>l</kbd>|
22+
|Scroll up|<kbd>PgUp</kbd> / <kbd>K</kbd>|
23+
|Scroll down|<kbd>PgDn</kbd> / <kbd>J</kbd>|
24+
|Go to the last message|<kbd>G</kbd> / <kbd>end</kbd>|
25+
|Narrow to all messages|<kbd>a</kbd> / <kbd>esc</kbd>|
26+
|Narrow to all private messages|<kbd>P</kbd>|
27+
|Narrow to all starred messages|<kbd>f</kbd>|
28+
|Narrow to messages in which you're mentioned|<kbd>#</kbd>|
29+
|Next unread topic|<kbd>n</kbd>|
30+
|Next unread private message|<kbd>p</kbd>|
31+
|Perform current action|<kbd>enter</kbd>|
3632

37-
### Message actions
38-
| Command | Key Combination |
39-
| ----------------------------------------------------- | --------------------------------------------- |
40-
| Reply to the current message | <kbd>r</kbd> |
41-
| Reply mentioning the sender of the current message | <kbd>@</kbd> |
42-
| Reply quoting the current message text | <kbd>></kbd> |
43-
| Reply privately to the sender of the current message | <kbd>R</kbd> |
44-
| Edit a sent message | <kbd>e</kbd> |
45-
| New message to a stream | <kbd>c</kbd> |
46-
| New message to a person or group of people | <kbd>x</kbd> |
47-
| Narrow to the stream of the current message | <kbd>s</kbd> |
48-
| Narrow to the topic of the current message | <kbd>S</kbd> |
49-
| Narrow to a topic/private-chat, or stream/all-private-messages| <kbd>z</kbd> |
50-
| Add/remove thumbs-up reaction to the current message | <kbd>+</kbd> |
51-
| Add/remove star status of the current message | <kbd>*</kbd> |
52-
| Show/hide message information | <kbd>i</kbd> |
53-
| Show/hide edit history (from message information) | <kbd>e</kbd> |
33+
## Searching
34+
|Command|Key Combination|
35+
| :--- | :---: |
36+
|Search users|<kbd>w</kbd>|
37+
|Search Messages|<kbd>/</kbd>|
38+
|Search Streams|<kbd>q</kbd>|
39+
|Search topics in a stream|<kbd>q</kbd>|
5440

55-
### Stream list actions
56-
| Command | Key Combination |
57-
| ----------------------------------------------------- | --------------------------------------------- |
58-
| Toggle topics in a stream | <kbd>t</kbd> |
59-
| Mute/unmute Streams | <kbd>m</kbd> |
60-
| Show/hide stream information & modify settings | <kbd>i</kbd> |
61-
| Show/hide stream members (from stream information) | <kbd>m</kbd> |
41+
## Message actions
42+
|Command|Key Combination|
43+
| :--- | :---: |
44+
|Reply to the current message|<kbd>r</kbd> / <kbd>enter</kbd>|
45+
|Reply mentioning the sender of the current message|<kbd>@</kbd>|
46+
|Reply quoting the current message text|<kbd>></kbd>|
47+
|Reply privately to the sender of the current message|<kbd>R</kbd>|
48+
|Edit a sent message|<kbd>e</kbd>|
49+
|New message to a stream|<kbd>c</kbd>|
50+
|New message to a person or group of people|<kbd>x</kbd>|
51+
|Narrow to the stream of the current message|<kbd>s</kbd>|
52+
|Narrow to the topic of the current message|<kbd>S</kbd>|
53+
|Narrow to a topic/private-chat, or stream/all-private-messages|<kbd>z</kbd>|
54+
|Add/remove thumbs-up reaction to the current message|<kbd>+</kbd>|
55+
|Add/remove star status of the current message|<kbd>ctrl</kbd> + <kbd>s</kbd> / <kbd>*</kbd>|
56+
|Show/hide message information|<kbd>i</kbd>|
57+
|Show/hide edit history (from message information)|<kbd>e</kbd>|
58+
59+
## Stream list actions
60+
|Command|Key Combination|
61+
| :--- | :---: |
62+
|Toggle topics in a stream|<kbd>t</kbd>|
63+
|Mute/unmute Streams|<kbd>m</kbd>|
64+
|Show/hide stream information & modify settings|<kbd>i</kbd>|
65+
|Show/hide stream members (from stream information)|<kbd>m</kbd>|
66+
67+
## Composing a Message
68+
|Command|Key Combination|
69+
| :--- | :---: |
70+
|Cycle through recipient and content boxes|<kbd>tab</kbd>|
71+
|Send a message|<kbd>ctrl</kbd> + <kbd>d</kbd> / <kbd>meta</kbd> + <kbd>enter</kbd>|
72+
|Save current message as a draft|<kbd>meta</kbd> + <kbd>s</kbd>|
73+
|Autocomplete @mentions, #stream_names, :emoji: and topics|<kbd>ctrl</kbd> + <kbd>f</kbd>|
74+
|Cycle through autocomplete suggestions in reverse|<kbd>ctrl</kbd> + <kbd>r</kbd>|
75+
|Jump to the beginning of line|<kbd>ctrl</kbd> + <kbd>A</kbd>|
76+
|Jump to the end of line|<kbd>ctrl</kbd> + <kbd>e</kbd>|
77+
|Jump backward one word|<kbd>meta</kbd> + <kbd>b</kbd>|
78+
|Jump backward one character|<kbd>ctrl</kbd> + <kbd>B</kbd> / <kbd>Left</kbd>|
79+
|Jump forward one character|<kbd>ctrl</kbd> + <kbd>F</kbd> / <kbd>Right</kbd>|
80+
|Jump forward one word|<kbd>meta</kbd> + <kbd>f</kbd>|
81+
|Delete one word|<kbd>meta</kbd> + <kbd>d</kbd>|
82+
|Delete previous character|<kbd>ctrl</kbd> + <kbd>h</kbd>|
83+
|Transpose characters|<kbd>ctrl</kbd> + <kbd>t</kbd>|
84+
|Kill (cut) forwards to the end of the line|<kbd>ctrl</kbd> + <kbd>K</kbd>|
85+
|Kill (cut) backwards to the start of the line|<kbd>ctrl</kbd> + <kbd>u</kbd>|
86+
|Kill (cut) forwards to the end of the current word|<kbd>meta</kbd> + <kbd>d</kbd>|
87+
|Kill (cut) backward to the start of the current word|<kbd>ctrl</kbd> + <kbd>w</kbd>|
88+
|Paste last kill|<kbd>ctrl</kbd> + <kbd>Y</kbd>|
89+
|Undo last action|<kbd>ctrl</kbd> + <kbd>_</kbd>|
90+
|Jump to the previous line|<kbd>ctrl</kbd> + <kbd>P</kbd> / <kbd>Up</kbd>|
91+
|Jump to the next line|<kbd>ctrl</kbd> + <kbd>N</kbd> / <kbd>Down</kbd>|
92+
|Clear compose box|<kbd>ctrl</kbd> + <kbd>L</kbd>|
6293

63-
### Composing a message
64-
| Command | Key Combination |
65-
| ----------------------------------------------------- | --------------------------------------------- |
66-
| Cycle through recipient and content boxes | <kbd>tab</kbd> |
67-
| Send a message | <kbd>Alt Enter</kbd> / <kbd>Ctrl d</kbd> |
68-
| Save current message as a draft | <kbd>Meta</kbd> + <kbd>s</kbd> |
69-
| Autocomplete @mentions, #stream_names, :emoji: and topics | <kbd>Ctrl</kbd> + <kbd>f</kbd> |
70-
| Cycle through autocomplete suggestions in reverse | <kbd>Ctrl</kbd> + <kbd>r</kbd> |
71-
| Jump to the beginning of line | <kbd>Ctrl</kbd> + <kbd>A</kbd> |
72-
| Jump backward one character | <kbd>Ctrl</kbd> + <kbd>B</kbd> / <kbd>←</kbd> |
73-
| Jump backward one word | <kbd>Meta</kbd> + <kbd>B</kbd> |
74-
| Delete one character | <kbd>Ctrl</kbd> + <kbd>D</kbd> |
75-
| Delete one word | <kbd>Meta</kbd> + <kbd>D</kbd> |
76-
| Jump to the end of line | <kbd>Ctrl</kbd> + <kbd>E</kbd> |
77-
| Jump forward one character | <kbd>Ctrl</kbd> + <kbd>F</kbd> / <kbd>→</kbd> |
78-
| Jump forward one word | <kbd>Meta</kbd> + <kbd>F</kbd> |
79-
| Delete previous character | <kbd>Ctrl</kbd> + <kbd>H</kbd> |
80-
| Transpose characters | <kbd>Ctrl</kbd> + <kbd>T</kbd> |
81-
| Kill (cut) forwards to the end of the line | <kbd>Ctrl</kbd> + <kbd>K</kbd> |
82-
| Kill (cut) backwards to the start of the line | <kbd>Ctrl</kbd> + <kbd>U</kbd> |
83-
| Kill (cut) forwards to the end of the current word | <kbd>Meta</kbd> + <kbd>D</kbd> |
84-
| Kill (cut) backwards to the start of the current word | <kbd>Ctrl</kbd> + <kbd>W</kbd> |
85-
| Paste last kill | <kbd>Ctrl</kbd> + <kbd>Y</kbd> |
86-
| Undo last action | <kbd>Ctrl</kbd> + <kbd>_</kbd> |
87-
| Jump to previous line | <kbd>Ctrl</kbd> + <kbd>P</kbd> / <kbd>↑</kbd> |
88-
| Jump to next line | <kbd>Ctrl</kbd> + <kbd>N</kbd> / <kbd>↓</kbd> |
89-
| Clear compose box | <kbd>Ctrl</kbd> + <kbd>L</kbd> |

tools/generate_hotkeys.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python3
2+
from pathlib import Path, PurePath
3+
4+
from zulipterminal.config.keys import HELP_CATEGORIES, KEY_BINDINGS
5+
6+
7+
categories = {
8+
category: {
9+
item['help_text']: item['keys']
10+
for item in KEY_BINDINGS.values()
11+
if item['key_category'] == category
12+
}
13+
for category in HELP_CATEGORIES.keys()
14+
}
15+
OUTPUT_FILE = Path(__file__).resolve().parent.parent / 'docs' / 'hotkeys.md'
16+
SCRIPT_NAME = PurePath(__file__).name
17+
18+
with open(OUTPUT_FILE,"w") as mdFile:
19+
mdFile.write(f"<!--- Generated automatically by tools/{SCRIPT_NAME} -->\n"
20+
"<!--- Do not modify -->\n\n# Hot Keys\n")
21+
for action in categories.keys():
22+
mdFile.write(f"## {HELP_CATEGORIES[action]}\n"
23+
"|Command|Key Combination|\n"
24+
"| :--- | :---: |\n")
25+
for help_text, key_combinations_list in categories[action].items():
26+
various_key_combinations = " / ".join([
27+
" + ".join([
28+
f"<kbd>{key}</kbd>"
29+
for key in key_combination.split()
30+
])
31+
for key_combination in key_combinations_list
32+
])
33+
mdFile.write(f"|{help_text}|{various_key_combinations}|\n")
34+
mdFile.write("\n")
35+
36+
print(f"Hot Keys list saved in {OUTPUT_FILE}")

0 commit comments

Comments
 (0)