From 8b8128c416001d520b5b5a2028849def6e6170e4 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sun, 6 Nov 2011 16:26:27 +0100 Subject: Fixes #2286 (with /info) --- src/tabs.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src') diff --git a/src/tabs.py b/src/tabs.py index 1209038c..b4e0cf1d 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -1859,6 +1859,7 @@ class ConversationTab(ChatTab): self.commands['unquery'] = (self.command_unquery, _("Usage: /unquery\nUnquery: close the tab"), None) self.commands['close'] = (self.command_unquery, _("Usage: /close\Close: close the tab"), None) self.commands['version'] = (self.command_version, _('Usage: /version\nVersion: get the software version of the current interlocutor (usually its XMPP client and Operating System)'), None) + self.commands['info'] = (self.command_info, _('Usage: /info\nInfo: get the status of the contact.'), None) self.resize() def completion(self): @@ -1882,6 +1883,18 @@ class ConversationTab(ChatTab): self.text_win.refresh() self.input.refresh() + def command_info(self, arg): + contact = roster.get_contact_by_jid(self.get_name()) + jid = JID(self.get_name()) + if jid.resource: + resource = contact.get_resource_by_fulljid(jid.full) + else: + resource = contact.get_highest_priority_resource() + if resource: + self._text_buffer.add_message("\x195}Status: %s\x193}" %resource.get_status(), None, None, None, None, None) + self.refresh() + self.core.doupdate() + def command_unquery(self, arg): self.core.close_tab() -- cgit v1.2.3 From b9c6f08a790358c990462287bed2062257c5ba7a Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Sun, 6 Nov 2011 16:50:10 +0100 Subject: =?UTF-8?q?Wasn=E2=80=99t=20that=20already=20remove,=20like,=20TWI?= =?UTF-8?q?CE=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core.py | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src') diff --git a/src/core.py b/src/core.py index 8c4ad258..c1220e4b 100644 --- a/src/core.py +++ b/src/core.py @@ -124,7 +124,6 @@ class Core(object): 'connect': (self.command_reconnect, _('Usage: /connect\nConnect: disconnect from the remote server if you are currently connected and then connect to it again'), None), 'server_cycle': (self.command_server_cycle, _('Usage: /server_cycle [domain] [message]\nServer Cycle: disconnect and reconnects in all the rooms in domain.'), None), 'bind': (self.command_bind, _('Usage: /bind \nBind: bind a key to an other key or to a “command”. For example "/bind ^H KEY_UP" makes Control + h do the same same than the Up key.'), None), -# nope 'pubsub': (self.command_pubsub, _('Usage: /pubsub \nPubsub: Open a pubsub browser on the given domain'), None), } self.key_func = { @@ -144,7 +143,6 @@ class Core(object): 'M-z': self.go_to_previous_tab, '^L': self.full_screen_redraw, 'M-j': self.go_to_room_number, -# 'M-c': self.coucou, } # Add handlers @@ -170,9 +168,6 @@ class Core(object): self.timed_events = set() - def coucou(self): - self.command_pubsub('pubsub.louiz.org') - def start(self): """ Init curses, create the first tab, etc @@ -206,7 +201,6 @@ class Core(object): self.information_win.resize(self.information_win_size, tabs.Tab.width, tabs.Tab.height - 2 - self.information_win_size, 0) - def resize_global_info_bar(self): """ Resize the GlobalInfoBar only once at each resize -- cgit v1.2.3 From 200019574d66c1a04d25e23eb0a0fcda7c25f445 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Sun, 6 Nov 2011 17:08:40 +0100 Subject: Use threads RLock to avoid crash on simultaneous refresh and resize. fixes #2180 --- src/core.py | 13 +++++++------ src/windows.py | 23 +++++++++++++---------- 2 files changed, 20 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/core.py b/src/core.py index c1220e4b..29748f4b 100644 --- a/src/core.py +++ b/src/core.py @@ -45,6 +45,7 @@ from contact import Contact, Resource from text_buffer import TextBuffer from keyboard import read_char from theming import get_theme +from windows import g_lock # http://xmpp.org/extensions/xep-0045.html#errorstatus ERROR_AND_STATUS_CODES = { @@ -67,8 +68,6 @@ possible_show = {'available':None, 'xa':'xa' } -resize_lock = threading.Lock() - Status = collections.namedtuple('Status', 'show message') class Core(object): @@ -198,14 +197,16 @@ class Core(object): """ Resize the global_information_win only once at each resize. """ - self.information_win.resize(self.information_win_size, tabs.Tab.width, - tabs.Tab.height - 2 - self.information_win_size, 0) + with g_lock: + self.information_win.resize(self.information_win_size, tabs.Tab.width, + tabs.Tab.height - 2 - self.information_win_size, 0) def resize_global_info_bar(self): """ Resize the GlobalInfoBar only once at each resize """ - self.tab_win.resize(1, tabs.Tab.width, tabs.Tab.height - 2, 0) + with g_lock: + self.tab_win.resize(1, tabs.Tab.width, tabs.Tab.height - 2, 0) def on_exception(self, typ, value, trace): """ @@ -692,7 +693,7 @@ class Core(object): tabs.Tab.resize(self.stdscr) self.resize_global_information_win() self.resize_global_info_bar() - with resize_lock: + with g_lock: for tab in self.tabs: if config.get('lazy_resize', 'true') == 'true': tab.need_resize = True diff --git a/src/windows.py b/src/windows.py index 42c9bfa0..790dd858 100644 --- a/src/windows.py +++ b/src/windows.py @@ -24,7 +24,7 @@ import curses import string from config import config -from threading import Lock +from threading import RLock from contact import Contact, Resource from roster import RosterGroup, roster @@ -46,7 +46,7 @@ allowed_color_digits = ('0', '1', '2', '3', '4', '5', '6', '7') # first is a bool telling if this is the first line of the message. Line = collections.namedtuple('Line', 'msg start_pos end_pos') -g_lock = Lock() +g_lock = RLock() LINES_NB_LIMIT = 4096 @@ -79,7 +79,8 @@ class Win(object): """ Override if something has to be done on resize """ - self._resize(height, width, y, x) + with g_lock: + self._resize(height, width, y, x) def _refresh(self): self._win.noutrefresh() @@ -255,10 +256,11 @@ class UserList(Win): self._refresh() def resize(self, height, width, y, x): - self._resize(height, width, y, x) - self._win.attron(to_curses_attr(get_theme().COLOR_VERTICAL_SEPARATOR)) - self._win.vline(0, 0, curses.ACS_VLINE, self.height) - self._win.attroff(to_curses_attr(get_theme().COLOR_VERTICAL_SEPARATOR)) + with g_lock: + self._resize(height, width, y, x) + self._win.attron(to_curses_attr(get_theme().COLOR_VERTICAL_SEPARATOR)) + self._win.vline(0, 0, curses.ACS_VLINE, self.height) + self._win.attroff(to_curses_attr(get_theme().COLOR_VERTICAL_SEPARATOR)) class Topic(Win): def __init__(self): @@ -674,9 +676,10 @@ class TextWin(Win): self.addstr(' ') def resize(self, height, width, y, x, room=None): - self._resize(height, width, y, x) - if room: - self.rebuild_everything(room) + with g_lock: + self._resize(height, width, y, x) + if room: + self.rebuild_everything(room) def rebuild_everything(self, room): self.built_lines = [] -- cgit v1.2.3 From 7d861ee88514b38081f748a2b9f844eb56c6c349 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Sun, 6 Nov 2011 17:31:56 +0100 Subject: Fix another thing related to Room removale --- src/tabs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/tabs.py b/src/tabs.py index b4e0cf1d..79412158 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -305,7 +305,7 @@ class ChatTab(Tab): # build the list of the recent words char_we_dont_want = string.punctuation+' ' words = list() - for msg in self.messages[:-40:-1]: + for msg in self._text_buffer.messages[:-40:-1]: if not msg: continue txt = xhtml.clean_text(msg.txt) @@ -494,7 +494,7 @@ class MucTab(ChatTab): """ /clear """ - self.messages = [] + self._text_buffer.messages = [] self.text_win.rebuild_everything(self._text_buffer) self.refresh() self.core.doupdate() -- cgit v1.2.3 From 0315b05f5122f1f4697699fc09de1b0860203177 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Sun, 6 Nov 2011 19:21:59 +0100 Subject: Fix the sending of colors in private. fixes #2287 --- src/core.py | 2 +- src/tabs.py | 5 ++--- src/xhtml.py | 39 +++++++++++---------------------------- 3 files changed, 14 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/core.py b/src/core.py index 29748f4b..dd320022 100644 --- a/src/core.py +++ b/src/core.py @@ -546,7 +546,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 79412158..afc93a9d 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -1213,7 +1213,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() @@ -1575,7 +1575,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 @@ -1877,7 +1876,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 += '' % (elem,) res += "

" return res.replace('\n', '
') - -def poezio_colors_to_xhtml(string): - """ - Generate a valid xhtml string from - the poezio colors in the given string - """ - res = "" - 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 += '' - open_elements = [] - elif attr_char == 'b': - if 'strong' not in open_elements: - res += '' - 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') - - -- cgit v1.2.3 From 04f103b9e67ccd1de7376be4f7b5156ec425e99c Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Mon, 7 Nov 2011 19:43:13 +0100 Subject: Add a function to convert ncurses colors to HTML color code. --- src/xhtml.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/xhtml.py b/src/xhtml.py index f6487905..2cedba7d 100644 --- a/src/xhtml.py +++ b/src/xhtml.py @@ -14,6 +14,7 @@ poezio colors to xhtml code import re import subprocess +import curses from sleekxmpp.xmlstream import ET from xml.etree.ElementTree import ElementTree from sys import version_info @@ -192,6 +193,29 @@ def get_body_from_message_stanza(message): return xhtml_to_poezio_colors(xhtml_body) return message['body'] +def ncurses_color_to_html(color): + """ + Takes an int between 0 and 256 and returns + a string of the form #XXXXXX representing an + html color. + """ + if color <= 15: + (r, g, b) = curses.color_content(color) + r = r / 1000 * 6 + g = g / 1000 * 6 + b = b / 1000 * 6 + elif color <= 231: + color = color - 16 + r = color % 6 + color = color / 6 + g = color % 6 + color = color / 6 + b = color % 6 + else: + color -= 232 + r = g = b = color / 24 * 6 + return '#%X%X%X' % (r*256/6, g*256/6, b*256/6) + def xhtml_to_poezio_colors(text): def parse_css(css): def get_color(value): @@ -324,7 +348,6 @@ def xhtml_to_poezio_colors(text): message += trim(elem.tail) return message - def clean_text(s): """ Remove all xhtml-im attributes (\x19etc) from the string with the -- cgit v1.2.3 From 17e5411d8f050a3c5e5bcd010551eecac96b5911 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Mon, 7 Nov 2011 19:47:16 +0100 Subject: use only full color mode when sending messages. Simple color mode should never be used in any part of the code except inside the input. --- src/tabs.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/tabs.py b/src/tabs.py index 7a968740..cae188ae 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -323,7 +323,7 @@ class ChatTab(Tab): if not self.execute_command(clean_text): if txt.startswith('//'): txt = txt[1:] - self.command_say(txt) + self.command_say(xhtml.convert_simple_to_full_colors(txt)) self.cancel_paused_delay() def send_chat_state(self, state, always_send=False): @@ -601,7 +601,7 @@ class MucTab(ChatTab): r = self.core.open_private_window(self.name, user.nick) if r and len(args) > 1: msg = arg[len(nick)+1:] - self.core.current_tab().command_say(msg) + self.core.current_tab().command_say(xhtml.convert_simple_to_full_colors(msg)) if not r: self.core.information(_("Cannot find user: %s" % nick), 'Error') @@ -718,7 +718,7 @@ class MucTab(ChatTab): if line.find('\x19') == -1: msg['body'] = line else: - msg['body'] = xhtml.clean_text_simple(line) + msg['body'] = xhtml.clean_text(line) msg['xhtml_im'] = xhtml.poezio_colors_to_html(line) if config.get('send_chat_states', 'true') == 'true' and self.remote_wants_chatstates is not False: msg['chat_state'] = needed @@ -1211,7 +1211,7 @@ class PrivateTab(ChatTab): if line.find('\x19') == -1: msg['body'] = line else: - msg['body'] = xhtml.clean_text_simple(line) + msg['body'] = xhtml.clean_text(line) msg['xhtml_im'] = xhtml.poezio_colors_to_html(line) if config.get('send_chat_states', 'true') == 'true' and self.remote_wants_chatstates is not False: needed = 'inactive' if self.core.status.show in ('xa', 'away') else 'active' @@ -1875,7 +1875,7 @@ class ConversationTab(ChatTab): if line.find('\x19') == -1: msg['body'] = line else: - msg['body'] = xhtml.clean_text_simple(line) + msg['body'] = xhtml.clean_text(line) msg['xhtml_im'] = xhtml.poezio_colors_to_html(line) if config.get('send_chat_states', 'true') == 'true' and self.remote_wants_chatstates is not False: needed = 'inactive' if self.core.status.show in ('xa', 'away') else 'active' -- cgit v1.2.3 From cd16403cb486df2c68da4af1e45b16a3c6687edd Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Mon, 7 Nov 2011 19:57:16 +0100 Subject: typo --- src/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/core.py b/src/core.py index ba2c7b1d..a2205618 100644 --- a/src/core.py +++ b/src/core.py @@ -1050,7 +1050,7 @@ class Core(object): if tab.get_user_by_name(nick_from) and\ tab.get_user_by_name(nick_from) in tab.ignores: return - self.events.trigger('muc_mg', message) + self.events.trigger('muc_msg', message) body = xhtml.get_body_from_message_stanza(message) if body: date = date if delayed == True else None -- cgit v1.2.3 From 15780364cf13de0bd4c2a40d895fe77273f00ab9 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Mon, 7 Nov 2011 19:54:12 +0100 Subject: avoid a crash on invalid colors --- src/windows.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/windows.py b/src/windows.py index 790dd858..1ff8f858 100644 --- a/src/windows.py +++ b/src/windows.py @@ -138,7 +138,8 @@ class Win(object): 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))) + if color_str: + 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:] -- cgit v1.2.3 From 36cd91dc9c6e30025e622f958fbdf984de10483b Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Mon, 7 Nov 2011 19:54:45 +0100 Subject: trigger events *_say BEFORE generating the xhtml, making it possible to add colors in the hook --- src/tabs.py | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/tabs.py b/src/tabs.py index cae188ae..02d3c90d 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -715,14 +715,16 @@ class MucTab(ChatTab): needed = 'inactive' if self.core.status.show in ('xa', 'away') else 'active' msg = self.core.xmpp.make_message(self.get_name()) msg['type'] = 'groupchat' - if line.find('\x19') == -1: - msg['body'] = line - else: - msg['body'] = xhtml.clean_text(line) - msg['xhtml_im'] = xhtml.poezio_colors_to_html(line) + msg['body'] = line + # trigger the event BEFORE looking for colors. + # This lets a plugin insert \x19xxx} colors, that will + # be converted in xhtml. + self.core.events.trigger('muc_say', msg) + if msg['body'].find('\x19') != -1: + msg['xhtml_im'] = xhtml.poezio_colors_to_html(msg['body']) + msg['body'] = xhtml.clean_text(msg['body']) if config.get('send_chat_states', 'true') == 'true' and self.remote_wants_chatstates is not False: msg['chat_state'] = needed - self.core.events.trigger('muc_say', msg) self.cancel_paused_delay() msg.send() self.chat_state = needed @@ -1208,11 +1210,14 @@ class PrivateTab(ChatTab): return msg = self.core.xmpp.make_message(self.get_name()) msg['type'] = 'chat' - if line.find('\x19') == -1: - msg['body'] = line - else: - msg['body'] = xhtml.clean_text(line) - msg['xhtml_im'] = xhtml.poezio_colors_to_html(line) + msg['body'] = line + # trigger the event BEFORE looking for colors. + # This lets a plugin insert \x19xxx} colors, that will + # be converted in xhtml. + self.core.events.trigger('private_say', msg) + if msg['body'].find('\x19') != -1: + msg['body'] = xhtml.clean_text(msg['body']) + msg['xhtml_im'] = xhtml.poezio_colors_to_html(msg['body']) if config.get('send_chat_states', 'true') == 'true' and self.remote_wants_chatstates is not False: needed = 'inactive' if self.core.status.show in ('xa', 'away') else 'active' msg['chat_state'] = needed @@ -1872,11 +1877,14 @@ class ConversationTab(ChatTab): def command_say(self, line): msg = self.core.xmpp.make_message(self.get_name()) msg['type'] = 'chat' - if line.find('\x19') == -1: - msg['body'] = line - else: - msg['body'] = xhtml.clean_text(line) - msg['xhtml_im'] = xhtml.poezio_colors_to_html(line) + msg['body'] = line + # trigger the event BEFORE looking for colors. + # This lets a plugin insert \x19xxx} colors, that will + # be converted in xhtml. + self.core.events.trigger('conversation_say', msg) + if msg['body'].find('\x19') != -1: + msg['body'] = xhtml.clean_text(msg['body']) + msg['xhtml_im'] = xhtml.poezio_colors_to_html(msg['body']) if config.get('send_chat_states', 'true') == 'true' and self.remote_wants_chatstates is not False: needed = 'inactive' if self.core.status.show in ('xa', 'away') else 'active' msg['chat_state'] = needed -- cgit v1.2.3 From 689f17cfd79b152d3ca75e570f9f13f70aa6c425 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Mon, 7 Nov 2011 19:55:16 +0100 Subject: Fix the curses -> html color conversion --- src/xhtml.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/xhtml.py b/src/xhtml.py index 2cedba7d..748c9080 100644 --- a/src/xhtml.py +++ b/src/xhtml.py @@ -201,9 +201,9 @@ def ncurses_color_to_html(color): """ if color <= 15: (r, g, b) = curses.color_content(color) - r = r / 1000 * 6 - g = g / 1000 * 6 - b = b / 1000 * 6 + r = r / 1000 * 6 - 0.01 + g = g / 1000 * 6 - 0.01 + b = b / 1000 * 6 - 0.01 elif color <= 231: color = color - 16 r = color % 6 @@ -214,7 +214,7 @@ def ncurses_color_to_html(color): else: color -= 232 r = g = b = color / 24 * 6 - return '#%X%X%X' % (r*256/6, g*256/6, b*256/6) + return '#%02X%02X%02X' % (r*256/6, g*256/6, b*256/6) def xhtml_to_poezio_colors(text): def parse_css(css): -- cgit v1.2.3 From 60b58301d3ba9e1df1fb4edbb98c5910d0458a36 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Mon, 7 Nov 2011 19:55:40 +0100 Subject: Little cleanup --- src/xhtml.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/xhtml.py b/src/xhtml.py index 748c9080..70e17423 100644 --- a/src/xhtml.py +++ b/src/xhtml.py @@ -251,7 +251,6 @@ def xhtml_to_poezio_colors(text): key, value = rule.split(':', 1) key = key.strip() value = value.strip() - log.debug(value) if key == 'background-color': pass#shell += '\x191' elif key == 'color': @@ -274,7 +273,6 @@ def xhtml_to_poezio_colors(text): def trim(string): return re.sub(whitespace_re, ' ', string) - log.debug(text) xml = ET.fromstring(text) message = '' if version_info[1] == 2: -- cgit v1.2.3 From 2b9a43ce6a5fa6ad93ab570a99d4d92337a40110 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Mon, 7 Nov 2011 19:56:03 +0100 Subject: poezio_colors_to_html now takes full colors (\x19xxx}) to generate the xhtml code --- src/xhtml.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/xhtml.py b/src/xhtml.py index 70e17423..973a4d18 100644 --- a/src/xhtml.py +++ b/src/xhtml.py @@ -400,7 +400,6 @@ def poezio_colors_to_html(string): 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': for elem in opened_elements[::-1]: res += '' % (elem,) @@ -409,17 +408,20 @@ def poezio_colors_to_html(string): if 'strong' not in opened_elements: opened_elements.append('strong') res += '' - elif attr_char in digits: - number = int(attr_char) - if number in number_to_color_names: - if 'strong' in opened_elements: - res += '' - opened_elements.remove('strong') - if 'span' in opened_elements: - res += '' - else: - opened_elements.append('span') - res += "" % (number_to_color_names[number]) + if attr_char in digits: + number_str = string[next_attr_char+1:string.find('}', next_attr_char)] + number = int(number_str) + if 'strong' in opened_elements: + res += '' + opened_elements.remove('strong') + if 'span' in opened_elements: + res += '' + else: + opened_elements.append('span') + res += "" % (ncurses_color_to_html(number),) + string = string[next_attr_char+len(number_str)+2:] + else: + string = string[next_attr_char+2:] next_attr_char = string.find('\x19') res += string for elem in opened_elements[::-1]: -- cgit v1.2.3