Add a new show_timestamps option to hide/show timestamps in text buffers.

This commit is contained in:
Florent Le Coz 2012-12-07 23:38:28 +01:00
parent 59be8bdd62
commit e2592f5cdf
4 changed files with 25 additions and 11 deletions

View file

@ -97,6 +97,9 @@ add_space_after_completion = true
# conversation window.
max_nick_length = 25
# Show the timestamp of each messages, or not
show_timestamps = true
# Words that you want to complete on recent words completion,
# separated by a colon (:).
# e.g. words = "anticonstitutionnellement:I protest:I like bananas:"

View file

@ -128,6 +128,10 @@ section of this documentation.
Whether or not to add a space after a completion in the middle of the
input (not at the start of it)
*show_timestamps*:: true
Whether or not to display a timestamp before each message.
*words*:: [empty]
Personal dictionary of the words you use often, that you want to complete

View file

@ -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:

View file

@ -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: