summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2013-03-10 18:35:51 +0100
committermathieui <mathieui@mathieui.net>2013-03-10 18:35:51 +0100
commitd87834760f6e512fe4c69fbe612a97a5242e8955 (patch)
tree6265dd40382921ff32b7cda9eda1875e1cedc21d /src
parentaf22dd53bb125a064f3e1cdd4c7e0795dc64d898 (diff)
downloadpoezio-d87834760f6e512fe4c69fbe612a97a5242e8955.tar.gz
poezio-d87834760f6e512fe4c69fbe612a97a5242e8955.tar.bz2
poezio-d87834760f6e512fe4c69fbe612a97a5242e8955.tar.xz
poezio-d87834760f6e512fe4c69fbe612a97a5242e8955.zip
Fix #2122 (coloration of long messages)
- Add a “prepend” attribute to the Line tuple I’m not sure of the impact of this on performance (we parse the message yet another time)
Diffstat (limited to 'src')
-rw-r--r--src/windows.py40
1 files changed, 37 insertions, 3 deletions
diff --git a/src/windows.py b/src/windows.py
index cb96fa19..6aa458ba 100644
--- a/src/windows.py
+++ b/src/windows.py
@@ -43,7 +43,7 @@ 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.
-Line = collections.namedtuple('Line', 'msg start_pos end_pos')
+Line = collections.namedtuple('Line', 'msg start_pos end_pos prepend')
g_lock = RLock()
@@ -57,6 +57,33 @@ def truncate_nick(nick, size=None):
return nick[:size]+'…'
return nick
+def parse_attrs(text, previous=None):
+ next_attr_char = text.find('\x19')
+ if previous:
+ attrs = previous
+ else:
+ attrs = []
+ while next_attr_char != -1 and text:
+ if next_attr_char + 1 < len(text):
+ attr_char = text[next_attr_char+1].lower()
+ else:
+ attr_char = str()
+ if attr_char == 'o':
+ attrs = []
+ elif attr_char == 'u':
+ attrs.append('u')
+ elif attr_char == 'b':
+ attrs.append('b')
+ if attr_char in string.digits and attr_char != '':
+ color_str = text[next_attr_char+1:text.find('}', next_attr_char)]
+ if color_str:
+ attrs.append(color_str + '}')
+ text = text[next_attr_char+len(color_str)+2:]
+ else:
+ text = text[next_attr_char+2:]
+ next_attr_char = text.find('\x19')
+ return attrs
+
class Win(object):
_win_core = None
@@ -881,8 +908,15 @@ class TextWin(Win):
if get_theme().CHAR_TIME_RIGHT and message.str_time:
offset += 1
lines = cut_text(txt, self.width-offset)
+ prepend = ''
+ attrs = []
for line in lines:
- saved = Line(msg=message, start_pos=line[0], end_pos=line[1])
+ saved = Line(msg=message, start_pos=line[0], end_pos=line[1], prepend=prepend)
+ attrs = parse_attrs(message.txt[line[0]:line[1]], attrs)
+ if attrs:
+ prepend = '\x19' + '\x19'.join(attrs)
+ else:
+ prepend = ''
ret.append(saved)
return ret
@@ -938,7 +972,7 @@ class TextWin(Win):
(0 if not with_timestamps else (len(line.msg.str_time) + 1)) +
# Offset for the nickname (if any) plus a space and a > after it
(0 if not line.msg.nickname else (len(truncate_nick(line.msg.nickname)) + (3 if line.msg.me else 2) + ceil(log10(line.msg.revisions + 1)))),
- line.msg.txt[line.start_pos:line.end_pos])
+ line.prepend+line.msg.txt[line.start_pos:line.end_pos])
if y != self.height-1:
self.addstr('\n')
self._win.attrset(0)