Skip to content
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

Introduce help context #1484

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
de8d7a6
ui: Make the Help hotkey suggestion in the footer more conventional.
Niloth-p Jul 10, 2024
9fccce3
refactor: ui/core/boxes: Separate out function to reset footer text.
Niloth-p Jul 15, 2024
13410a2
refactor: ui/core: Separate footer events from set_footer_text().
Niloth-p Jul 15, 2024
b9b5ee8
ui: Add state variable to track live footer events.
Niloth-p Jul 15, 2024
af00b47
lint-hotkeys: Handle the doc file does not exist exception.
Niloth-p Jul 15, 2024
d2e0c17
refactor: lint-hotkeys: Remove the write_hotkeys_file() function.
Niloth-p Jul 15, 2024
4e8783c
refactor: lint-hotkeys: Make int error flag boolean & use SystemExit.
Niloth-p Jul 15, 2024
e954870
lint-hotkeys: Rewrite function docstrings and comments.
Niloth-p Jul 15, 2024
4ed23c7
refactor: lint-hotkeys: Rename get_hotkeys_file_string().
Niloth-p Jul 15, 2024
9717776
refactor: lint-hotkeys: Rename ambiguous keyword "action" to "batch".
Niloth-p Jul 15, 2024
11a7ead
refactor: lint-hotkeys: Improve variable naming of generated dict.
Niloth-p Jul 17, 2024
3237251
lint-hotkeys: Refactor the flow by creating new ENTRY_BY_CATEGORIES.
Niloth-p Jul 15, 2024
188bd7f
lint-hotkeys: Delay generation of file string when linting.
Niloth-p Jul 17, 2024
0dd8aa4
refactor: lint-hotkeys: Split out the help text linting function.
Niloth-p Jul 17, 2024
5286488
refactor: lint-hotkeys: Split out the function that lints categories.
Niloth-p Jul 17, 2024
4e7a4f2
lint-hotkeys: Restructure the error messages of lint_help_text().
Niloth-p Jul 17, 2024
efc8f82
lint-hotkeys: Lint for typos in key_category values.
Niloth-p Jul 17, 2024
ac8e715
refactor: lint-hotkeys: Use help_group instead of HELP_CATEGORIES.
Niloth-p Jul 17, 2024
58ec337
refactor: lint-hotkeys: Create generic variable entries_by_group.
Niloth-p Jul 17, 2024
3ce52db
refactor: lint-hotkeys: Create generic variables for key_category.
Niloth-p Jul 17, 2024
4911685
refactor: lint-hotkeys: Replace 'category(ies)' with 'group(s)'.
Niloth-p Jul 17, 2024
b35e0ce
refactor: lint-hotkeys: Delete constant OUTPUT_FILE_NAME, compute it.
Niloth-p Jul 17, 2024
001814b
refactor: lint-hotkeys: Replace usage of OUTPUT_FILE.
Niloth-p Jul 17, 2024
e2c7e57
refactor: lint-hotkeys: Generalize the traversal of key group values.
Niloth-p Jul 17, 2024
f908dc6
refactor: lint-hotkeys: Use bundled group values.
Niloth-p Jul 18, 2024
f5d0bc4
keys: Add a contexts field to Key Binding.
Niloth-p Jul 8, 2024
a8dd4de
lint-hotkeys: Add argument to generate a keys file grouped by contexts.
Niloth-p Jul 18, 2024
a76da7f
keys: Use the help contexts in generating random help tips.
Niloth-p Jul 8, 2024
9c48eb7
keys: Include previously excluded random help hints.
Niloth-p Apr 16, 2024
2e1b0f0
ui: Enable footer texts to display contextual help tips.
Niloth-p Jul 16, 2024
1b6ad6b
ui/keys: Display the context of the footer hint.
Niloth-p Jul 10, 2024
f75a309
contexts/core/ui: Track the currently focused widget in the UI.
Niloth-p Jul 11, 2024
58b1a96
core/ui/views/keys: Add a Contextual Help Menu.
Niloth-p Jul 10, 2024
3513d73
keys/views: Add mapping of contexts to broader contexts they belong to.
Niloth-p Jul 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions tests/config/test_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,20 @@ def test_is_command_key_invalid_command(invalid_command: str) -> None:

def test_HELP_is_not_allowed_as_tip() -> None:
assert keys.KEY_BINDINGS["HELP"]["excluded_from_random_tips"] is True
assert keys.KEY_BINDINGS["HELP"] not in keys.commands_for_random_tips()
commands, _ = keys.commands_for_random_tips()
assert keys.KEY_BINDINGS["HELP"] not in commands


@pytest.mark.parametrize(
"context, expected_command",
"context, expected_command, expected_context",
[
(None, "GAMMA"),
("context_1", "BETA"),
("context_2", "GAMMA"),
(None, "GAMMA", "Global"),
("context_1", "BETA", "Context 1"),
("context_2", "GAMMA", "Global"),
],
)
def test_commands_for_random_tips(
context: str, expected_command: str, mocker: MockerFixture
context: str, expected_command: str, expected_context: str, mocker: MockerFixture
) -> None:
new_key_bindings: Dict[str, keys.KeyBinding] = {
"ALPHA": {
Expand Down Expand Up @@ -117,9 +118,10 @@ def test_commands_for_random_tips(
}
mocker.patch.dict(keys.KEY_BINDINGS, new_key_bindings, clear=True)
mocker.patch.object(keys, "HELP_CONTEXTS", new_help_contexts)
result = keys.commands_for_random_tips(context)
assert len(result) == 1
assert new_key_bindings[expected_command] in result
commands, context_display_name = keys.commands_for_random_tips(context)
assert len(commands) == 1
assert new_key_bindings[expected_command] in commands
assert context_display_name == expected_context


def test_updated_urwid_command_map() -> None:
Expand Down
10 changes: 6 additions & 4 deletions zulipterminal/config/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Keybindings and their helper functions
"""

from typing import Dict, List
from typing import Dict, List, Tuple

from typing_extensions import NotRequired, TypedDict
from urwid.command_map import (
Expand Down Expand Up @@ -650,9 +650,10 @@ def primary_display_key_for_command(command: str) -> str:
return display_key_for_urwid_key(primary_key_for_command(command))


def commands_for_random_tips(context: str = "") -> List[KeyBinding]:
def commands_for_random_tips(context: str = "") -> Tuple[List[KeyBinding], str]:
"""
Return list of commands which may be displayed as a random tip
Return list of commands which may be displayed as a random tip,
and their associated user-facing context name
"""
if not context or context not in HELP_CONTEXTS:
context = "global"
Expand All @@ -664,7 +665,8 @@ def commands_for_random_tips(context: str = "") -> List[KeyBinding]:
]
if len(random_tips) == 0:
return commands_for_random_tips("global")
return random_tips
context_display_name = HELP_CONTEXTS.get(context, "Global")
return random_tips, context_display_name


# Refer urwid/command_map.py
Expand Down
8 changes: 6 additions & 2 deletions zulipterminal/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def right_column_view(self) -> Any:

def get_random_help(self) -> List[Any]:
# Get random allowed hotkey (ie. eligible for being displayed as a tip)
allowed_commands = commands_for_random_tips(self.context)
allowed_commands, tip_context = commands_for_random_tips(self.context)
if not allowed_commands:
return ["Help[?] "]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideas on how we can further highlight the differentation of the Help and its hotkey from the random hint are welcome.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest a space in the first instance? Then it'd be similar to eg. the Search [<key>] formatting we have right now. My other concern when running it is that we end up with

Help[?]  OTHERKEY, KEY  HELP TEXT FOR HINT

In that, the hint looks as close to the hint description as to the help hint, so we could add an extra space?

However, without that latter extra space, I'd still consider it an improvement, since the : is confusing by suggesting the Help is the hint, I think?

In the longer-term I mentioned highlighting hotkeys consistently, which might help here, but that's beyond the remit of this commit I think :)

random_command = random.choice(allowed_commands)
Expand All @@ -114,7 +114,11 @@ def get_random_help(self) -> List[Any]:
return [
"Help[?] ",
("footer_contrast", f" {random_command_display_keys} "),
f" {random_command['help_text']}",
f" ({tip_context}) ",
(
"footer_contrast",
f" {random_command['help_text']} ",
),
Comment on lines 116 to +121
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shows the information quite well at this stage 👍

Later, I can see we'll want to iterate on the layout - there's a similar issue as with the Help [?] point, but also that the context/keys/descriptions 'bounce around' spacing-wise.

]

@asynch
Expand Down