Skip to content

Commit e2a62a2

Browse files
Ezio-Sarthakneiljp
authored andcommitted
boxes: Add appropriate color to compose header stream markers.
Style improvements: * Stream prefixes' color rendered. * The topic prefix is not rendered to make equivalence with the webapp. Tests updated and added (marker/color rendering). Partially fixes #783.
1 parent 2a5d91d commit e2a62a2

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

tests/ui_tools/test_boxes.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,15 @@ def test__stream_box_autocomplete(self, mocker, write_box, text, state,
315315
matching_streams)
316316

317317
@pytest.mark.parametrize([
318-
'stream_name', 'stream_id', 'is_valid_stream', 'expected_marker'], [
319-
('Secret stream', 99, True, STREAM_MARKER_PRIVATE),
320-
('Stream 1', 1, True, STREAM_MARKER_PUBLIC),
321-
('Stream 0', 0, False, STREAM_MARKER_INVALID),
318+
'stream_name',
319+
'stream_id',
320+
'is_valid_stream',
321+
'expected_marker',
322+
'expected_color'
323+
], [
324+
('Secret stream', 99, True, STREAM_MARKER_PRIVATE, '#ccc'),
325+
('Stream 1', 1, True, STREAM_MARKER_PUBLIC, '#b0a5fd'),
326+
('Stream 0', 0, False, STREAM_MARKER_INVALID, 'general_bar'),
322327
], ids=[
323328
'private_stream',
324329
'public_stream',
@@ -327,7 +332,7 @@ def test__stream_box_autocomplete(self, mocker, write_box, text, state,
327332
def test__set_stream_write_box_style_markers(self, write_box, stream_id,
328333
stream_name, is_valid_stream,
329334
expected_marker, stream_dict,
330-
mocker):
335+
mocker, expected_color):
331336
# FIXME: Refactor when we have ~ Model.is_private_stream
332337
write_box.model.stream_dict = stream_dict
333338
write_box.model.is_valid_stream.return_value = is_valid_stream
@@ -337,8 +342,11 @@ def test__set_stream_write_box_style_markers(self, write_box, stream_id,
337342

338343
write_box._set_stream_write_box_style(write_box, stream_name)
339344

340-
assert (write_box.header_write_box
341-
[write_box.FOCUS_HEADER_PREFIX_STREAM].text) == expected_marker
345+
stream_marker = (write_box.header_write_box
346+
[write_box.FOCUS_HEADER_PREFIX_STREAM])
347+
348+
assert stream_marker.text == expected_marker
349+
assert stream_marker.attrib[0][0] == expected_color
342350

343351
@pytest.mark.parametrize('text, expected_text', [
344352
('Som', 'Some general stream'),

zulipterminal/ui_tools/boxes.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,14 @@ def stream_box_view(self, stream_id: int, caption: str='', title: str='',
117117
)
118118
self.title_write_box.set_completer_delims("")
119119

120+
stream_marker = STREAM_MARKER_PUBLIC
121+
color = None
122+
if caption:
123+
color = self.model.stream_dict[self.stream_id]['color']
124+
if self.model.stream_dict[self.stream_id]['invite_only']:
125+
stream_marker = STREAM_MARKER_PRIVATE
120126
self.header_write_box = urwid.Columns([
121-
('pack', urwid.Text(STREAM_MARKER_PUBLIC)),
127+
('pack', urwid.Text((color, STREAM_MARKER_PUBLIC))),
122128
self.stream_write_box,
123129
('pack', urwid.Text(STREAM_TOPIC_SEPARATOR)),
124130
self.title_write_box], dividechars=1)
@@ -149,15 +155,17 @@ def _set_stream_write_box_style(self, widget: ReadlineEdit,
149155
new_text: str) -> None:
150156
# FIXME: Refactor when we have ~ Model.is_private_stream
151157
stream_marker = STREAM_MARKER_INVALID
158+
color = 'general_bar'
152159
if self.model.is_valid_stream(new_text):
153160
stream = self.model.stream_dict[
154161
self.model.stream_id_from_name(new_text)]
155162
if stream['invite_only']:
156163
stream_marker = STREAM_MARKER_PRIVATE
157164
else:
158165
stream_marker = STREAM_MARKER_PUBLIC
166+
color = stream['color']
159167
(self.header_write_box[self.FOCUS_HEADER_PREFIX_STREAM]
160-
.set_text(stream_marker))
168+
.set_text((color, stream_marker)))
161169

162170
def _topic_box_autocomplete(self, text: str, state: Optional[int]
163171
) -> Optional[str]:

0 commit comments

Comments
 (0)