Skip to content

Commit 4ea702d

Browse files
committed
core: Display settings in LoadingView.
Stop showing loading settings for theme and autohide to stdout and use the LoadingView instead. Note that in case of invalid settings, output would still be displayed to stdout. Tests amended.
1 parent 3070f44 commit 4ea702d

File tree

6 files changed

+24
-22
lines changed

6 files changed

+24
-22
lines changed

tests/cli/test_run.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,6 @@ def test_valid_zuliprc_but_no_connection(capsys, mocker, minimal_zuliprc,
9393

9494
lines = captured.out.strip().split("\n")
9595
expected_lines = [
96-
"Loading with:",
97-
" theme 'zt_dark' specified with no config.",
98-
" autohide setting 'no_autohide' specified with no config.",
9996
"\x1b[91m",
10097
("Error connecting to Zulip server: {}.\x1b[0m".
10198
format(server_connection_error)),
@@ -126,13 +123,10 @@ def test_warning_regarding_incomplete_theme(capsys, mocker, monkeypatch,
126123

127124
lines = captured.out.strip().split("\n")
128125
expected_lines = [
129-
"Loading with:",
130-
" theme '{}' specified on command line.".format(bad_theme),
131126
"\x1b[93m"
132127
" WARNING: Incomplete theme; results may vary!",
133128
" (you could try: {}, {})"
134129
"\x1b[0m".format('a', 'b'),
135-
" autohide setting 'no_autohide' specified with no config.",
136130
"\x1b[91m",
137131
("Error connecting to Zulip server: {}.\x1b[0m".
138132
format(server_connection_error)),

tests/core/test_core.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,16 @@ def controller(self, mocker) -> None:
3434
self.theme = 'default'
3535
self.autohide = True # FIXME Add tests for no-autohide
3636
self.notify_enabled = False
37-
return Controller(self.config_file, self.theme, 256, self.autohide,
38-
self.notify_enabled)
37+
self.settings = mocker.Mock()
38+
return Controller(self.config_file, self.theme, 256, self.settings,
39+
self.autohide, self.notify_enabled)
3940

4041
def test_initialize_controller(self, controller, mocker) -> None:
4142
self.client.assert_called_once_with(
4243
config_file=self.config_file,
4344
client='ZulipTerminal/' + ZT_VERSION + ' ' + platform(),
4445
)
45-
self.loading_view.assert_called_once_with(controller)
46+
self.loading_view.assert_called_once_with(controller, self.settings)
4647
self.model.assert_called_once_with(controller)
4748
self.view.assert_called_once_with(controller)
4849
self.model.poll_for_events.assert_called_once_with()

tests/ui/test_ui_tools.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2476,7 +2476,9 @@ class TestLoadingView:
24762476
@pytest.fixture
24772477
def loading_view(self, mocker):
24782478
self.controller = mocker.Mock()
2479-
loading_view = LoadingView(self.controller)
2479+
self.settings = {'theme': ('wombat', 'on commandline'),
2480+
'autohide': ('autohide', 'default')}
2481+
loading_view = LoadingView(self.controller, self.settings)
24802482
return loading_view
24812483

24822484
def test_init(self, loading_view):

zulipterminal/cli/run.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,17 +258,13 @@ def main(options: Optional[List[str]]=None) -> None:
258258
"{} (by alias '{}')".format(theme_to_use[1], theme_to_use[0])
259259
)
260260

261-
print("Loading with:")
262-
print(" theme '{}' specified {}.".format(*theme_to_use))
263261
complete, incomplete = complete_and_incomplete_themes()
264262
if theme_to_use[0] in incomplete:
265263
print(in_color('yellow',
266264
" WARNING: Incomplete theme; "
267265
"results may vary!\n"
268266
" (you could try: {})".
269267
format(", ".join(complete))))
270-
print(" autohide setting '{}' specified {}."
271-
.format(*zterm['autohide']))
272268
# For binary settings
273269
# Specify setting in order True, False
274270
valid_settings = {
@@ -293,9 +289,13 @@ def main(options: Optional[List[str]]=None) -> None:
293289
else:
294290
theme_data = THEMES[theme_to_use[0]]
295291

292+
settings = {'theme': theme_to_use,
293+
'autohide': zterm['autohide']}
294+
296295
Controller(zuliprc_path,
297296
theme_data,
298297
int(args.color_depth),
298+
settings,
299299
**boolean_settings).main()
300300
except ServerConnectionFailure as e:
301301
print(in_color('red',

zulipterminal/core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import time
55
from functools import partial
66
from platform import platform
7-
from typing import Any, List, Optional, Tuple
7+
from typing import Any, Dict, List, Optional, Tuple
88

99
import urwid
1010
import zulip
@@ -28,7 +28,7 @@ class Controller:
2828
"""
2929

3030
def __init__(self, config_file: str, theme: ThemeSpec,
31-
color_depth: int,
31+
color_depth: int, settings: Dict[str, Any],
3232
autohide: bool, notify: bool) -> None:
3333
self.theme = theme
3434
self.color_depth = color_depth
@@ -41,7 +41,7 @@ def __init__(self, config_file: str, theme: ThemeSpec,
4141
self.client = zulip.Client(config_file=config_file,
4242
client='ZulipTerminal/{} {}'.
4343
format(ZT_VERSION, platform()))
44-
self.loading_view = LoadingView(self)
44+
self.loading_view = LoadingView(self, settings)
4545
self.init_model_view()
4646

4747
@asynch

zulipterminal/ui_tools/views.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -989,12 +989,17 @@ def __init__(self, controller: Any, msg: Message, title: str) -> None:
989989

990990

991991
class LoadingView(urwid.Filler):
992-
def __init__(self, controller: Any) -> None:
992+
def __init__(self, controller: Any, settings: Dict[str, Any]) -> None:
993993
self.controller = controller
994-
self.text = ["Welcome to Zulip.\n\n",
994+
self.text = [('user_active', "Welcome to Zulip.\n\n\n"),
995+
"Loading with:\n",
996+
"theme '{}' specified {}.\n".format(*settings['theme']),
997+
"autohide setting '{}' specified {}.\n\n"
998+
.format(*settings['autohide']),
995999
"Loading..."]
996-
text_wid = urwid.Text(self.text, 'center')
997-
super().__init__(text_wid, 'middle', 'pack')
1000+
text_wid = urwid.Text(self.text)
1001+
padding = urwid.Padding(text_wid, 'center', ('relative', 50))
1002+
super().__init__(padding, 'middle', 'pack')
9981003

9991004
def selectable(self) -> bool:
10001005
return True
@@ -1003,4 +1008,4 @@ def keypress(self, size: Tuple[int, int], key: str) -> str:
10031008
return key
10041009

10051010
def set_spinner(self, spinner: str) -> None:
1006-
self.base_widget.set_text(self.text + [spinner])
1011+
self.body.base_widget.set_text(self.text + [spinner])

0 commit comments

Comments
 (0)