Skip to content

Commit 51ba272

Browse files
committed
refactor: ui: Add semantic styles in set_footer_text().
This commit adds: * styling via a semantic parameter to the footer text in set_footer_text(). (default styling: "area:neutral") * hooks to use to these semantic styles wherever reasonable. Tests amended. Fixes #782.
1 parent 72c45fb commit 51ba272

File tree

8 files changed

+26
-17
lines changed

8 files changed

+26
-17
lines changed

tests/helper/test_helper.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,8 @@ def test_display_error_if_present(mocker, response, footer_updated):
305305
display_error_if_present(response, controller)
306306

307307
if footer_updated:
308-
set_footer_text.assert_called_once_with(response['msg'], 3)
308+
set_footer_text.assert_called_once_with(response['msg'],
309+
'task:failure', 3)
309310
else:
310311
set_footer_text.assert_not_called()
311312

@@ -340,7 +341,7 @@ def test_notify_if_message_sent_outside_narrow(mocker, req, narrow,
340341

341342
if footer_updated:
342343
set_footer_text.assert_called_once_with(
343-
'Message is sent outside of current narrow.', 3)
344+
'Message is sent outside of current narrow.', 'task:success', 3)
344345
else:
345346
set_footer_text.assert_not_called()
346347

tests/model/test_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ def test_update_stream_message(self, mocker, model,
562562
set_footer_text = model.controller.view.set_footer_text
563563
if result and footer_updated:
564564
set_footer_text.assert_called_once_with(
565-
"You changed a message's topic.", 3)
565+
"You changed a message's topic.", 'task:success', 3)
566566
else:
567567
set_footer_text.assert_not_called()
568568

tests/ui/test_ui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def test_set_footer_text_with_duration(self, view, mocker,
7676
return_value=['some help text'])
7777
mock_sleep = mocker.patch('time.sleep')
7878

79-
view.set_footer_text([custom_text], duration)
79+
view.set_footer_text([custom_text], duration=duration)
8080

8181
view._w.footer.set_text.assert_has_calls([
8282
mocker.call([custom_text]),

zulipterminal/helper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ def notify(title: str, html_text: str) -> str:
648648
def display_error_if_present(response: Dict[str, Any], controller: Any
649649
) -> None:
650650
if response['result'] == 'error' and hasattr(controller, 'view'):
651-
controller.view.set_footer_text(response['msg'], 3)
651+
controller.view.set_footer_text(response['msg'], 'task:failure', 3)
652652

653653

654654
def check_narrow_and_notify(outer_narrow: List[Any],
@@ -659,7 +659,7 @@ def check_narrow_and_notify(outer_narrow: List[Any],
659659
if (current_narrow != [] and current_narrow != outer_narrow
660660
and current_narrow != inner_narrow):
661661
controller.view.set_footer_text(
662-
'Message is sent outside of current narrow.', 3)
662+
'Message is sent outside of current narrow.', 'task:success', 3)
663663

664664

665665
def notify_if_message_sent_outside_narrow(message: Composition,

zulipterminal/model.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@ def session_draft_message(self) -> Optional[Composition]:
376376

377377
def save_draft(self, draft: Composition) -> None:
378378
self._draft = deepcopy(draft)
379-
self.controller.view.set_footer_text("Saved message as draft", 3)
379+
self.controller.view.set_footer_text("Saved message as draft",
380+
'task:success', 3)
380381

381382
@asynch
382383
def toggle_message_star_status(self, message: Message) -> None:
@@ -474,7 +475,8 @@ def update_stream_message(self, topic: str, message_id: int,
474475
new_topic = request['topic']
475476
view = self.controller.view
476477
if old_topic != new_topic:
477-
view.set_footer_text("You changed a message's topic.", 3)
478+
view.set_footer_text("You changed a message's topic.",
479+
'task:success', 3)
478480

479481
return response['result'] == 'success'
480482

zulipterminal/ui.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,14 @@ def get_random_help(self) -> List[Any]:
7878

7979
@asynch
8080
def set_footer_text(self, text_list: Optional[List[Any]]=None,
81+
theme: str='area:neutral',
8182
duration: Optional[float]=None) -> None:
8283
if text_list is None:
8384
text = self.get_random_help()
8485
else:
8586
text = text_list
8687
self._w.footer.set_text(text)
88+
self._w.footer.set_attr_map({None: theme})
8789
self.controller.update_screen()
8890
if duration is not None:
8991
assert duration > 0
@@ -250,7 +252,7 @@ def keypress(self, size: Tuple[int, int], key: str) -> Optional[str]:
250252
self.middle_column.set_focus('footer')
251253
else:
252254
self.set_footer_text('No draft message was saved in'
253-
' this session.', 3)
255+
' this session.', 'task:failure', 3)
254256
return key
255257
elif is_command_key('ABOUT', key):
256258
self.controller.show_about()

zulipterminal/ui_tools/boxes.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,8 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
535535
)
536536
else:
537537
self.view.set_footer_text("Cannot send message without"
538-
" specifying recipients.", 3)
538+
" specifying recipients.",
539+
'task:failure', 3)
539540
success = None
540541
if success:
541542
self.msg_write_box.edit_text = ''
@@ -594,7 +595,8 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
594595
'_REVERSE'
595596
))
596597
)
597-
self.view.set_footer_text(invalid_stream_error, 3)
598+
self.view.set_footer_text(invalid_stream_error,
599+
'task:failure', 3)
598600
return key
599601
user_ids = self.model.get_other_subscribers_in_stream(
600602
stream_name=stream_name)
@@ -625,7 +627,8 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
625627
if invalid_emails:
626628
invalid_emails_error = ('Invalid recipient(s) - '
627629
+ ', '.join(invalid_emails))
628-
self.view.set_footer_text(invalid_emails_error, 3)
630+
self.view.set_footer_text(invalid_emails_error,
631+
'task:failure', 3)
629632
return key
630633
users = self.model.user_dict
631634
self.recipient_user_ids = [users[email]['user_id']
@@ -1499,12 +1502,13 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
14991502
elif is_command_key('EDIT_MESSAGE', key):
15001503
if self.message['sender_id'] != self.model.user_id:
15011504
self.model.controller.view.set_footer_text(
1502-
" You can't edit messages sent by other users.", 3)
1505+
" You can't edit messages sent by other users.",
1506+
'task:failure', 3)
15031507
return key
15041508
# Check if editing is allowed in the realm
15051509
elif not self.model.initial_data['realm_allow_message_editing']:
15061510
self.model.controller.view.set_footer_text(
1507-
" Editing sent message is disabled.", 3)
1511+
" Editing sent message is disabled.", 'task:failure', 3)
15081512
return key
15091513
# Check if message is still editable, i.e. within
15101514
# the time limit.
@@ -1516,13 +1520,13 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
15161520
if self.message['type'] == 'private':
15171521
self.model.controller.view.set_footer_text(
15181522
" Time Limit for editing the message has"
1519-
" been exceeded.", 3)
1523+
" been exceeded.", 'task:failure', 3)
15201524
return key
15211525
elif self.message['type'] == 'stream':
15221526
self.model.controller.view.set_footer_text(
15231527
" Only topic editing allowed."
15241528
" Time Limit for editing the message body has"
1525-
" been exceeded.", 3)
1529+
" been exceeded.", 'task:failure', 3)
15261530
msg_body_edit_enabled = False
15271531

15281532
if self.message['type'] == 'private':

zulipterminal/ui_tools/buttons.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ def handle_narrow_link(self) -> None:
513513
error = self._validate_narrow_link(parsed_link)
514514

515515
if error:
516-
self.view.set_footer_text(f" {error}", duration=3)
516+
self.view.set_footer_text(f" {error}", 'task:failure', duration=3)
517517
else:
518518
self._switch_narrow_to(parsed_link)
519519

0 commit comments

Comments
 (0)