Skip to content

Commit

Permalink
refactor: ui: Add semantic styles in set_footer_text().
Browse files Browse the repository at this point in the history
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 zulip#782.
  • Loading branch information
Ezio-Sarthak committed Apr 17, 2021
1 parent 6f89e19 commit 9c48738
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 17 deletions.
5 changes: 3 additions & 2 deletions tests/helper/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ def test_display_error_if_present(mocker, response, footer_updated):
display_error_if_present(response, controller)

if footer_updated:
set_footer_text.assert_called_once_with(response['msg'], 3)
set_footer_text.assert_called_once_with(response['msg'],
'task:failure', 3)
else:
set_footer_text.assert_not_called()

Expand Down Expand Up @@ -340,7 +341,7 @@ def test_notify_if_message_sent_outside_narrow(mocker, req, narrow,

if footer_updated:
set_footer_text.assert_called_once_with(
'Message is sent outside of current narrow.', 3)
'Message is sent outside of current narrow.', 'task:success', 3)
else:
set_footer_text.assert_not_called()

Expand Down
2 changes: 1 addition & 1 deletion tests/model/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ def test_update_stream_message(self, mocker, model,
set_footer_text = model.controller.view.set_footer_text
if result and footer_updated:
set_footer_text.assert_called_once_with(
"You changed a message's topic.", 3)
"You changed a message's topic.", 'task:success', 3)
else:
set_footer_text.assert_not_called()

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_set_footer_text_with_duration(self, view, mocker,
return_value=['some help text'])
mock_sleep = mocker.patch('time.sleep')

view.set_footer_text([custom_text], duration)
view.set_footer_text([custom_text], duration=duration)

view._w.footer.set_text.assert_has_calls([
mocker.call([custom_text]),
Expand Down
4 changes: 2 additions & 2 deletions zulipterminal/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ def notify(title: str, html_text: str) -> str:
def display_error_if_present(response: Dict[str, Any], controller: Any
) -> None:
if response['result'] == 'error' and hasattr(controller, 'view'):
controller.view.set_footer_text(response['msg'], 3)
controller.view.set_footer_text(response['msg'], 'task:failure', 3)


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


def notify_if_message_sent_outside_narrow(message: Composition,
Expand Down
6 changes: 4 additions & 2 deletions zulipterminal/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@ def session_draft_message(self) -> Optional[Composition]:

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

@asynch
def toggle_message_star_status(self, message: Message) -> None:
Expand Down Expand Up @@ -474,7 +475,8 @@ def update_stream_message(self, topic: str, message_id: int,
new_topic = request['topic']
view = self.controller.view
if old_topic != new_topic:
view.set_footer_text("You changed a message's topic.", 3)
view.set_footer_text("You changed a message's topic.",
'task:success', 3)

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

Expand Down
4 changes: 3 additions & 1 deletion zulipterminal/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,14 @@ def get_random_help(self) -> List[Any]:

@asynch
def set_footer_text(self, text_list: Optional[List[Any]]=None,
theme: str='footer:neutral',
duration: Optional[float]=None) -> None:
if text_list is None:
text = self.get_random_help()
else:
text = text_list
self._w.footer.set_text(text)
self._w.footer.set_attr_map({None: theme})
self.controller.update_screen()
if duration is not None:
assert duration > 0
Expand Down Expand Up @@ -250,7 +252,7 @@ def keypress(self, size: Tuple[int, int], key: str) -> Optional[str]:
self.middle_column.set_focus('footer')
else:
self.set_footer_text('No draft message was saved in'
' this session.', 3)
' this session.', 'task:failure', 3)
return key
elif is_command_key('ABOUT', key):
self.controller.show_about()
Expand Down
18 changes: 11 additions & 7 deletions zulipterminal/ui_tools/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,8 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
)
else:
self.view.set_footer_text("Cannot send message without"
" specifying recipients.", 3)
" specifying recipients.",
'task:failure', 3)
success = None
if success:
self.msg_write_box.edit_text = ''
Expand Down Expand Up @@ -594,7 +595,8 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
'_REVERSE'
))
)
self.view.set_footer_text(invalid_stream_error, 3)
self.view.set_footer_text(invalid_stream_error,
'task:failure', 3)
return key
user_ids = self.model.get_other_subscribers_in_stream(
stream_name=stream_name)
Expand Down Expand Up @@ -625,7 +627,8 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
if invalid_emails:
invalid_emails_error = ('Invalid recipient(s) - '
+ ', '.join(invalid_emails))
self.view.set_footer_text(invalid_emails_error, 3)
self.view.set_footer_text(invalid_emails_error,
'task:failure', 3)
return key
users = self.model.user_dict
self.recipient_user_ids = [users[email]['user_id']
Expand Down Expand Up @@ -1509,12 +1512,13 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
elif is_command_key('EDIT_MESSAGE', key):
if self.message['sender_id'] != self.model.user_id:
self.model.controller.view.set_footer_text(
" You can't edit messages sent by other users.", 3)
" You can't edit messages sent by other users.",
'task:failure', 3)
return key
# Check if editing is allowed in the realm
elif not self.model.initial_data['realm_allow_message_editing']:
self.model.controller.view.set_footer_text(
" Editing sent message is disabled.", 3)
" Editing sent message is disabled.", 'task:failure', 3)
return key
# Check if message is still editable, i.e. within
# the time limit.
Expand All @@ -1526,13 +1530,13 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
if self.message['type'] == 'private':
self.model.controller.view.set_footer_text(
" Time Limit for editing the message has"
" been exceeded.", 3)
" been exceeded.", 'task:failure', 3)
return key
elif self.message['type'] == 'stream':
self.model.controller.view.set_footer_text(
" Only topic editing allowed."
" Time Limit for editing the message body has"
" been exceeded.", 3)
" been exceeded.", 'task:warning', 3)
msg_body_edit_enabled = False

if self.message['type'] == 'private':
Expand Down
2 changes: 1 addition & 1 deletion zulipterminal/ui_tools/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ def handle_narrow_link(self) -> None:
error = self._validate_narrow_link(parsed_link)

if error:
self.view.set_footer_text(f" {error}", duration=3)
self.view.set_footer_text(f" {error}", 'task:failure', duration=3)
else:
self._switch_narrow_to(parsed_link)

Expand Down

0 comments on commit 9c48738

Please sign in to comment.