From 30f04244fffdd11c08cf7ddbc39e08a9824feee4 Mon Sep 17 00:00:00 2001 From: Swarnim114 Date: Thu, 25 Jul 2024 18:17:23 +0530 Subject: [PATCH 1/4] about_popup: Terminal size added in about popup. Fixes #1536. --- zulipterminal/core.py | 2 ++ zulipterminal/ui_tools/views.py | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/zulipterminal/core.py b/zulipterminal/core.py index a23b1596f1..bfae1a1adc 100644 --- a/zulipterminal/core.py +++ b/zulipterminal/core.py @@ -301,6 +301,7 @@ def popup_with_message(self, text: str, width: int) -> None: self.show_pop_up(NoticeView(self, text, width, "NOTICE"), "area:error") def show_about(self) -> None: + screen = self.loop.screen self.show_pop_up( AboutView( self, @@ -315,6 +316,7 @@ def show_about(self) -> None: maximum_footlinks=self.maximum_footlinks, exit_confirmation_enabled=self.exit_confirmation, transparency_enabled=self.transparency_enabled, + screen=screen, ), "area:help", ) diff --git a/zulipterminal/ui_tools/views.py b/zulipterminal/ui_tools/views.py index 6d01a82566..d5d4ac5dc5 100644 --- a/zulipterminal/ui_tools/views.py +++ b/zulipterminal/ui_tools/views.py @@ -1092,6 +1092,7 @@ def __init__( notify_enabled: bool, exit_confirmation_enabled: bool, transparency_enabled: bool, + screen: urwid.raw_display.Screen, ) -> None: self.feature_level_content = ( [("Feature level", str(server_feature_level))] @@ -1099,6 +1100,8 @@ def __init__( else [] ) + terminal_size = screen.get_cols_rows() + contents = [ ("Application", [("Zulip Terminal", zt_version)]), ("Server", [("Version", server_version)] + self.feature_level_content), @@ -1119,7 +1122,11 @@ def __init__( ), ( "Detected Environment", - [("Platform", PLATFORM), ("Python", detected_python_in_full())], + [ + ("Platform", PLATFORM), + ("Python", detected_python_in_full()), + ("Current terminal size", f"{terminal_size[0]}x{terminal_size[1]}"), + ], ), ] @@ -1137,7 +1144,6 @@ def __init__( popup_width, column_widths = self.calculate_table_widths(contents, len(title)) widgets = self.make_table_with_categories(contents, column_widths) - super().__init__(controller, widgets, "ABOUT", popup_width, title) def keypress(self, size: urwid_Size, key: str) -> str: From 6204d1f1058b437ec3bc9aa5fa28c7af6e025af6 Mon Sep 17 00:00:00 2001 From: Swarnim114 Date: Thu, 25 Jul 2024 22:14:00 +0530 Subject: [PATCH 2/4] about_popup: Modified test_pipups.py to test terminal size. --- tests/ui_tools/test_popups.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/ui_tools/test_popups.py b/tests/ui_tools/test_popups.py index 878be178c4..d05dab04d2 100644 --- a/tests/ui_tools/test_popups.py +++ b/tests/ui_tools/test_popups.py @@ -2,10 +2,12 @@ from typing import Any, Callable, Dict, List, Optional, Tuple import pytest +import urwid from pytest import param as case from pytest_mock import MockerFixture from urwid import Columns, Pile, Text, Widget +from zulipterminal import urwid_types from zulipterminal.api_types import Message from zulipterminal.config.keys import is_command_key, keys_for_command from zulipterminal.config.ui_mappings import EDIT_MODE_CAPTIONS @@ -195,6 +197,10 @@ def mock_external_classes(self, mocker: MockerFixture) -> None: mocker.patch(MODULE + ".detected_python_in_full", lambda: "[Python version]") + + mock_screen = mocker.Mock(spec=urwid.raw_display.Screen) + mock_screen.get_cols_rows.return_value = (80, 24) + self.about_view = AboutView( self.controller, "About", @@ -208,6 +214,7 @@ def mock_external_classes(self, mocker: MockerFixture) -> None: maximum_footlinks=3, exit_confirmation_enabled=False, transparency_enabled=False, + screen=mock_screen, ) @pytest.mark.parametrize( @@ -246,6 +253,9 @@ def test_feature_level_content( mocker.patch(LISTWALKER, return_value=[]) server_version, server_feature_level = zulip_version + mock_screen = mocker.Mock(spec=urwid.raw_display.Screen) + mock_screen.get_cols_rows.return_value = (80, 24) + about_view = AboutView( self.controller, "About", @@ -259,6 +269,7 @@ def test_feature_level_content( maximum_footlinks=3, exit_confirmation_enabled=False, transparency_enabled=False, + screen=mock_screen, ) assert len(about_view.feature_level_content) == ( @@ -299,7 +310,8 @@ def test_copied_content(self) -> None: #### Detected Environment Platform: WSL -Python: [Python version]""" +Python: [Python version] +Current terminal size: 80x24""" assert self.about_view.copy_info == expected_output From 48385e12e9ca1b7bc17b16e42602f1a1c126c77a Mon Sep 17 00:00:00 2001 From: Swarnim114 Date: Fri, 26 Jul 2024 16:57:05 +0530 Subject: [PATCH 3/4] about_popup: Modified Terminal size text for readability. --- tests/ui_tools/test_popups.py | 34 ++++++++++++++++++++------------- zulipterminal/core.py | 4 ++-- zulipterminal/ui_tools/views.py | 15 ++++++++++++--- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/tests/ui_tools/test_popups.py b/tests/ui_tools/test_popups.py index d05dab04d2..5485fdee5e 100644 --- a/tests/ui_tools/test_popups.py +++ b/tests/ui_tools/test_popups.py @@ -2,12 +2,10 @@ from typing import Any, Callable, Dict, List, Optional, Tuple import pytest -import urwid from pytest import param as case from pytest_mock import MockerFixture from urwid import Columns, Pile, Text, Widget -from zulipterminal import urwid_types from zulipterminal.api_types import Message from zulipterminal.config.keys import is_command_key, keys_for_command from zulipterminal.config.ui_mappings import EDIT_MODE_CAPTIONS @@ -197,10 +195,6 @@ def mock_external_classes(self, mocker: MockerFixture) -> None: mocker.patch(MODULE + ".detected_python_in_full", lambda: "[Python version]") - - mock_screen = mocker.Mock(spec=urwid.raw_display.Screen) - mock_screen.get_cols_rows.return_value = (80, 24) - self.about_view = AboutView( self.controller, "About", @@ -214,7 +208,7 @@ def mock_external_classes(self, mocker: MockerFixture) -> None: maximum_footlinks=3, exit_confirmation_enabled=False, transparency_enabled=False, - screen=mock_screen, + terminal_size=(80, 24), ) @pytest.mark.parametrize( @@ -253,9 +247,6 @@ def test_feature_level_content( mocker.patch(LISTWALKER, return_value=[]) server_version, server_feature_level = zulip_version - mock_screen = mocker.Mock(spec=urwid.raw_display.Screen) - mock_screen.get_cols_rows.return_value = (80, 24) - about_view = AboutView( self.controller, "About", @@ -269,14 +260,31 @@ def test_feature_level_content( maximum_footlinks=3, exit_confirmation_enabled=False, transparency_enabled=False, - screen=mock_screen, + terminal_size=(80, 24), ) assert len(about_view.feature_level_content) == ( 1 if server_feature_level else 0 ) - def test_categories(self) -> None: + def test_categories(self, mocker: MockerFixture) -> None: + mocker.Mock() + self.about_view = AboutView( + self.controller, + "About", + zt_version=ZT_VERSION, + server_version=MINIMUM_SUPPORTED_SERVER_VERSION[0], + server_feature_level=MINIMUM_SUPPORTED_SERVER_VERSION[1], + theme_name="zt_dark", + color_depth=256, + notify_enabled=False, + autohide_enabled=False, + maximum_footlinks=3, + exit_confirmation_enabled=False, + transparency_enabled=False, + terminal_size=(80, 24), + ) + categories = [ widget.text for widget in self.about_view.log @@ -311,7 +319,7 @@ def test_copied_content(self) -> None: #### Detected Environment Platform: WSL Python: [Python version] -Current terminal size: 80x24""" +Current terminal size: 80 columns x 24 rows""" assert self.about_view.copy_info == expected_output diff --git a/zulipterminal/core.py b/zulipterminal/core.py index bfae1a1adc..592c4cf25b 100644 --- a/zulipterminal/core.py +++ b/zulipterminal/core.py @@ -301,7 +301,7 @@ def popup_with_message(self, text: str, width: int) -> None: self.show_pop_up(NoticeView(self, text, width, "NOTICE"), "area:error") def show_about(self) -> None: - screen = self.loop.screen + terminal_size = self.loop.screen.get_cols_rows() self.show_pop_up( AboutView( self, @@ -316,7 +316,7 @@ def show_about(self) -> None: maximum_footlinks=self.maximum_footlinks, exit_confirmation_enabled=self.exit_confirmation, transparency_enabled=self.transparency_enabled, - screen=screen, + terminal_size=terminal_size, ), "area:help", ) diff --git a/zulipterminal/ui_tools/views.py b/zulipterminal/ui_tools/views.py index d5d4ac5dc5..8468adcbdf 100644 --- a/zulipterminal/ui_tools/views.py +++ b/zulipterminal/ui_tools/views.py @@ -1076,6 +1076,10 @@ def __init__( super().__init__(controller, widgets, "EXIT_POPUP", width, title) + + + + class AboutView(PopUpView): def __init__( self, @@ -1092,7 +1096,7 @@ def __init__( notify_enabled: bool, exit_confirmation_enabled: bool, transparency_enabled: bool, - screen: urwid.raw_display.Screen, + terminal_size: Tuple[int, int], ) -> None: self.feature_level_content = ( [("Feature level", str(server_feature_level))] @@ -1100,7 +1104,7 @@ def __init__( else [] ) - terminal_size = screen.get_cols_rows() + contents = [ ("Application", [("Zulip Terminal", zt_version)]), @@ -1125,7 +1129,8 @@ def __init__( [ ("Platform", PLATFORM), ("Python", detected_python_in_full()), - ("Current terminal size", f"{terminal_size[0]}x{terminal_size[1]}"), + ("Current terminal size", + f"{terminal_size[0]} columns x {terminal_size[1]} rows"), ], ), ] @@ -1152,6 +1157,10 @@ def keypress(self, size: urwid_Size, key: str) -> str: return super().keypress(size, key) + + + + class UserInfoView(PopUpView): def __init__(self, controller: Any, user_id: int, title: str, command: str) -> None: display_data, display_custom_profile_data = self._fetch_user_data( From 104eadadd5812fe1b012b3010015700ff244cc81 Mon Sep 17 00:00:00 2001 From: Swarnim114 Date: Fri, 26 Jul 2024 17:00:57 +0530 Subject: [PATCH 4/4] about_popup: Modified Terminal size text for readability. --- zulipterminal/ui_tools/views.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/zulipterminal/ui_tools/views.py b/zulipterminal/ui_tools/views.py index 8468adcbdf..82abc23b37 100644 --- a/zulipterminal/ui_tools/views.py +++ b/zulipterminal/ui_tools/views.py @@ -1076,10 +1076,6 @@ def __init__( super().__init__(controller, widgets, "EXIT_POPUP", width, title) - - - - class AboutView(PopUpView): def __init__( self, @@ -1104,8 +1100,6 @@ def __init__( else [] ) - - contents = [ ("Application", [("Zulip Terminal", zt_version)]), ("Server", [("Version", server_version)] + self.feature_level_content), @@ -1129,8 +1123,10 @@ def __init__( [ ("Platform", PLATFORM), ("Python", detected_python_in_full()), - ("Current terminal size", - f"{terminal_size[0]} columns x {terminal_size[1]} rows"), + ( + "Current terminal size", + f"{terminal_size[0]} columns x {terminal_size[1]} rows", + ), ], ), ] @@ -1157,10 +1153,6 @@ def keypress(self, size: urwid_Size, key: str) -> str: return super().keypress(size, key) - - - - class UserInfoView(PopUpView): def __init__(self, controller: Any, user_id: int, title: str, command: str) -> None: display_data, display_custom_profile_data = self._fetch_user_data(