Colourize tab name in its infobar

This is for faster learning the colour <-> tab association and to
see quickly in which tab you’re currently in.
This commit is contained in:
Jonas Schäfer 2020-05-10 15:08:10 +02:00 committed by Link Mauve
parent 7b99fcfb2f
commit 8b13d3c572
2 changed files with 39 additions and 5 deletions

View file

@ -238,6 +238,10 @@ class Theme:
MODE_TAB_NORMAL = '' MODE_TAB_NORMAL = ''
MODE_TAB_IMPORTANT = 'r' # reverse video mode MODE_TAB_IMPORTANT = 'r' # reverse video mode
# This is the mode used for the tab name in the info bar of MUC and 1:1
# chat tabs.
MODE_TAB_NAME = 'r'
COLOR_VERTICAL_TAB_NORMAL = (4, -1) COLOR_VERTICAL_TAB_NORMAL = (4, -1)
COLOR_VERTICAL_TAB_NONEMPTY = (4, -1) COLOR_VERTICAL_TAB_NONEMPTY = (4, -1)
COLOR_VERTICAL_TAB_JOINED = (82, -1) COLOR_VERTICAL_TAB_JOINED = (82, -1)

View file

@ -16,6 +16,7 @@ from poezio.config import config
from poezio.windows.base_wins import Win from poezio.windows.base_wins import Win
from poezio.ui.funcs import truncate_nick from poezio.ui.funcs import truncate_nick
from poezio.theming import get_theme, to_curses_attr from poezio.theming import get_theme, to_curses_attr
from poezio.colors import ccg_text_to_color
if TYPE_CHECKING: if TYPE_CHECKING:
from poezio.user import User from poezio.user import User
@ -103,6 +104,9 @@ class PrivateInfoWin(InfoWin):
to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) to_curses_attr(get_theme().COLOR_INFORMATION_BAR))
def write_room_name(self, name): def write_room_name(self, name):
# TODO: autocolour this too, but we need more info about the occupant
# (whether we know its real jid) and the room (whether it is
# anonymous) to provide correct colouring.
try: try:
jid = JID(name) jid = JID(name)
except InvalidJID: except InvalidJID:
@ -223,13 +227,23 @@ class ConversationInfoWin(InfoWin):
""" """
Write the information about the contact Write the information about the contact
""" """
color = to_curses_attr(get_theme().COLOR_INFORMATION_BAR) theme = get_theme()
color = to_curses_attr(theme.COLOR_INFORMATION_BAR)
if config.get('autocolor_tab_names') and contact is not None:
name_color = (
ccg_text_to_color(theme.ccg_palette, str(contact.bare_jid)),
-1,
theme.MODE_TAB_NAME,
)
else:
name_color = color
if not contact: if not contact:
self.addstr("(contact not in roster)", color) self.addstr("(contact not in roster)", color)
return return
display_name = contact.name display_name = contact.name
if display_name: if display_name:
self.addstr('%s ' % (display_name), color) self.addstr('%s ' % (display_name), name_color)
def write_contact_jid(self, jid): def write_contact_jid(self, jid):
""" """
@ -237,9 +251,17 @@ class ConversationInfoWin(InfoWin):
""" """
theme = get_theme() theme = get_theme()
color = to_curses_attr(theme.COLOR_INFORMATION_BAR) color = to_curses_attr(theme.COLOR_INFORMATION_BAR)
if config.get('autocolor_tab_names'):
name_color = (
ccg_text_to_color(theme.ccg_palette, str(contact.jid)),
-1,
theme.MODE_TAB_NAME,
)
else:
name_color = theme.COLOR_CONVERSATION_NAME
self.addstr('[', color) self.addstr('[', color)
self.addstr(jid.full, self.addstr(jid.full, to_curses_attr(name_color))
to_curses_attr(theme.COLOR_CONVERSATION_NAME))
self.addstr('] ', color) self.addstr('] ', color)
def write_chatstate(self, state): def write_chatstate(self, state):
@ -313,9 +335,17 @@ class MucInfoWin(InfoWin):
def write_room_name(self, room): def write_room_name(self, room):
theme = get_theme() theme = get_theme()
color = to_curses_attr(theme.COLOR_INFORMATION_BAR) color = to_curses_attr(theme.COLOR_INFORMATION_BAR)
label_color = theme.COLOR_GROUPCHAT_NAME
if config.get('autocolor_tab_names'):
label_color = ccg_text_to_color(
theme.ccg_palette,
room.jid.bare,
), -1, theme.MODE_TAB_NAME
self.addstr('[', color) self.addstr('[', color)
self.addstr(room.name, self.addstr(room.name,
to_curses_attr(theme.COLOR_GROUPCHAT_NAME)) to_curses_attr(label_color))
self.addstr(']', color) self.addstr(']', color)
def write_participants_number(self, room): def write_participants_number(self, room):