summaryrefslogtreecommitdiff
path: root/src/text_buffer.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/text_buffer.py')
-rw-r--r--src/text_buffer.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/text_buffer.py b/src/text_buffer.py
index b615e96c..1dc042c6 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')
+Message = collections.namedtuple('Message', 'txt nick_color time str_time nickname user identifier')
class TextBuffer(object):
"""
@@ -35,7 +35,7 @@ class TextBuffer(object):
def add_window(self, win):
self.windows.append(win)
- def add_message(self, txt, time=None, nickname=None, nick_color=None, history=None, user=None, highlight=False):
+ def make_message(self, txt, time, nickname, nick_color, history, user, identifier):
time = time or datetime.now()
if txt.startswith('/me '):
if nick_color:
@@ -50,7 +50,12 @@ class TextBuffer(object):
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"),\
- nickname=nickname, user=user)
+ nickname=nickname, user=user, identifier=identifier)
+ 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):
+ msg = self.make_message(txt, time, nickname, nick_color, history, user, identifier)
self.messages.append(msg)
while len(self.messages) > self.messages_nb_limit:
self.messages.pop(0)
@@ -64,6 +69,15 @@ class TextBuffer(object):
window.scroll_up(nb)
return ret_val or 1
+ def modify_message(self, txt, old_id, new_id):
+ 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)
+ 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))
+
def del_window(self, win):
self.windows.remove(win)