summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2011-11-06 19:24:37 +0100
committerFlorent Le Coz <louiz@louiz.org>2011-11-06 19:24:37 +0100
commit6a0ac419c5c1d259171a5d49e323f23cd181462c (patch)
tree1c18c4bb890cd9b2ea425bdc67c4feff52f9e99c
parent07f9fab401f34753d0619ebb8d65f6f9df97931d (diff)
parent0315b05f5122f1f4697699fc09de1b0860203177 (diff)
downloadpoezio-6a0ac419c5c1d259171a5d49e323f23cd181462c.tar.gz
poezio-6a0ac419c5c1d259171a5d49e323f23cd181462c.tar.bz2
poezio-6a0ac419c5c1d259171a5d49e323f23cd181462c.tar.xz
poezio-6a0ac419c5c1d259171a5d49e323f23cd181462c.zip
Merge branch 'master' into plugins
-rw-r--r--src/core.py2
-rw-r--r--src/tabs.py5
-rw-r--r--src/xhtml.py39
3 files changed, 14 insertions, 32 deletions
diff --git a/src/core.py b/src/core.py
index d9d0b00e..aab82768 100644
--- a/src/core.py
+++ b/src/core.py
@@ -617,7 +617,7 @@ class Core(object):
if not body:
return
tab.add_message(body, time=None, nickname=nick_from,
- forced_user=self.get_tab_by_name(room_from, tabs.MucTab).get_user_by_name(nick_from))
+ forced_user=self.get_tab_by_name(room_from, tabs.MucTab).get_user_by_name(nick_from))
conversation = self.get_tab_by_name(jid.full, tabs.PrivateTab)
if conversation and conversation.remote_wants_chatstates is None:
if message['chat_state']:
diff --git a/src/tabs.py b/src/tabs.py
index 63b1628f..78f56bdb 100644
--- a/src/tabs.py
+++ b/src/tabs.py
@@ -1217,7 +1217,7 @@ class PrivateTab(ChatTab):
needed = 'inactive' if self.core.status.show in ('xa', 'away') else 'active'
msg['chat_state'] = needed
msg.send()
- self.core.add_message_to_text_buffer(self._text_buffer, line, None, self.core.own_nick or self.own_nick)
+ self.core.add_message_to_text_buffer(self._text_buffer, xhtml.convert_simple_to_full_colors(line), None, self.core.own_nick or self.own_nick)
self.cancel_paused_delay()
self.text_win.refresh()
self.input.refresh()
@@ -1579,7 +1579,6 @@ class RosterInfoTab(Tab):
self.command_add(jid.lstrip('\n'))
self.core.information('Contacts imported from %s' % filepath, 'Info')
-
def command_export(self, arg):
"""
Export the contacts
@@ -1881,7 +1880,7 @@ class ConversationTab(ChatTab):
needed = 'inactive' if self.core.status.show in ('xa', 'away') else 'active'
msg['chat_state'] = needed
msg.send()
- self.core.add_message_to_text_buffer(self._text_buffer, line, None, self.core.own_nick)
+ self.core.add_message_to_text_buffer(self._text_buffer, xhtml.convert_simple_to_full_colors(line), None, self.core.own_nick)
logger.log_message(JID(self.get_name()).bare, self.core.own_nick, line)
self.cancel_paused_delay()
self.text_win.refresh()
diff --git a/src/xhtml.py b/src/xhtml.py
index 38239d18..f6487905 100644
--- a/src/xhtml.py
+++ b/src/xhtml.py
@@ -178,6 +178,8 @@ whitespace_re = re.compile(r'\s+')
xhtml_attr_re = re.compile(r'\x19\d{0,3}\}|\x19[buaio]')
+xhtml_simple_attr_re = re.compile(r'\x19\d')
+
def get_body_from_message_stanza(message):
"""
Returns a string with xhtml markups converted to
@@ -342,6 +344,15 @@ def clean_text_simple(string):
pos = string.find('\x19')
return string
+def convert_simple_to_full_colors(text):
+ """
+ takes a \x19n formatted string and returns
+ a \x19n} formatted one.
+ """
+ def add_curly_bracket(match):
+ return match.group(0) + '}'
+ return re.sub(xhtml_simple_attr_re, add_curly_bracket, text)
+
number_to_color_names = {
1: 'red',
2: 'green',
@@ -394,31 +405,3 @@ def poezio_colors_to_html(string):
res += '</%s>' % (elem,)
res += "</p></body>"
return res.replace('\n', '<br />')
-
-def poezio_colors_to_xhtml(string):
- """
- Generate a valid xhtml string from
- the poezio colors in the given string
- """
- res = "<body xmlns='http://www.w3.org/1999/xhtml'>"
- next_attr_char = string.find('\x19')
- open_elements = []
- while next_attr_char != -1:
- attr_char = string[next_attr_char+1].lower()
- if next_attr_char != 0:
- res += string[:next_attr_char]
- string = string[next_attr_char+2:]
- if attr_char == 'o':
- # close all opened elements
- for elem in open_elements:
- res += '</%s>'
- open_elements = []
- elif attr_char == 'b':
- if 'strong' not in open_elements:
- res += '<strong>'
- open_elements.append('strong')
- elif attr_char in digits:
- self._win.attron(common.curses_color_pair(int(attr_char)))
- next_attr_char = string.find('\x19')
-
-