diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/text_buffer.py | 9 | ||||
-rw-r--r-- | src/theming.py | 3 | ||||
-rw-r--r-- | src/windows.py | 14 |
3 files changed, 20 insertions, 6 deletions
diff --git a/src/text_buffer.py b/src/text_buffer.py index 67aa8ef6..48de2b1c 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 me old_message') +Message = collections.namedtuple('Message', 'txt nick_color time str_time nickname user identifier highlight me old_message revisions') class TextBuffer(object): """ @@ -40,7 +40,7 @@ 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, old_message=None): + def make_message(self, txt, time, nickname, nick_color, history, user, identifier, str_time=None, highlight=False, old_message=None, revisions=0): time = time or datetime.now() me = False if txt.startswith('/me '): @@ -56,7 +56,8 @@ class TextBuffer(object): identifier=identifier, highlight=highlight, me=me, - old_message=old_message) + old_message=old_message, + revisions=revisions) log.debug('Set message %s with %s.' % (identifier, msg)) return msg @@ -78,7 +79,7 @@ class TextBuffer(object): 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, time if time else msg.time, msg.nickname, msg.nick_color, None, msg.user, new_id, highlight=highlight, old_message=msg) + 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, revisions=msg.revisions + 1) self.messages[i] = message log.debug('Replacing message %s with %s.' % (old_id, new_id)) return diff --git a/src/theming.py b/src/theming.py index aba42a1c..cc7d0f89 100644 --- a/src/theming.py +++ b/src/theming.py @@ -114,6 +114,9 @@ class Theme(object): # Color for the /me message COLOR_ME_MESSAGE = (6, -1) + # Color for the number of revisions of a message + COLOR_REVISIONS_MESSAGE = (3, -1, 'b') + # Color for various important text. For example the "?" before JIDs in # the roster that require an user action. COLOR_IMPORTANT_TEXT = (3, 5, 'b') diff --git a/src/windows.py b/src/windows.py index b18102bc..d5239a09 100644 --- a/src/windows.py +++ b/src/windows.py @@ -20,6 +20,7 @@ log = logging.getLogger(__name__) import curses import string +from math import ceil, log10 from config import config from threading import RLock @@ -789,8 +790,9 @@ class TextWin(Win): nick = truncate_nick(message.nickname) offset = 0 if nick: - # TODO: add the number of corrections. offset += wcwidth.wcswidth(nick) + 2 # + nick + '> ' length + if message.revisions > 0: + offset += ceil(log10(message.revisions + 1)) if message.me: offset += 1 # '* ' before and ' ' after if timestamp: @@ -846,9 +848,17 @@ class TextWin(Win): self._win.attron(to_curses_attr(get_theme().COLOR_ME_MESSAGE)) self.addstr('* ') self.write_nickname(msg.nickname, color, msg.highlight) + if msg.revisions: + self._win.attron(to_curses_attr(get_theme().COLOR_REVISIONS_MESSAGE)) + self.addstr('%d' % msg.revisions) + self._win.attrset(0) self.addstr(' ') else: self.write_nickname(msg.nickname, color, msg.highlight) + if msg.revisions: + self._win.attron(to_curses_attr(get_theme().COLOR_REVISIONS_MESSAGE)) + self.addstr('%d' % msg.revisions) + self._win.attrset(0) self.addstr('> ') if y != self.height-1: self.addstr('\n') @@ -861,7 +871,7 @@ class TextWin(Win): # Offset for the timestamp (if any) plus a space after it (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))), + (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]) if y != self.height-1: self.addstr('\n') |