Skip to content

Commit 070cf2b

Browse files
committed
refactor: buttons: Make dynamic stream color palette addition explicit.
Add comments re need to tidy palette extension & implementation details.
1 parent 5418195 commit 070cf2b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

zulipterminal/ui_tools/buttons.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,16 +210,26 @@ def __init__(
210210
self.count = count
211211
self.view = view
212212

213+
# FIXME: This section should be moved to a general palette-extension method
214+
# which is triggered when streams are initially loaded and when colors are
215+
# adjusted, or new streams added
213216
for entry in view.palette:
214217
if entry[0] is None:
218+
# NOTE: entry is generated at runtime, so length is dynamic
219+
# entry[5] is 256-color background entry
220+
# entry[2] is 16-color background entry
215221
background = entry[5] if len(entry) > 4 else entry[2]
216222
inverse_text = background if background else "black"
217223
break
224+
# These tuples represent (new) Urwid palette entries for the stream color:
225+
# (style_name, 16-color fg, 16-color bg, mono, 256+color fg, 256+color bg)
226+
# The normalized color becomes a named style (eg. "#abc") for colored foreground
218227
view.palette.append(
219-
(self.color, "", "", "bold", f"{self.color}, bold", background)
228+
(f"{self.color}", "", "", "bold", f"{self.color}, bold", background)
220229
)
230+
# The s-prefixed style name (eg "s#abc") is used for inverted styling
221231
view.palette.append(
222-
("s" + self.color, "", "", "standout", inverse_text, self.color)
232+
(f"s{self.color}", "", "", "standout", inverse_text, self.color)
223233
)
224234

225235
stream_marker = STREAM_ACCESS_TYPE[stream_access_type]["icon"]

0 commit comments

Comments
 (0)