diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core.py | 12 | ||||
-rw-r--r-- | src/room.py | 6 | ||||
-rw-r--r-- | src/tabs.py | 42 | ||||
-rw-r--r-- | src/windows.py | 38 | ||||
-rw-r--r-- | src/xhtml.py | 1 |
5 files changed, 65 insertions, 34 deletions
diff --git a/src/core.py b/src/core.py index f707070c..5e2566ff 100644 --- a/src/core.py +++ b/src/core.py @@ -360,13 +360,13 @@ class Core(object): return # If a resource got offline, display the message in the conversation with this # precise resource. - self.add_information_message_to_conversation_tab(jid.full, '\x195%s is \x191offline' % (resource.get_jid().full)) + self.add_information_message_to_conversation_tab(jid.full, '\x195}%s is \x191}offline' % (resource.get_jid().full)) contact.remove_resource(resource) # Display the message in the conversation with the bare JID only if that was # the only resource online (i.e. now the contact is completely disconnected) if not contact.get_highest_priority_resource(): # No resource left: that was the last one - self.add_information_message_to_conversation_tab(jid.bare, '\x195%s is \x191offline' % (jid.bare)) - self.information('\x193%s \x195is \x191offline' % (resource.get_jid().bare), "Roster") + self.add_information_message_to_conversation_tab(jid.bare, '\x195}%s is \x191}offline' % (jid.bare)) + self.information('\x193}%s \x195}is \x191}offline' % (resource.get_jid().bare), "Roster") def on_got_online(self, presence): jid = presence['from'] @@ -384,13 +384,13 @@ class Core(object): resource.set_status(status_message) resource.set_presence(status) resource.set_priority(priority) - self.add_information_message_to_conversation_tab(jid.full, '\x195%s is \x194online' % (jid.full)) + self.add_information_message_to_conversation_tab(jid.full, '\x195}%s is \x194}online' % (jid.full)) if not contact.get_highest_priority_resource(): # No connected resource yet: the user's just connecting if time.time() - self.connection_time > 12: # We do not display messages if we recently logged in - self.information("\x193%s \x195is \x194online\x195 (\x190%s\x195)" % (resource.get_jid().bare, status), "Roster") - self.add_information_message_to_conversation_tab(jid.bare, '\x195%s is \x194online' % (jid.bare)) + self.information("\x193}%s \x195}is \x194}online\x195} (\x190}%s\x195})" % (resource.get_jid().bare, status), "Roster") + self.add_information_message_to_conversation_tab(jid.bare, '\x195%s is \x194}online' % (jid.bare)) contact.add_resource(resource) def add_information_message_to_conversation_tab(self, jid, msg): diff --git a/src/room.py b/src/room.py index 37b0de66..b97dd0b6 100644 --- a/src/room.py +++ b/src/room.py @@ -101,7 +101,7 @@ class Room(TextBuffer): self.log_message(txt, time, nickname) special_message = False if txt.startswith('/me '): - txt = "\x192* \x195" + nickname + ' ' + txt[4:] + txt = "\x192}* \x195}" + nickname + ' ' + txt[4:] special_message = True user = self.get_user_by_name(nickname) if nickname is not None else None if user: @@ -115,13 +115,13 @@ class Room(TextBuffer): self.set_color_state(get_theme().COLOR_TAB_NEW_MESSAGE) nick_color = nick_color or None if not nickname or time: - txt = '\x195%s' % (txt,) + txt = '\x195}%s' % (txt,) else: # TODO highlight = self.do_highlight(txt, time, nickname) if highlight: nick_color = highlight if special_message: - txt = '\x195%s' % (txt,) + txt = '\x195}%s' % (txt,) nickname = None time = time or datetime.now() message = Message(txt='%s\x19o'%(txt.replace('\t', ' '),), nick_color=nick_color, diff --git a/src/tabs.py b/src/tabs.py index e4cbf99b..88d8ad7f 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -801,9 +801,9 @@ class MucTab(ChatTab): room.joined = True self.send_chat_state('active') new_user.color = get_theme().COLOR_OWN_NICK - room.add_message(_("\x195Your nickname is \x193%s") % (from_nick)) + room.add_message(_("\x195}Your nickname is \x193}%s") % (from_nick)) if '170' in status_codes: - room.add_message('\x191Warning: \x195this room is publicly logged') + room.add_message('\x191}Warning: \x195}this room is publicly logged') else: change_nick = '303' in status_codes kick = '307' in status_codes and typ == 'unavailable' @@ -842,9 +842,9 @@ class MucTab(ChatTab): hide_exit_join = config.get('hide_exit_join', -1) if hide_exit_join != 0: if not jid.full: - room.add_message('\x194%(spec)s \x193%(nick)s\x195 joined the room' % {'nick':from_nick, 'spec':get_theme().CHAR_JOIN}) + room.add_message('\x194}%(spec)s \x193}%(nick)s\x195} joined the room' % {'nick':from_nick, 'spec':get_theme().CHAR_JOIN}) else: - room.add_message('\x194%(spec)s \x193%(nick)s \x195(\x194%(jid)s\x195) joined the room' % {'spec':get_theme().CHAR_JOIN, 'nick':from_nick, 'jid':jid.full}) + room.add_message('\x194}%(spec)s \x193}%(nick)s \x195}(\x194}%(jid)s\x195}) joined the room' % {'spec':get_theme().CHAR_JOIN, 'nick':from_nick, 'jid':jid.full}) self.core.on_user_rejoined_private_conversation(room.name, from_nick) @@ -857,7 +857,7 @@ class MucTab(ChatTab): if isinstance(_tab, PrivateTab) and JID(_tab.get_name()).bare == room.name: _tab.get_room().own_nick = new_nick user.change_nick(new_nick) - room.add_message('\x193%(old)s\x195 is now known as \x193%(new)s' % {'old':from_nick, 'new':new_nick}) + room.add_message('\x193}%(old)s\x195} is now known as \x193}%(new)s' % {'old':from_nick, 'new':new_nick}) # rename the private tabs if needed self.core.rename_private_tabs(room.name, from_nick, new_nick) @@ -875,16 +875,16 @@ class MucTab(ChatTab): self.tab_win.refresh() self.core.doupdate() if by: - kick_msg = _('\x191%(spec)s \x193You\x195 have been banned by \x194%(by)s') % {'spec': get_theme().CHAR_KICK, 'by':by} + kick_msg = _('\x191}%(spec)s \x193}You\x195} have been banned by \x194}%(by)s') % {'spec': get_theme().CHAR_KICK, 'by':by} else: - kick_msg = _('\x191%(spec)s \x193You\x195 have been banned.') % {'spec':get_theme().CHAR_KICK} + kick_msg = _('\x191}%(spec)s \x193}You\x195} have been banned.') % {'spec':get_theme().CHAR_KICK} else: if by: - kick_msg = _('\x191%(spec)s \x193%(nick)s\x195 has been banned by \x194%(by)s') % {'spec':get_theme().CHAR_KICK, 'nick':from_nick, 'by':by} + kick_msg = _('\x191}%(spec)s \x193}%(nick)s\x195} has been banned by \x194}%(by)s') % {'spec':get_theme().CHAR_KICK, 'nick':from_nick, 'by':by} else: - kick_msg = _('\x191%(spec)s \x193%(nick)s\x195 has been banned') % {'spec':get_theme().CHAR_KICK, 'nick':from_nick.replace('"', '\\"')} + kick_msg = _('\x191}%(spec)s \x193}%(nick)s\x195 has been banned') % {'spec':get_theme().CHAR_KICK, 'nick':from_nick.replace('"', '\\"')} if reason is not None and reason.text: - kick_msg += _('\x195 Reason: \x196%(reason)s\x195') % {'reason': reason.text} + kick_msg += _('\x195} Reason: \x196}%(reason)s\x195}') % {'reason': reason.text} room.add_message(kick_msg) def on_user_kicked(self, room, presence, user, from_nick): @@ -901,19 +901,19 @@ class MucTab(ChatTab): self.tab_win.refresh() self.core.doupdate() if by: - kick_msg = _('\x191%(spec)s \x193You\x195 have been kicked by \x193%(by)s') % {'spec': get_theme().CHAR_KICK, 'by':by} + kick_msg = _('\x191}%(spec)s \x193}You\x195} have been kicked by \x193}%(by)s') % {'spec': get_theme().CHAR_KICK, 'by':by} else: - kick_msg = _('\x191%(spec)s \x193You\x195 have been kicked.') % {'spec':get_theme().CHAR_KICK} + kick_msg = _('\x191}%(spec)s \x193}You\x195} have been kicked.') % {'spec':get_theme().CHAR_KICK} # try to auto-rejoin if config.get('autorejoin', 'false') == 'true': muc.join_groupchat(self.core.xmpp, room.name, room.own_nick) else: if by: - kick_msg = _('\x191%(spec)s \x193%(nick)s\x195 has been kicked by \x193%(by)s') % {'spec':get_theme().CHAR_KICK.replace('"', '\\"'), 'nick':from_nick.replace('"', '\\"'), 'by':by.replace('"', '\\"')} + kick_msg = _('\x191}%(spec)s \x193}%(nick)s\x195} has been kicked by \x193}%(by)s') % {'spec':get_theme().CHAR_KICK.replace('"', '\\"'), 'nick':from_nick.replace('"', '\\"'), 'by':by.replace('"', '\\"')} else: - kick_msg = _('\x191%(spec)s \x193%(nick)s\x195 has been kicked') % {'spec':get_theme().CHAR_KICK, 'nick':from_nick.replace('"', '\\"')} + kick_msg = _('\x191}%(spec)s \x193}%(nick)s\x195} has been kicked') % {'spec':get_theme().CHAR_KICK, 'nick':from_nick.replace('"', '\\"')} if reason is not None and reason.text: - kick_msg += _('\x195 Reason: \x196%(reason)s') % {'reason': reason.text} + kick_msg += _('\x195} Reason: \x196}%(reason)s') % {'reason': reason.text} room.add_message(kick_msg) def on_user_leave_groupchat(self, room, user, jid, status, from_nick, from_room): @@ -930,9 +930,9 @@ class MucTab(ChatTab): hide_exit_join = config.get('hide_exit_join', -1) if config.get('hide_exit_join', -1) >= -1 else -1 if hide_exit_join == -1 or user.has_talked_since(hide_exit_join): if not jid.full: - leave_msg = _('\x191%(spec)s \x193%(nick)s\x195 has left the room') % {'nick':from_nick, 'spec':get_theme().CHAR_QUIT} + leave_msg = _('\x191}%(spec)s \x193}%(nick)s\x195} has left the room') % {'nick':from_nick, 'spec':get_theme().CHAR_QUIT} else: - leave_msg = _('\x191%(spec)s \x193%(nick)s\x195 (\x194%(jid)s\x195) has left the room') % {'spec':get_theme().CHAR_QUIT, 'nick':from_nick, 'jid':jid.full} + leave_msg = _('\x191}%(spec)s \x193}%(nick)s\x195} (\x194}%(jid)s\x195}) has left the room') % {'spec':get_theme().CHAR_QUIT, 'nick':from_nick, 'jid':jid.full} if status: leave_msg += ' (%s)' % status room.add_message(leave_msg) @@ -946,7 +946,7 @@ class MucTab(ChatTab): # build the message display_message = False # flag to know if something significant enough # to be displayed has changed - msg = _('\x193%s\x195 changed: ')% from_nick.replace('"', '\\"') + msg = _('\x193}%s\x195} changed: ')% from_nick.replace('"', '\\"') if show not in SHOW_NAME: self.core.information("%s from room %s sent an invalid show: %s" %\ (from_nick, from_room, show), "warning") @@ -1125,9 +1125,9 @@ class PrivateTab(ChatTab): The user left the associated MUC """ if not status_message: - self.get_room().add_message(_('\x191%(spec)s \x193%(nick)s\x195 has left the room') % {'nick':from_nick.replace('"', '\\"'), 'spec':get_theme().CHAR_QUIT.replace('"', '\\"')}) + self.get_room().add_message(_('\x191}%(spec)s \x193}%(nick)s\x195} has left the room') % {'nick':from_nick.replace('"', '\\"'), 'spec':get_theme().CHAR_QUIT.replace('"', '\\"')}) else: - self.get_room().add_message(_('\x191%(spec)s \x193%(nick)s\x195 has left the room (%(status)s)"') % {'nick':from_nick.replace('"', '\\"'), 'spec':get_theme().CHAR_QUIT, 'status': status_message.replace('"', '\\"')}) + self.get_room().add_message(_('\x191}%(spec)s \x193}%(nick)s\x195} has left the room (%(status)s)"') % {'nick':from_nick.replace('"', '\\"'), 'spec':get_theme().CHAR_QUIT, 'status': status_message.replace('"', '\\"')}) self.deactivate() self.refresh() self.core.doupdate() @@ -1136,7 +1136,7 @@ class PrivateTab(ChatTab): """ The user (or at least someone with the same nick) came back in the MUC """ - self.get_room().add_message('\x194%(spec)s \x193%(nick)s\x195 joined the room' % {'nick':nick, 'spec':get_theme().CHAR_JOIN}) + self.get_room().add_message('\x194}%(spec)s \x193}%(nick)s\x195} joined the room' % {'nick':nick, 'spec':get_theme().CHAR_JOIN}) self.activate() self.refresh() self.core.doupdate() diff --git a/src/windows.py b/src/windows.py index a0751c29..2352a82a 100644 --- a/src/windows.py +++ b/src/windows.py @@ -40,6 +40,7 @@ import collections from theming import get_theme, to_curses_attr +allowed_color_digits = ('0', '1', '2', '3', '4', '5', '6', '7') # msg is a reference to the corresponding Message tuple. text_start and text_end are the position # delimiting the text in this line. # first is a bool telling if this is the first line of the message. @@ -112,7 +113,7 @@ class Win(object): attributes as they are in the string. For example: \x19bhello → hello in bold - \xc1Bonj\xc2our → 'Bonj' in red and 'our' in green + \x191}Bonj\x192}our → 'Bonj' in red and 'our' in green next_attr_char is the \x19 delimiter attr_char is the char following it, it can be one of 'u', 'b', 'c[0-9]' @@ -120,6 +121,37 @@ class Win(object): if y is not None and x is not None: self.move(y, x) next_attr_char = text.find('\x19') + while next_attr_char != -1 and text: + log.debug('Addstr_Colored: [%s]' % text.replace('\x19', '\\x19')) + if next_attr_char + 1 < len(text): + attr_char = text[next_attr_char+1].lower() + else: + attr_char = str() + if next_attr_char != 0: + self.addstr(text[:next_attr_char]) + if attr_char == 'o': + self._win.attrset(0) + elif attr_char == 'u': + self._win.attron(curses.A_UNDERLINE) + elif attr_char == 'b': + self._win.attron(curses.A_BOLD) + if attr_char in string.digits and attr_char != '': + color_str = text[next_attr_char+1:text.find('}', next_attr_char)] + self._win.attron(to_curses_attr((int(color_str), -1))) + text = text[next_attr_char+len(color_str)+2:] + else: + text = text[next_attr_char+2:] + next_attr_char = text.find('\x19') + self.addstr(text) + + def addstr_colored_lite(self, text, y=None, x=None): + """ + Just like addstr_colored, but only handles colors with one digit. + \x193 is the 3rd color. We do not use any } char in this version + """ + if y is not None and x is not None: + self.move(y, x) + next_attr_char = text.find('\x19') while next_attr_char != -1: if next_attr_char + 1 < len(text): attr_char = text[next_attr_char+1].lower() @@ -1101,7 +1133,7 @@ class MessageInput(Input): Read one more char (c) and add \x19c to the string """ attr_char = self.core.read_keyboard()[0] - if attr_char in self.text_attributes or (attr_char in string.digits and int(attr_char) < 7): + if attr_char in self.text_attributes or attr_char in allowed_color_digits: self.do_command('\x19', False) self.do_command(attr_char) @@ -1142,7 +1174,7 @@ class MessageInput(Input): self._win.attron(to_curses_attr(self.color)) displayed_text = text[self.line_pos:self.line_pos+self.width-1] self._win.attrset(0) - self.addstr_colored(displayed_text) + self.addstr_colored_lite(displayed_text) self.addstr(0, wcwidth.wcswidth(displayed_text[:self.pos]), '') if self.color: self._win.attroff(to_curses_attr(self.color)) diff --git a/src/xhtml.py b/src/xhtml.py index fd50bb11..949044b1 100644 --- a/src/xhtml.py +++ b/src/xhtml.py @@ -378,7 +378,6 @@ def poezio_colors_to_html(string): res += "</p></body>" return res.replace('\n', '<br />') - def poezio_colors_to_xhtml(string): """ Generate a valid xhtml string from |