Skip to content

Commit 49d3fa5

Browse files
preetmishraneiljp
authored andcommitted
core/ui/views/keys/README: Show new AboutView on ABOUT keypress.
This introduces a minimal AboutView to show metadata about the app. For now, the popup shows ZT_VERSION (the running version of Zulip Terminal) under an 'Application' category. Tests added.
1 parent cf17759 commit 49d3fa5

File tree

6 files changed

+63
-4
lines changed

6 files changed

+63
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ source ~/.zshenv
114114
| Command | Key Combination |
115115
| ----------------------------------------------------- | --------------------------------------------- |
116116
| Show/hide help menu | <kbd>?</kbd> |
117+
| Show/hide about menu | <kbd>Meta</kbd> + <kbd>?</kbd> |
117118
| Go back | <kbd>esc</kbd> |
118119
| Redraw screen | <kbd>Ctrl</kbd> + <kbd>l</kbd> |
119120
| Quit | <kbd>Ctrl</kbd> + <kbd>C</kbd> |

tests/ui/test_ui_tools.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
StreamButton, TopButton, TopicButton, UserButton,
1414
)
1515
from zulipterminal.ui_tools.views import (
16-
HelpView, LeftColumnView, MessageView, MiddleColumnView, ModListWalker,
17-
MsgInfoView, PopUpConfirmationView, PopUpView, RightColumnView,
18-
StreamInfoView, StreamsView, TopicsView, UsersView,
16+
AboutView, HelpView, LeftColumnView, MessageView, MiddleColumnView,
17+
ModListWalker, MsgInfoView, PopUpConfirmationView, PopUpView,
18+
RightColumnView, StreamInfoView, StreamsView, TopicsView, UsersView,
1919
)
2020

2121

@@ -1239,6 +1239,38 @@ def test_keypress_navigation(self, mocker,
12391239
super_keypress.assert_called_once_with(size, expected_key)
12401240

12411241

1242+
class TestAboutView:
1243+
@pytest.fixture(autouse=True)
1244+
def mock_external_classes(self, mocker):
1245+
self.controller = mocker.Mock()
1246+
mocker.patch.object(self.controller, 'maximum_popup_dimensions',
1247+
return_value=(64, 64))
1248+
mocker.patch(VIEWS + '.urwid.SimpleFocusListWalker', return_value=[])
1249+
self.about_view = AboutView(self.controller, 'About',
1250+
zt_version='0.5.1+git')
1251+
1252+
@pytest.mark.parametrize('key', {*keys_for_command('GO_BACK'),
1253+
*keys_for_command('ABOUT')})
1254+
def test_keypress_exit_popup(self, key):
1255+
size = (200, 20)
1256+
self.about_view.keypress(size, key)
1257+
assert self.controller.exit_popup.called
1258+
1259+
def test_keypress_exit_popup_invalid_key(self):
1260+
key = 'a'
1261+
size = (200, 20)
1262+
self.about_view.keypress(size, key)
1263+
assert not self.controller.exit_popup.called
1264+
1265+
def test_keypress_navigation(self, mocker,
1266+
navigation_key_expected_key_pair):
1267+
key, expected_key = navigation_key_expected_key_pair
1268+
size = (200, 20)
1269+
super_keypress = mocker.patch(VIEWS + '.urwid.ListBox.keypress')
1270+
self.about_view.keypress(size, key)
1271+
super_keypress.assert_called_once_with(size, expected_key)
1272+
1273+
12421274
class TestPopUpConfirmationView:
12431275
@pytest.fixture
12441276
def popup_view(self, mocker, stream_button):

zulipterminal/config/keys.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
'excluded_from_random_tips': True,
1919
'key_category': 'general',
2020
}),
21+
('ABOUT', {
22+
'keys': {'meta ?'},
23+
'help_text': 'Show/hide about menu',
24+
'key_category': 'general',
25+
}),
2126
('GO_BACK', {
2227
'keys': {'esc'},
2328
'help_text': 'Go Back',

zulipterminal/core.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
from zulipterminal.ui import Screen, View
1616
from zulipterminal.ui_tools.utils import create_msg_box_list
1717
from zulipterminal.ui_tools.views import (
18-
HelpView, MsgInfoView, NoticeView, PopUpConfirmationView, StreamInfoView,
18+
AboutView, HelpView, MsgInfoView, NoticeView, PopUpConfirmationView,
19+
StreamInfoView,
1920
)
2021
from zulipterminal.version import ZT_VERSION
2122

@@ -146,6 +147,9 @@ def show_stream_info(self, color: str, name: str, desc: str) -> None:
146147
def popup_with_message(self, text: str, width: int) -> None:
147148
self.show_pop_up(NoticeView(self, text, width, "NOTICE"))
148149

150+
def show_about(self) -> None:
151+
self.show_pop_up(AboutView(self, 'About', zt_version=ZT_VERSION))
152+
149153
def search_messages(self, text: str) -> None:
150154
# Search for a text in messages
151155
self.model.index['search'].clear()

zulipterminal/ui.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ def keypress(self, size: Tuple[int, int], key: str) -> Optional[str]:
188188
search_box.set_edit_text("")
189189
self.controller.enter_editor_mode_with(search_box)
190190
return key
191+
elif is_command_key('ABOUT', key):
192+
self.controller.show_about()
193+
return key
191194
elif is_command_key('HELP', key):
192195
# Show help menu
193196
self.controller.show_help()

zulipterminal/ui_tools/views.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,20 @@ def __init__(self, controller: Any,
878878
super().__init__(controller, widgets, 'GO_BACK', width, title)
879879

880880

881+
class AboutView(PopUpView):
882+
def __init__(self, controller: Any, title: str, *,
883+
zt_version: str) -> None:
884+
contents = [
885+
('Application', [('Zulip Terminal', zt_version)]),
886+
]
887+
888+
popup_width, column_widths = self.calculate_table_widths(contents,
889+
len(title))
890+
widgets = self.make_table_with_categories(contents, column_widths)
891+
892+
super().__init__(controller, widgets, 'ABOUT', popup_width, title)
893+
894+
881895
class HelpView(PopUpView):
882896
def __init__(self, controller: Any, title: str) -> None:
883897
help_menu_content = []

0 commit comments

Comments
 (0)