diff options
author | Madhur Garg <madhurgarg96@gmail.com> | 2019-06-06 03:54:42 +0530 |
---|---|---|
committer | Madhur Garg <madhurgarg96@gmail.com> | 2019-06-20 03:09:30 +0530 |
commit | a1aad86a5bbf98db4a27f83aa6f9b45a0e83eb56 (patch) | |
tree | af20639f86a0ca00e0f356589e35910b4c2e308c | |
parent | b2c38497d499017c31d1d27538569afc9a4562cd (diff) | |
download | poezio-a1aad86a5bbf98db4a27f83aa6f9b45a0e83eb56.tar.gz poezio-a1aad86a5bbf98db4a27f83aa6f9b45a0e83eb56.tar.bz2 poezio-a1aad86a5bbf98db4a27f83aa6f9b45a0e83eb56.tar.xz poezio-a1aad86a5bbf98db4a27f83aa6f9b45a0e83eb56.zip |
Getting the line number of the message in the tab based on the searched timestamp
-rw-r--r-- | poezio/tabs/basetabs.py | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py index f90f1a2b..0db53a47 100644 --- a/poezio/tabs/basetabs.py +++ b/poezio/tabs/basetabs.py @@ -859,21 +859,47 @@ class ChatTab(Tab): elif args[1] == '0': args = ['home'] text_buffer = self._text_buffer - line_count=0 + built_lines = [] + message_count = 0 for message in text_buffer.messages: - line_count+=1 - for i in message.txt: - if i == '\n': - line_count+=1 - if message.str_time == args[1]: - if len(self.text_win.built_lines) - self.text_win.height >= line_count: - self.text_win.pos = len(self.text_win.built_lines) - self.text_win.height - line_count + 1 + txt = message.txt + timestamp = config.get('show_timestamps') + nick_size = config.get('max_nick_length') + nick = truncate_nick(message.nickname, nick_size) + offset = 0 + theme = get_theme() + if message.ack: + if message.ack > 0: + offset += poopt.wcswidth(theme.CHAR_ACK_RECEIVED) + 1 + else: + offset += poopt.wcswidth(theme.CHAR_NACK) + 1 + if nick: + offset += poopt.wcswidth(nick) + 2 + if message.revisions > 0: + offset += ceil(log10(message.revisions + 1)) + if message.me: + offset += 1 + if timestamp: + if message.str_time: + offset += 1 + len(message.str_time) + if theme.CHAR_TIME_LEFT and message.str_time: + offset += 1 + if theme.CHAR_TIME_RIGHT and message.str_time: + offset += 1 + lines = poopt.cut_text(txt, self.text_win.width - offset - 1) + for line in lines: + built_lines.append(line) + if message.time <= new_date: + message_count += 1 + if len(self.text_win.built_lines) - self.text_win.height >= len(built_lines): + self.text_win.pos = len(self.text_win.built_lines) - self.text_win.height - len(built_lines) + 1 self.core.refresh_window() - return else: self.text_win.pos = 0 self.core.refresh_window() - return + if message_count == 0: + self.text_win.scroll_up(len(self.text_win.built_lines)) + self.core.refresh_window() def on_line_up(self): return self.text_win.scroll_up(1) |