From 0ae1ee2fbf0b3b10fbaaa12e7f340f2aedce3621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9lestin=20Matte?= Date: Tue, 23 Dec 2014 18:20:33 +0100 Subject: Add nick_color_aliases (default: true), to look for color of aliases --- data/default_config.cfg | 3 +++ doc/source/configuration.rst | 10 +++++++++- src/config.py | 1 + src/tabs/muctab.py | 22 +++++++++++++++++++--- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/data/default_config.cfg b/data/default_config.cfg index 08afa452..66c4d8ce 100644 --- a/data/default_config.cfg +++ b/data/default_config.cfg @@ -374,6 +374,9 @@ user_list_sort = desc # If the MUC nicks should receive a fixed color based on their text or not deterministic_nick_colors = true +# If _nick, nick_, _nick_, nick__ etc. should have the same color as nick +nick_color_aliases = true + # The nick of people who join, part, change their status, etc. in a MUC will # be displayed using their nick color if true. display_user_color_in_join_part = true diff --git a/doc/source/configuration.rst b/doc/source/configuration.rst index 8d82f4bd..219db9a3 100644 --- a/doc/source/configuration.rst +++ b/doc/source/configuration.rst @@ -528,6 +528,15 @@ or the way messages are displayed. The value of this option affects the behavior of :term:`/recolor`. + nick_color_aliases + + **Default value:** ``true`` + + Automatically search for color of nick aliases. For example, if nick is + set to red, _nick, nick_, _nick_, nick__ etc. will have the same color. + Aliases colors are checked first, so that it is still possible to have + different colors for nick_ and nick. + vertical_tab_list_size **Default value:** ``20`` @@ -755,7 +764,6 @@ or the way messages are displayed. be displayed in that color. This color won't be changed by the recolor command. - User Interaction ~~~~~~~~~~~~~~~~ diff --git a/src/config.py b/src/config.py index 068f8325..43b88c98 100644 --- a/src/config.py +++ b/src/config.py @@ -43,6 +43,7 @@ DEFAULT_CONFIG = { 'custom_port': '', 'default_nick': '', 'deterministic_nick_colors': True, + 'nick_color_aliases': True, 'display_activity_notifications': False, 'display_gaming_notifications': False, 'display_mood_notifications': False, diff --git a/src/tabs/muctab.py b/src/tabs/muctab.py index 89cecca8..7264569a 100644 --- a/src/tabs/muctab.py +++ b/src/tabs/muctab.py @@ -426,7 +426,7 @@ class MucTab(ChatTab): for user in self.users: if user.nick == self.own_nick: continue - color = config.get_by_tabname(user.nick, 'muc_colors') + color = self.search_for_color(user.nick) if color != '': continue user.set_deterministic_color() @@ -444,7 +444,7 @@ class MucTab(ChatTab): # search our own user, to remove it from the list # Also remove users whose color is fixed for user in full_sorted_users: - color = config.get_by_tabname(user.nick, 'muc_colors') + color = self.search_for_color(user.nick) if user.nick == self.own_nick: sorted_users.remove(user) user.color = get_theme().COLOR_OWN_NICK @@ -1068,7 +1068,7 @@ class MucTab(ChatTab): jid = presence['muc']['jid'] typ = presence['type'] deterministic = config.get_by_tabname('deterministic_nick_colors', self.name) - color = config.get_by_tabname(from_nick, 'muc_colors') + color = self.search_for_color(from_nick) if not self.joined: # user in the room BEFORE us. # ignore redondant presence message, see bug #1509 if (from_nick not in [user.nick for user in self.users] @@ -1670,3 +1670,19 @@ class MucTab(ChatTab): self.core.refresh_window() else: # Re-send a self-ping in a few seconds self.enable_self_ping_event() + + def search_for_color(self, nick): + """ + Search for the color of a nick in the config file. + Also, look at the colors of its possible aliases if nick_color_aliases + is set. + """ + color = config.get_by_tabname(nick, 'muc_colors') + if color != '': + return color + nick_color_aliases = config.get_by_tabname('nick_color_aliases', self.name) + if nick_color_aliases: + nick_alias = re.sub('^_*', '', nick) + nick_alias = re.sub('_*$', '', nick_alias) + color = config.get_by_tabname(nick_alias, 'muc_colors') + return color -- cgit v1.2.3