Commit a1af8a49 authored by Link Mauve's avatar Link Mauve

Store get_theme() in a variable in each function, to avoid redundant calls.

parent 7d6cd695
Pipeline #1875 failed with stages
in 1 minute and 55 seconds
......@@ -1270,71 +1270,40 @@ class HandlerCore:
semi_anon = '173' in status_codes
full_anon = '174' in status_codes
modif = False
info_col = {'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT)}
if show_unavailable or hide_unavailable or non_priv or logging_off\
or non_anon or semi_anon or full_anon:
tab.add_message(
'\x19%(info_col)s}Info: A configuration change not privacy-related occurred.'
% {
'info_col': dump_tuple(
get_theme().COLOR_INFORMATION_TEXT)
},
'\x19%(info_col)s}Info: A configuration change not privacy-related occurred.' % info_col
typ=2)
modif = True
if show_unavailable:
tab.add_message(
'\x19%(info_col)s}Info: The unavailable members are now shown.'
% {
'info_col': dump_tuple(
get_theme().COLOR_INFORMATION_TEXT)
},
'\x19%(info_col)s}Info: The unavailable members are now shown.' % info_col
typ=2)
elif hide_unavailable:
tab.add_message(
'\x19%(info_col)s}Info: The unavailable members are now hidden.'
% {
'info_col': dump_tuple(
get_theme().COLOR_INFORMATION_TEXT)
},
'\x19%(info_col)s}Info: The unavailable members are now hidden.' % info_col
typ=2)
if non_anon:
tab.add_message(
'\x191}Warning:\x19%(info_col)s} The room is now not anonymous. (public JID)'
% {
'info_col': dump_tuple(
get_theme().COLOR_INFORMATION_TEXT)
},
'\x191}Warning:\x19%(info_col)s} The room is now not anonymous. (public JID)' % info_col
typ=2)
elif semi_anon:
tab.add_message(
'\x19%(info_col)s}Info: The room is now semi-anonymous. (moderators-only JID)'
% {
'info_col': dump_tuple(
get_theme().COLOR_INFORMATION_TEXT)
},
'\x19%(info_col)s}Info: The room is now semi-anonymous. (moderators-only JID)' % info_col
typ=2)
elif full_anon:
tab.add_message(
'\x19%(info_col)s}Info: The room is now fully anonymous.' %
{
'info_col': dump_tuple(
get_theme().COLOR_INFORMATION_TEXT)
},
'\x19%(info_col)s}Info: The room is now fully anonymous.' % info_col
typ=2)
if logging_on:
tab.add_message(
'\x191}Warning: \x19%(info_col)s}This room is publicly logged'
% {
'info_col': dump_tuple(
get_theme().COLOR_INFORMATION_TEXT)
},
'\x191}Warning: \x19%(info_col)s}This room is publicly logged' % info_col
typ=2)
elif logging_off:
tab.add_message(
'\x19%(info_col)s}Info: This room is not logged anymore.' %
{
'info_col': dump_tuple(
get_theme().COLOR_INFORMATION_TEXT)
},
'\x19%(info_col)s}Info: This room is not logged anymore.' % info_col
typ=2)
if modif:
self.core.refresh_window()
......@@ -1352,9 +1321,10 @@ class HandlerCore:
if subject != tab.topic:
# Do not display the message if the subject did not change or if we
# receive an empty topic when joining the room.
theme = get_theme()
fmt = {
'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT),
'text_col': dump_tuple(get_theme().COLOR_NORMAL_TEXT),
'info_col': dump_tuple(theme.COLOR_INFORMATION_TEXT),
'text_col': dump_tuple(theme.COLOR_NORMAL_TEXT),
'subject': subject,
'user': '',
}
......@@ -1448,17 +1418,18 @@ class HandlerCore:
xhtml_text, force=True).rstrip('\x19o').strip()
else:
poezio_colored = str(stanza)
char = get_theme().CHAR_XML_OUT
self.core.add_message_to_text_buffer(
self.core.xml_buffer,
poezio_colored,
nickname=get_theme().CHAR_XML_OUT)
nickname=char)
try:
if self.core.xml_tab.match_stanza(
ElementBase(ET.fromstring(stanza))):
self.core.add_message_to_text_buffer(
self.core.xml_tab.filtered_buffer,
poezio_colored,
nickname=get_theme().CHAR_XML_OUT)
nickname=char)
except:
log.debug('', exc_info=True)
......@@ -1477,16 +1448,17 @@ class HandlerCore:
xhtml_text, force=True).rstrip('\x19o').strip()
else:
poezio_colored = str(stanza)
char = get_theme().CHAR_XML_IN
self.core.add_message_to_text_buffer(
self.core.xml_buffer,
poezio_colored,
nickname=get_theme().CHAR_XML_IN)
nickname=char)
try:
if self.core.xml_tab.match_stanza(stanza):
self.core.add_message_to_text_buffer(
self.core.xml_tab.filtered_buffer,
poezio_colored,
nickname=get_theme().CHAR_XML_IN)
nickname=char)
except:
log.debug('', exc_info=True)
if isinstance(self.core.tabs.current_tab, tabs.XMLTab):
......
......@@ -157,13 +157,14 @@ class MucTab(ChatTab):
def leave_room(self, message: str):
if self.joined:
info_col = dump_tuple(get_theme().COLOR_INFORMATION_TEXT)
char_quit = get_theme().CHAR_QUIT
spec_col = dump_tuple(get_theme().COLOR_QUIT_CHAR)
theme = get_theme()
info_col = dump_tuple(theme.COLOR_INFORMATION_TEXT)
char_quit = theme.CHAR_QUIT
spec_col = dump_tuple(theme.COLOR_QUIT_CHAR)
if config.get_by_tabname('display_user_color_in_join_part',
self.general_jid):
color = dump_tuple(get_theme().COLOR_OWN_NICK)
color = dump_tuple(theme.COLOR_OWN_NICK)
else:
color = "3"
......@@ -301,8 +302,9 @@ class MucTab(ChatTab):
"""
Print the current topic
"""
info_text = dump_tuple(get_theme().COLOR_INFORMATION_TEXT)
norm_text = dump_tuple(get_theme().COLOR_NORMAL_TEXT)
theme = get_theme()
info_text = dump_tuple(theme.COLOR_INFORMATION_TEXT)
norm_text = dump_tuple(theme.COLOR_NORMAL_TEXT)
if self.topic_from:
user = self.get_user_by_name(self.topic_from)
if user:
......@@ -521,7 +523,8 @@ class MucTab(ChatTab):
if (self.core.tabs.current_tab is self
and self.core.status.show not in ('xa', 'away')):
self.send_chat_state('active')
new_user.color = get_theme().COLOR_OWN_NICK
theme = get_theme()
new_user.color = theme.COLOR_OWN_NICK
if config.get_by_tabname('display_user_color_in_join_part',
self.general_jid):
......@@ -529,14 +532,14 @@ class MucTab(ChatTab):
else:
color = "3"
info_col = dump_tuple(get_theme().COLOR_INFORMATION_TEXT)
warn_col = dump_tuple(get_theme().COLOR_WARNING_TEXT)
spec_col = dump_tuple(get_theme().COLOR_JOIN_CHAR)
info_col = dump_tuple(theme.COLOR_INFORMATION_TEXT)
warn_col = dump_tuple(theme.COLOR_WARNING_TEXT)
spec_col = dump_tuple(theme.COLOR_JOIN_CHAR)
enable_message = ('\x19%(color_spec)s}%(spec)s\x19%(info_col)s} You '
'(\x19%(nick_col)s}%(nick)s\x19%(info_col)s}) joined'
' the room') % {
'nick': from_nick,
'spec': get_theme().CHAR_JOIN,
'spec': theme.CHAR_JOIN,
'color_spec': spec_col,
'nick_col': color,
'info_col': info_col,
......@@ -651,9 +654,10 @@ class MucTab(ChatTab):
color = dump_tuple(user.color)
else:
color = 3
info_col = dump_tuple(get_theme().COLOR_INFORMATION_TEXT)
spec_col = dump_tuple(get_theme().COLOR_JOIN_CHAR)
char_join = get_theme().CHAR_JOIN
theme = get_theme()
info_col = dump_tuple(theme.COLOR_INFORMATION_TEXT)
spec_col = dump_tuple(theme.COLOR_JOIN_CHAR)
char_join = theme.CHAR_JOIN
if not jid.full:
msg = ('\x19%(color_spec)s}%(spec)s \x19%(color)s}%(nick)s'
'\x19%(info_col)s} joined the room') % {
......@@ -672,7 +676,7 @@ class MucTab(ChatTab):
'color': color,
'jid': jid.full,
'info_col': info_col,
'jid_color': dump_tuple(get_theme().COLOR_MUC_JID),
'jid_color': dump_tuple(theme.COLOR_MUC_JID),
'color_spec': spec_col,
}
self.add_message(msg, typ=2)
......@@ -731,8 +735,9 @@ class MucTab(ChatTab):
else:
by = None
info_col = dump_tuple(get_theme().COLOR_INFORMATION_TEXT)
char_kick = get_theme().CHAR_KICK
theme = get_theme()
info_col = dump_tuple(theme.COLOR_INFORMATION_TEXT)
char_kick = theme.CHAR_KICK
if from_nick == self.own_nick: # we are banned
if by:
......@@ -807,8 +812,9 @@ class MucTab(ChatTab):
reason = presence.xml.find('{%s}x/{%s}item/{%s}reason' %
(NS_MUC_USER, NS_MUC_USER, NS_MUC_USER))
by = None
info_col = dump_tuple(get_theme().COLOR_INFORMATION_TEXT)
char_kick = get_theme().CHAR_KICK
theme = get_theme()
info_col = dump_tuple(theme.COLOR_INFORMATION_TEXT)
char_kick = theme.CHAR_KICK
if actor_elem is not None:
by = actor_elem.get('nick') or actor_elem.get('jid')
if from_nick == self.own_nick: # we are kicked
......@@ -901,8 +907,9 @@ class MucTab(ChatTab):
color = dump_tuple(user.color)
else:
color = 3
info_col = dump_tuple(get_theme().COLOR_INFORMATION_TEXT)
spec_col = dump_tuple(get_theme().COLOR_QUIT_CHAR)
theme = get_theme()
info_col = dump_tuple(theme.COLOR_INFORMATION_TEXT)
spec_col = dump_tuple(theme.COLOR_QUIT_CHAR)
error_leave_txt = ''
if server_initiated:
......@@ -914,18 +921,18 @@ class MucTab(ChatTab):
'room%(error_leave)s') % {
'nick': from_nick,
'color': color,
'spec': get_theme().CHAR_QUIT,
'spec': theme.CHAR_QUIT,
'info_col': info_col,
'color_spec': spec_col,
'error_leave': error_leave_txt,
}
else:
jid_col = dump_tuple(get_theme().COLOR_MUC_JID)
jid_col = dump_tuple(theme.COLOR_MUC_JID)
leave_msg = ('\x19%(color_spec)s}%(spec)s \x19%(color)s}'
'%(nick)s\x19%(info_col)s} (\x19%(jid_col)s}'
'%(jid)s\x19%(info_col)s}) has left the '
'room%(error_leave)s') % {
'spec': get_theme().CHAR_QUIT,
'spec': theme.CHAR_QUIT,
'nick': from_nick,
'color': color,
'jid': jid.full,
......@@ -952,16 +959,17 @@ class MucTab(ChatTab):
color = dump_tuple(user.color)
else:
color = 3
info_col = dump_tuple(get_theme().COLOR_INFORMATION_TEXT)
if from_nick == self.own_nick:
msg = '\x19%(color)s}You\x19%(info_col)s} changed: ' % {
'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT),
'info_col': info_col),
'color': color
}
else:
msg = '\x19%(color)s}%(nick)s\x19%(info_col)s} changed: ' % {
'nick': from_nick,
'color': color,
'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT)
'info_col': info_col)
}
if affiliation != user.affiliation:
msg += 'affiliation: %s, ' % affiliation
......@@ -1496,23 +1504,24 @@ class MucTab(ChatTab):
if not self.joined:
return
theme = get_theme()
aff = {
'owner': get_theme().CHAR_AFFILIATION_OWNER,
'admin': get_theme().CHAR_AFFILIATION_ADMIN,
'member': get_theme().CHAR_AFFILIATION_MEMBER,
'none': get_theme().CHAR_AFFILIATION_NONE,
'owner': theme.CHAR_AFFILIATION_OWNER,
'admin': theme.CHAR_AFFILIATION_ADMIN,
'member': theme.CHAR_AFFILIATION_MEMBER,
'none': theme.CHAR_AFFILIATION_NONE,
}
colors = {}
colors["visitor"] = dump_tuple(get_theme().COLOR_USER_VISITOR)
colors["moderator"] = dump_tuple(get_theme().COLOR_USER_MODERATOR)
colors["participant"] = dump_tuple(get_theme().COLOR_USER_PARTICIPANT)
color_other = dump_tuple(get_theme().COLOR_USER_NONE)
colors["visitor"] = dump_tuple(theme.COLOR_USER_VISITOR)
colors["moderator"] = dump_tuple(theme.COLOR_USER_MODERATOR)
colors["participant"] = dump_tuple(theme.COLOR_USER_PARTICIPANT)
color_other = dump_tuple(theme.COLOR_USER_NONE)
buff = ['Users: %s \n' % len(self.users)]
for user in self.users:
affiliation = aff.get(user.affiliation,
get_theme().CHAR_AFFILIATION_NONE)
theme.CHAR_AFFILIATION_NONE)
color = colors.get(user.role, color_other)
buff.append(
'\x19%s}%s\x19o\x19%s}%s\x19o' %
......
......@@ -345,21 +345,22 @@ class PrivateTab(OneToOneTab):
The user left the associated MUC
"""
self.deactivate()
theme = get_theme()
if config.get_by_tabname('display_user_color_in_join_part',
self.general_jid):
color = dump_tuple(user.color)
else:
color = dump_tuple(get_theme().COLOR_REMOTE_USER)
color = dump_tuple(theme.COLOR_REMOTE_USER)
if not status_message:
self.add_message(
'\x19%(quit_col)s}%(spec)s \x19%(nick_col)s}'
'%(nick)s\x19%(info_col)s} has left the room' % {
'nick': user.nick,
'spec': get_theme().CHAR_QUIT,
'spec': theme.CHAR_QUIT,
'nick_col': color,
'quit_col': dump_tuple(get_theme().COLOR_QUIT_CHAR),
'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT)
'quit_col': dump_tuple(theme.COLOR_QUIT_CHAR),
'info_col': dump_tuple(theme.COLOR_INFORMATION_TEXT)
},
typ=2)
else:
......@@ -369,10 +370,10 @@ class PrivateTab(OneToOneTab):
' (%(status)s)' % {
'status': status_message,
'nick': user.nick,
'spec': get_theme().CHAR_QUIT,
'spec': theme.CHAR_QUIT,
'nick_col': color,
'quit_col': dump_tuple(get_theme().COLOR_QUIT_CHAR),
'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT)
'quit_col': dump_tuple(theme.COLOR_QUIT_CHAR),
'info_col': dump_tuple(theme.COLOR_INFORMATION_TEXT)
},
typ=2)
return self.core.tabs.current_tab is self
......@@ -385,7 +386,8 @@ class PrivateTab(OneToOneTab):
self.activate()
self.check_features()
tab = self.parent_muc
color = dump_tuple(get_theme().COLOR_REMOTE_USER)
theme = get_theme()
color = dump_tuple(theme.COLOR_REMOTE_USER)
if tab and config.get_by_tabname('display_user_color_in_join_part',
self.general_jid):
user = tab.get_user_by_name(nick)
......@@ -396,9 +398,9 @@ class PrivateTab(OneToOneTab):
'%(info_col)s} joined the room' % {
'nick': nick,
'color': color,
'spec': get_theme().CHAR_JOIN,
'join_col': dump_tuple(get_theme().COLOR_JOIN_CHAR),
'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT)
'spec': theme.CHAR_JOIN,
'join_col': dump_tuple(theme.COLOR_JOIN_CHAR),
'info_col': dump_tuple(theme.COLOR_INFORMATION_TEXT)
},
typ=2)
return self.core.tabs.current_tab is self
......@@ -417,12 +419,13 @@ class PrivateTab(OneToOneTab):
return [(3, safeJID(self.name).resource), (4, self.name)]
def add_error(self, error_message):
error = '\x19%s}%s\x19o' % (dump_tuple(get_theme().COLOR_CHAR_NACK),
theme = get_theme()
error = '\x19%s}%s\x19o' % (dump_tuple(theme.COLOR_CHAR_NACK),
error_message)
self.add_message(
error,
highlight=True,
nickname='Error',
nick_color=get_theme().COLOR_ERROR_MSG,
nick_color=theme.COLOR_ERROR_MSG,
typ=2)
self.core.refresh_window()
......@@ -245,9 +245,10 @@ class BookmarksWin(Win):
return
if self.current_input == 0:
return
theme = get_theme()
self.lines[self.current_input][
self.current_horizontal_input].set_color(
get_theme().COLOR_NORMAL_TEXT)
theme.COLOR_NORMAL_TEXT)
self.current_input -= 1
# Adjust the scroll position if the current_input would be outside
# of the visible area
......@@ -256,20 +257,21 @@ class BookmarksWin(Win):
self.refresh()
self.lines[self.current_input][
self.current_horizontal_input].set_color(
get_theme().COLOR_SELECTED_ROW)
theme.COLOR_SELECTED_ROW)
def go_to_next_horizontal_input(self) -> None:
if not self.lines:
return
theme = get_theme()
self.lines[self.current_input][
self.current_horizontal_input].set_color(
get_theme().COLOR_NORMAL_TEXT)
theme.COLOR_NORMAL_TEXT)
self.current_horizontal_input += 1
if self.current_horizontal_input > 3:
self.current_horizontal_input = 0
self.lines[self.current_input][
self.current_horizontal_input].set_color(
get_theme().COLOR_SELECTED_ROW)
theme.COLOR_SELECTED_ROW)
def go_to_next_page(self) -> bool:
if not self.lines:
......@@ -278,9 +280,10 @@ class BookmarksWin(Win):
if self.current_input == len(self.lines) - 1:
return False
theme = get_theme()
self.lines[self.current_input][
self.current_horizontal_input].set_color(
get_theme().COLOR_NORMAL_TEXT)
theme.COLOR_NORMAL_TEXT)
inc = min(self.height, len(self.lines) - self.current_input - 1)
if self.current_input + inc - self.scroll_pos > self.height - 1:
......@@ -291,7 +294,7 @@ class BookmarksWin(Win):
self.current_input += inc
self.lines[self.current_input][
self.current_horizontal_input].set_color(
get_theme().COLOR_SELECTED_ROW)
theme.COLOR_SELECTED_ROW)
return True
def go_to_previous_page(self) -> bool:
......@@ -301,9 +304,10 @@ class BookmarksWin(Win):
if self.current_input == 0:
return False
theme = get_theme()
self.lines[self.current_input][
self.current_horizontal_input].set_color(
get_theme().COLOR_NORMAL_TEXT)
theme.COLOR_NORMAL_TEXT)
dec = min(self.height, self.current_input)
self.current_input -= dec
......@@ -314,7 +318,7 @@ class BookmarksWin(Win):
self.refresh()
self.lines[self.current_input][
self.current_horizontal_input].set_color(
get_theme().COLOR_SELECTED_ROW)
theme.COLOR_SELECTED_ROW)
return True
def go_to_previous_horizontal_input(self) -> None:
......@@ -322,13 +326,14 @@ class BookmarksWin(Win):
return
if self.current_horizontal_input == 0:
return
theme = get_theme()
self.lines[self.current_input][
self.current_horizontal_input].set_color(
get_theme().COLOR_NORMAL_TEXT)
theme.COLOR_NORMAL_TEXT)
self.current_horizontal_input -= 1
self.lines[self.current_input][
self.current_horizontal_input].set_color(
get_theme().COLOR_SELECTED_ROW)
theme.COLOR_SELECTED_ROW)
def on_input(self, key: str) -> None:
if not self.lines:
......
......@@ -438,10 +438,11 @@ class FormWin:
return
if self.current_input == len(self.inputs) - 1:
return
theme = get_theme()
self.inputs[self.current_input]['input'].set_color(
get_theme().COLOR_NORMAL_TEXT)
theme.COLOR_NORMAL_TEXT)
self.inputs[self.current_input]['label'].set_color(
get_theme().COLOR_NORMAL_TEXT)
theme.COLOR_NORMAL_TEXT)
self.current_input += 1
jump = 0
while self.current_input + jump != len(
......@@ -460,19 +461,20 @@ class FormWin:
self.scroll_pos += 1
self.refresh()
self.inputs[self.current_input]['input'].set_color(
get_theme().COLOR_SELECTED_ROW)
theme.COLOR_SELECTED_ROW)
self.inputs[self.current_input]['label'].set_color(
get_theme().COLOR_SELECTED_ROW)
theme.COLOR_SELECTED_ROW)
def go_to_previous_input(self):
if not self.inputs:
return
if self.current_input == 0:
return
theme = get_theme()
self.inputs[self.current_input]['input'].set_color(
get_theme().COLOR_NORMAL_TEXT)
theme.COLOR_NORMAL_TEXT)
self.inputs[self.current_input]['label'].set_color(
get_theme().COLOR_NORMAL_TEXT)
theme.COLOR_NORMAL_TEXT)
self.current_input -= 1
jump = 0
while self.current_input - jump > 0 and self.inputs[self.current_input
......@@ -489,9 +491,9 @@ class FormWin:
self.refresh()
self.current_input -= jump
self.inputs[self.current_input]['input'].set_color(
get_theme().COLOR_SELECTED_ROW)
theme.COLOR_SELECTED_ROW)
self.inputs[self.current_input]['label'].set_color(
get_theme().COLOR_SELECTED_ROW)
theme.COLOR_SELECTED_ROW)
def on_input(self, key, raw=False):
if not self.inputs:
......@@ -521,11 +523,10 @@ class FormWin:
inp['input'].refresh()
inp['label'].refresh()
if self.inputs and self.current_input < self.height - 1:
self.inputs[self.current_input]['input'].set_color(
get_theme().COLOR_SELECTED_ROW)
color = get_theme().COLOR_SELECTED_ROW
self.inputs[self.current_input]['input'].set_color(color)
self.inputs[self.current_input]['input'].refresh()
self.inputs[self.current_input]['label'].set_color(
get_theme().COLOR_SELECTED_ROW)
self.inputs[self.current_input]['label'].set_color(color)
self.inputs[self.current_input]['label'].refresh()
def refresh_current_input(self):
......
......@@ -25,8 +25,9 @@ class GlobalInfoBar(Win):
def refresh(self) -> None:
log.debug('Refresh: %s', self.__class__.__name__)
self._win.erase()
theme = get_theme()
self.addstr(0, 0, "[",
to_curses_attr(get_theme().COLOR_INFORMATION_BAR))
to_curses_attr(theme.COLOR_INFORMATION_BAR))
show_names = config.get('show_tab_names')
show_nums = config.get('show_tab_numbers')
......@@ -37,7 +38,7 @@ class GlobalInfoBar(Win):
if not tab:
continue
color = tab.color
if not show_inactive and color is get_theme().COLOR_TAB_NORMAL:
if not show_inactive and color is theme.COLOR_TAB_NORMAL:
continue
try:
if show_nums or not show_names:
......@@ -51,16 +52,16 @@ class GlobalInfoBar(Win):
else:
self.addstr("%s" % tab.name, to_curses_attr(color))
self.addstr("|",
to_curses_attr(get_theme().COLOR_INFORMATION_BAR))
to_curses_attr(theme.COLOR_INFORMATION_BAR))
except: # end of line
break
(y, x) = self._win.getyx()
self.addstr(y, x - 1, '] ',
to_curses_attr(get_theme().COLOR_INFORMATION_BAR))
to_curses_attr(theme.COLOR_INFORMATION_BAR))
(y, x) = self._win.getyx()
remaining_size = self.width - x
self.addnstr(' ' * remaining_size, remaining_size,
to_curses_attr(get_theme().COLOR_INFORMATION_BAR))
to_curses_attr(theme.COLOR_INFORMATION_BAR))
self._refresh()
......@@ -76,17 +77,17 @@ class VerticalGlobalInfoBar(Win):
height, width = self._win.getmaxyx()
self._win.erase()
sorted_tabs = [tab for tab in self.core.tabs if tab]
theme = get_theme()
if not config.get('show_inactive_tabs'):
sorted_tabs = [
tab for tab in sorted_tabs
if tab.vertical_color != get_theme().COLOR_VERTICAL_TAB_NORMAL
if tab.vertical_color != theme.COLOR_VERTICAL_TAB_NORMAL
]
nb_tabs = len(sorted_tabs)
use_nicks = config.get('use_tab_nicks')
if nb_tabs >= height:
for y, tab in enumerate(sorted_tabs):
if tab.vertical_color == get_theme(
).COLOR_VERTICAL_TAB_CURRENT:
if tab.vertical_color == theme.COLOR_VERTICAL_TAB_CURRENT:
pos = y
break
# center the current tab as much as possible
......@@ -102,14 +103,14 @@ class VerticalGlobalInfoBar(Win):
if asc_sort:
y = height - y - 1
self.addstr(y, 0, "%2d" % tab.nb,
to_curses_attr(get_theme().COLOR_VERTICAL_TAB_NUMBER))
to_curses_attr(theme.COLOR_VERTICAL_TAB_NUMBER))
self.addstr('.')
if use_nicks:
self.addnstr("%s" % tab.get_nick(), width - 4,
to_curses_attr(color))
else:
self.addnstr("%s" % tab.name, width - 4, to_curses_attr(color))
separator = to_curses_attr(get_theme().COLOR_VERTICAL_SEPARATOR)
separator = to_curses_attr(theme.COLOR_VERTICAL_SEPARATOR)
self._win.attron(separator)
self._win.vline(0, width - 1, curses.ACS_VLINE, height)
self._win.attroff(separator)
......
......@@ -94,9 +94,10 @@ class PrivateInfoWin(InfoWin):
def write_room_name(self, name):
jid = safeJID(name)
room_name, nick = jid.bare, jid.resource
self.addstr(nick, to_curses_attr(get_theme().COLOR_PRIVATE_NAME))
theme = get_theme()
self.addstr(nick, to_curses_attr(theme.COLOR_PRIVATE_NAME))
txt = ' from room %s' % room_name
self.addstr(txt, to_curses_attr(get_theme().COLOR_INFORMATION_BAR))
self.addstr(txt, to_curses_attr(theme.COLOR_INFORMATION_BAR))
def write_chatstate(self, state):
if state:
......@@ -119,15 +120,16 @@ class MucListInfoWin(InfoWin):
def refresh(self, name=None, window=None):
log.debug('Refresh: %s', self.__class__.__name__)
self._win.erase()
theme = get_theme()
if name:
self.addstr(name,
to_curses_attr(get_theme().COLOR_INFORMATION_BAR))
to_curses_attr(theme.COLOR_INFORMATION_BAR))
else:
self.addstr(self.message,
to_curses_attr(get_theme().COLOR_INFORMATION_BAR))
to_curses_attr(theme.COLOR_INFORMATION_BAR))
if window:
self.print_scroll_position(window)
self.finish_line(get_theme().COLOR_INFORMATION_BAR)
self.finish_line(theme.COLOR_INFORMATION_BAR)
self._refresh()
......@@ -176,9 +178,9 @@ class ConversationInfoWin(InfoWin):
Write all information added by plugins by getting the
value returned by the callbacks.
"""
color = to_curses_attr(get_theme().COLOR_INFORMATION_BAR)
for plugin in information.values():
self.addstr(plugin(jid),
to_curses_attr(get_theme().COLOR_INFORMATION_BAR))
self.addstr(plugin(jid), color)
def write_resource_information(self, resource):
"""
......@@ -188,38 +190,40 @@ class ConversationInfoWin(InfoWin):
presence = "unavailable"
else:
presence = resource.presence
color = get_theme().color_show(presence)
theme = get_theme()
color = theme.color_show(presence)
if not presence:
presence = get_theme().CHAR_STATUS
self.addstr('[', to_curses_attr(get_theme().COLOR_INFORMATION_BAR))
presence = theme.CHAR_STATUS
self.addstr('[', to_curses_attr(theme.COLOR_INFORMATION_BAR))
self.addstr(presence, to_curses_attr(color))
if resource and resource.status:
shortened = resource.status[:20] + (resource.status[:20] and '…')
self.addstr(' %s' % shortened,
to_curses_attr(get_theme().COLOR_INFORMATION_BAR))
self.addstr(']', to_curses_attr(get_theme().COLOR_INFORMATION_BAR))
to_curses_attr(theme.COLOR_INFORMATION_BAR))
self.addstr(']', to_curses_attr(theme.COLOR_INFORMATION_BAR))
def write_contact_information(self, contact):