Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight current narrow (rebased/simplified/extended) #1244 #1334

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions zulipterminal/config/themes.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
'area:error' : 'standout',
'area:user' : 'standout',
'search_error' : 'standout',
'active_narrow' : 'standout',
'task:success' : 'standout',
'task:error' : 'standout',
'task:warning' : 'standout',
Expand Down
26 changes: 26 additions & 0 deletions zulipterminal/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ def __init__(self, controller: Any) -> None:
self._last_unread_topic = None
self.last_unread_pm = None

self.active_button: Any = None

self.user_id = -1
self.user_email = ""
self.user_full_name = ""
Expand Down Expand Up @@ -314,6 +316,10 @@ def set_narrow(
raise RuntimeError("Model.set_narrow parameters used incorrectly.")

if new_narrow != self.narrow:
# Deactivate any previous button
if self.active_button is not None:
self.active_button.is_active = False

self.narrow = new_narrow

if pm_with is not None and new_narrow[0][0] == "pm-with":
Expand All @@ -330,6 +336,26 @@ def set_narrow(
else:
self.stream_id = None

# Activate new button (if stream)
if self.stream_id:
new_stream_button = self.controller.view.stream_id_to_button[
self.stream_id
]
self.active_button = new_stream_button # Save to deactivate
self.active_button.is_active = True
if new_narrow == []:
self.active_button = self.controller.view.home_button
self.active_button.is_active = True
if pms is True:
self.active_button = self.controller.view.pm_button
self.active_button.is_active = True
if starred is True:
self.active_button = self.controller.view.starred_button
self.active_button.is_active = True
if mentioned is True:
self.active_button = self.controller.view.mentioned_button
self.active_button.is_active = True

return False
else:
return True
Expand Down
1 change: 1 addition & 0 deletions zulipterminal/themes/gruvbox_dark.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
'area:error' : (Color.DARK0_HARD, Color.BRIGHT_RED),
'area:user' : (Color.DARK0_HARD, Color.BRIGHT_YELLOW),
'search_error' : (Color.BRIGHT_RED, Color.DARK0_HARD),
'active_narrow' : (Color.DARK0_HARD, Color.BRIGHT_GREEN),
'task:success' : (Color.DARK0_HARD, Color.BRIGHT_GREEN),
'task:error' : (Color.DARK0_HARD, Color.BRIGHT_RED),
'task:warning' : (Color.DARK0_HARD, Color.NEUTRAL_PURPLE),
Expand Down
1 change: 1 addition & 0 deletions zulipterminal/themes/gruvbox_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
'area:error' : (Color.LIGHT0_HARD, Color.FADED_RED),
'area:user' : (Color.LIGHT0_HARD, Color.FADED_YELLOW),
'search_error' : (Color.FADED_RED, Color.LIGHT0_HARD),
'active_narrow' : (Color.LIGHT0_HARD, Color.FADED_GREEN),
'task:success' : (Color.LIGHT0_HARD, Color.FADED_GREEN),
'task:error' : (Color.LIGHT0_HARD, Color.FADED_RED),
'task:warning' : (Color.LIGHT0_HARD, Color.NEUTRAL_PURPLE),
Expand Down
1 change: 1 addition & 0 deletions zulipterminal/themes/zt_blue.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
'area:error' : (Color.WHITE, Color.DARK_RED),
'area:user' : (Color.WHITE, Color.DARK_BLUE),
'search_error' : (Color.LIGHT_RED, Color.LIGHT_BLUE),
'active_narrow' : (Color.WHITE, Color.DARK_GREEN),
'task:success' : (Color.WHITE, Color.DARK_GREEN),
'task:error' : (Color.WHITE, Color.DARK_RED),
'task:warning' : (Color.WHITE, Color.BROWN),
Expand Down
1 change: 1 addition & 0 deletions zulipterminal/themes/zt_dark.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
'area:error' : (Color.WHITE, Color.DARK_RED),
'area:user' : (Color.WHITE, Color.DARK_BLUE),
'search_error' : (Color.LIGHT_RED, Color.BLACK),
'active_narrow' : (Color.WHITE, Color.DARK_GREEN),
'task:success' : (Color.WHITE, Color.DARK_GREEN),
'task:error' : (Color.WHITE, Color.DARK_RED),
'task:warning' : (Color.WHITE, Color.BROWN),
Expand Down
1 change: 1 addition & 0 deletions zulipterminal/themes/zt_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
'area:error' : (Color.BLACK, Color.LIGHT_RED),
'area:user' : (Color.WHITE, Color.DARK_BLUE),
'search_error' : (Color.LIGHT_RED, Color.WHITE),
'active_narrow' : (Color.BLACK, Color.DARK_GREEN),
'task:success' : (Color.BLACK, Color.DARK_GREEN),
'task:error' : (Color.WHITE, Color.DARK_RED),
'task:warning' : (Color.BLACK, Color.YELLOW),
Expand Down
15 changes: 14 additions & 1 deletion zulipterminal/ui_tools/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def __init__(
self.show_function = show_function
self.count = count

self._is_active = False

super().__init__("")

self.button_prefix = urwid.Text("")
Expand All @@ -57,6 +59,18 @@ def __init__(

urwid.connect_signal(self, "click", self.activate)

@property
def is_active(self) -> bool:
return self._is_active

@is_active.setter
def is_active(self, new_value: bool) -> None:
self._is_active = new_value
if self._is_active:
self._w.set_attr_map({None: "active_narrow"})
else:
self._w.set_attr_map({None: self.label_style})

def _set_prefix_style(self, style: str) -> None:
self._prefix_markup = (style, self._prefix_markup[1])

Expand Down Expand Up @@ -100,7 +114,6 @@ def update_widget(self) -> Any:
self.button_prefix.set_text(prefix)
self.set_label(self.label_text)
self.button_suffix.set_text(suffix)
self._w.set_attr_map({None: self.label_style})

def activate(self, key: Any) -> None:
self.controller.view.show_left_panel(visible=False)
Expand Down