diff options
author | Florent Le Coz <louiz@louiz.org> | 2012-12-07 23:38:28 +0100 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2012-12-07 23:39:49 +0100 |
commit | e2592f5cdf3efe13d74f75eeadcd37d54b4d9d5c (patch) | |
tree | 5c6b462051daa30480ad5b0ba19d9c8a0ea02a76 /src | |
parent | 59be8bdd62bbbb9b57a209b005441206eb02f7cd (diff) | |
download | poezio-e2592f5cdf3efe13d74f75eeadcd37d54b4d9d5c.tar.gz poezio-e2592f5cdf3efe13d74f75eeadcd37d54b4d9d5c.tar.bz2 poezio-e2592f5cdf3efe13d74f75eeadcd37d54b4d9d5c.tar.xz poezio-e2592f5cdf3efe13d74f75eeadcd37d54b4d9d5c.zip |
Add a new show_timestamps option to hide/show timestamps in text buffers.
Diffstat (limited to 'src')
-rw-r--r-- | src/text_buffer.py | 2 | ||||
-rw-r--r-- | src/windows.py | 27 |
2 files changed, 18 insertions, 11 deletions
diff --git a/src/text_buffer.py b/src/text_buffer.py index 8430a230..33942537 100644 --- a/src/text_buffer.py +++ b/src/text_buffer.py @@ -69,7 +69,7 @@ class TextBuffer(object): ret_val = None for window in self.windows: # make the associated windows # build the lines from the new message - nb = window.build_new_message(msg, history=history, highlight=highlight) + nb = window.build_new_message(msg, history=history, highlight=highlight, timestamp=config.get("show_timestamps", "true") != 'false') if ret_val is None: ret_val = nb if window.pos != 0: diff --git a/src/windows.py b/src/windows.py index 1b23cd03..4cf358a0 100644 --- a/src/windows.py +++ b/src/windows.py @@ -765,7 +765,7 @@ class TextWin(Win): if room and room.messages: self.separator_after = room.messages[-1] - def build_new_message(self, message, history=None, clean=True, highlight=False): + def build_new_message(self, message, history=None, clean=True, highlight=False, timestamp=False): """ Take one message, build it and add it to the list Return the number of lines that are built for the given @@ -779,14 +779,15 @@ class TextWin(Win): return 0 nick = truncate_nick(message.nickname) offset = 0 - if message.str_time: - offset += 1 + len(message.str_time) if nick: offset += wcwidth.wcswidth(nick) + 2 # + nick + spaces length - if get_theme().CHAR_TIME_LEFT and message.str_time: - offset += 1 - if get_theme().CHAR_TIME_RIGHT and message.str_time: - offset += 1 + if timestamp: + if message.str_time: + offset += 1 + len(message.str_time) + if get_theme().CHAR_TIME_LEFT and message.str_time: + offset += 1 + if get_theme().CHAR_TIME_RIGHT and message.str_time: + offset += 1 lines = cut_text(txt, self.width-offset) if self.lock: for line in lines: @@ -814,6 +815,7 @@ class TextWin(Win): lines = self.built_lines[-self.height:] else: lines = self.built_lines[-self.height-self.pos:-self.pos] + with_timestamps = config.get("show_timestamps", 'true') != 'false' with g_lock: self._win.move(0, 0) self._win.erase() @@ -827,7 +829,8 @@ class TextWin(Win): color = msg.user.color else: color = None - self.write_time(msg.str_time) + if with_timestamps: + self.write_time(msg.str_time) self.write_nickname(msg.nickname, color) if y != self.height-1: self.addstr('\n') @@ -837,7 +840,10 @@ class TextWin(Win): self.write_line_separator(y) else: self.write_text(y, - (3 if line.msg.nickname else (1 if line.msg.str_time else 0)) + len(line.msg.str_time)+len(truncate_nick(line.msg.nickname) or ''), + # 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))) + 2), line.msg.txt[line.start_pos:line.end_pos]) if y != self.height-1: self.addstr('\n') @@ -883,8 +889,9 @@ class TextWin(Win): def rebuild_everything(self, room): self.built_lines = [] + with_timestamps = config.get("show_timestamps", 'true') != 'false' for message in room.messages: - self.build_new_message(message, clean=False) + self.build_new_message(message, clean=False, timestamp=with_timestamps) if self.separator_after is message: self.build_new_message(None) while len(self.built_lines) > self.lines_nb_limit: |