summaryrefslogtreecommitdiff
path: root/src/text_buffer.py
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2012-12-26 01:50:11 +0100
committerFlorent Le Coz <louiz@louiz.org>2012-12-29 13:14:50 +0100
commit590afbd4bcc8c9e3f04dd46d7747959290e71f51 (patch)
treee24cd224aa43221c0701856e30b76df668728e4c /src/text_buffer.py
parentdc4e0302b493491f6b7c565bfe5aa99af3483f61 (diff)
downloadpoezio-590afbd4bcc8c9e3f04dd46d7747959290e71f51.tar.gz
poezio-590afbd4bcc8c9e3f04dd46d7747959290e71f51.tar.bz2
poezio-590afbd4bcc8c9e3f04dd46d7747959290e71f51.tar.xz
poezio-590afbd4bcc8c9e3f04dd46d7747959290e71f51.zip
Fix /correct and /me highlights, and handle /correct a bit better.
Diffstat (limited to 'src/text_buffer.py')
-rw-r--r--src/text_buffer.py31
1 files changed, 15 insertions, 16 deletions
diff --git a/src/text_buffer.py b/src/text_buffer.py
index 2d3cb87a..67aa8ef6 100644
--- a/src/text_buffer.py
+++ b/src/text_buffer.py
@@ -18,7 +18,7 @@ from datetime import datetime
from config import config
from theming import get_theme
-Message = collections.namedtuple('Message', 'txt nick_color time str_time nickname user identifier highlight')
+Message = collections.namedtuple('Message', 'txt nick_color time str_time nickname user identifier highlight me old_message')
class TextBuffer(object):
"""
@@ -40,29 +40,28 @@ class TextBuffer(object):
return self.messages[-1] if self.messages else None
- def make_message(self, txt, time, nickname, nick_color, history, user, identifier, str_time=None, highlight=False):
+ def make_message(self, txt, time, nickname, nick_color, history, user, identifier, str_time=None, highlight=False, old_message=None):
time = time or datetime.now()
+ me = False
if txt.startswith('/me '):
- if nick_color:
- color = nick_color[0]
- elif user:
- color = user.color[0]
- else:
- color = None
- # TODO: display the bg color too.
- txt = '\x19%(info_col)s}* \x19%(col)s}%(nick)s \x19%(info_col)s}%(msg)s' % {'info_col':get_theme().COLOR_ME_MESSAGE[0], 'col': color or 5, 'nick': nickname, 'msg': txt[4:]}
- nickname = None
+ me = True
+ txt = '\x19%(info_col)s}' % {'info_col': get_theme().COLOR_ME_MESSAGE[0]} + txt[4:]
msg = Message(
txt='%s\x19o'%(txt.replace('\t', ' '),),
nick_color=nick_color,
time=time,
str_time=(time.strftime("%Y-%m-%d %H:%M:%S") if history else time.strftime("%H:%M:%S")) if str_time is None else '',
- nickname=nickname, user=user, identifier=identifier, highlight=highlight)
+ nickname=nickname,
+ user=user,
+ identifier=identifier,
+ highlight=highlight,
+ me=me,
+ old_message=old_message)
log.debug('Set message %s with %s.' % (identifier, msg))
return msg
def add_message(self, txt, time=None, nickname=None, nick_color=None, history=None, user=None, highlight=False, identifier=None, str_time=None):
- msg = self.make_message(txt, time, nickname, nick_color, history, user, identifier, str_time, highlight)
+ msg = self.make_message(txt, time, nickname, nick_color, history, user, identifier, str_time=str_time, highlight=highlight)
self.messages.append(msg)
while len(self.messages) > self.messages_nb_limit:
self.messages.pop(0)
@@ -76,14 +75,14 @@ class TextBuffer(object):
window.scroll_up(nb)
return ret_val or 1
- def modify_message(self, txt, old_id, new_id):
+ def modify_message(self, txt, old_id, new_id, highlight=False, time=None):
for i, msg in enumerate(self.messages):
if msg.identifier == old_id:
- message = self.make_message(txt, msg.time, msg.nickname, msg.nick_color, None, msg.user, new_id, msg.highlight)
+ message = self.make_message(txt, time if time else msg.time, msg.nickname, msg.nick_color, None, msg.user, new_id, highlight=highlight, old_message=msg)
self.messages[i] = message
log.debug('Replacing message %s with %s.' % (old_id, new_id))
return
- log.debug('Message %s not found in text_buffer, abort replacement.' % (identifier))
+ log.debug('Message %s not found in text_buffer, abort replacement.' % (old_id))
def del_window(self, win):
self.windows.remove(win)