Skip to content

Commit ad7a80c

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: "footer:neutral") * hooks to use to these semantic styles wherever reasonable. Tests amended. Fixes #782.
1 parent 28fc076 commit ad7a80c

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
@@ -568,7 +568,7 @@ def test_update_stream_message(self, mocker, model,
568568
set_footer_text = model.controller.view.set_footer_text
569569
if result and footer_updated:
570570
set_footer_text.assert_called_once_with(
571-
"You changed a message's topic.", 3)
571+
"You changed a message's topic.", 'task:success', 3)
572572
else:
573573
set_footer_text.assert_not_called()
574574

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
@@ -385,7 +385,8 @@ def session_draft_message(self) -> Optional[Composition]:
385385

386386
def save_draft(self, draft: Composition) -> None:
387387
self._draft = deepcopy(draft)
388-
self.controller.view.set_footer_text("Saved message as draft", 3)
388+
self.controller.view.set_footer_text("Saved message as draft",
389+
'task:success', 3)
389390

390391
@asynch
391392
def toggle_message_star_status(self, message: Message) -> None:
@@ -483,7 +484,8 @@ def update_stream_message(self, topic: str, message_id: int,
483484
new_topic = request['topic']
484485
view = self.controller.view
485486
if old_topic != new_topic:
486-
view.set_footer_text("You changed a message's topic.", 3)
487+
view.set_footer_text("You changed a message's topic.",
488+
'task:success', 3)
487489

488490
return response['result'] == 'success'
489491

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='footer: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
@@ -539,7 +539,8 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
539539
)
540540
else:
541541
self.view.set_footer_text("Cannot send message without"
542-
" specifying recipients.", 3)
542+
" specifying recipients.",
543+
'task:failure', 3)
543544
success = None
544545
if success:
545546
self.msg_write_box.edit_text = ''
@@ -598,7 +599,8 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
598599
'_REVERSE'
599600
))
600601
)
601-
self.view.set_footer_text(invalid_stream_error, 3)
602+
self.view.set_footer_text(invalid_stream_error,
603+
'task:failure', 3)
602604
return key
603605
user_ids = self.model.get_other_subscribers_in_stream(
604606
stream_name=stream_name)
@@ -629,7 +631,8 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
629631
if invalid_emails:
630632
invalid_emails_error = ('Invalid recipient(s) - '
631633
+ ', '.join(invalid_emails))
632-
self.view.set_footer_text(invalid_emails_error, 3)
634+
self.view.set_footer_text(invalid_emails_error,
635+
'task:failure', 3)
633636
return key
634637
users = self.model.user_dict
635638
self.recipient_user_ids = [users[email]['user_id']
@@ -1513,12 +1516,13 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
15131516
elif is_command_key('EDIT_MESSAGE', key):
15141517
if self.message['sender_id'] != self.model.user_id:
15151518
self.model.controller.view.set_footer_text(
1516-
" You can't edit messages sent by other users.", 3)
1519+
" You can't edit messages sent by other users.",
1520+
'task:failure', 3)
15171521
return key
15181522
# Check if editing is allowed in the realm
15191523
elif not self.model.initial_data['realm_allow_message_editing']:
15201524
self.model.controller.view.set_footer_text(
1521-
" Editing sent message is disabled.", 3)
1525+
" Editing sent message is disabled.", 'task:failure', 3)
15221526
return key
15231527
# Check if message is still editable, i.e. within
15241528
# the time limit.
@@ -1530,13 +1534,13 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
15301534
if self.message['type'] == 'private':
15311535
self.model.controller.view.set_footer_text(
15321536
" Time Limit for editing the message has"
1533-
" been exceeded.", 3)
1537+
" been exceeded.", 'task:failure', 3)
15341538
return key
15351539
elif self.message['type'] == 'stream':
15361540
self.model.controller.view.set_footer_text(
15371541
" Only topic editing allowed."
15381542
" Time Limit for editing the message body has"
1539-
" been exceeded.", 3)
1543+
" been exceeded.", 'task:warning', 3)
15401544
msg_body_edit_enabled = False
15411545

15421546
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)