From 0a573f12dd92a38c4b499f869b5d93d70cfce822 Mon Sep 17 00:00:00 2001 From: Madhur Garg Date: Wed, 12 Jun 2019 19:49:00 +0530 Subject: [PATCH 01/14] Corrected the search for lastlog messages and refresh of the window. --- plugins/lastlog.py | 58 ++++++++++++---------------------------------- 1 file changed, 15 insertions(+), 43 deletions(-) diff --git a/plugins/lastlog.py b/plugins/lastlog.py index ae946f46..5198527e 100644 --- a/plugins/lastlog.py +++ b/plugins/lastlog.py @@ -12,7 +12,7 @@ import re from poezio.plugin import BasePlugin -from poezio.tabs import ConversationTab, PrivateTab, MucTab +from poezio import tabs from poezio.text_buffer import Message, TextBuffer @@ -32,60 +32,32 @@ def add_line(text_buffer: TextBuffer, text: str) -> None: ) -def add_message(text_buffer: TextBuffer, msg: Message) -> None: - """Adds a message to the TextBuffer""" - text_buffer.add_message( - msg.txt, - msg.time, - None, # Nickname - None, # Nick Color - False, # History - None, # User - msg.highlight, - msg.identifier, - msg.str_time, - None, # Jid - ) - - class Plugin(BasePlugin): """Lastlog Plugin""" def init(self): - self.api.add_tab_command( - ConversationTab, 'lastlog', self.command_lastlog, - usage='', help=( - 'Search in the buffer and returns results' - 'on the screen' - ), - ) - self.api.add_tab_command( - MucTab, 'lastlog', self.command_lastlog, usage='', - help=('Search in the buffer and returns results' - 'on the screen'), - ) - self.api.add_tab_command( - PrivateTab, 'lastlog', self.command_lastlog, usage='', - help=('Search in the buffer and returns results' - 'on the screen'), - ) + for tab in tabs.ConversationTab, tabs.PrivateTab, tabs.MucTab: + self.api.add_tab_command( + tab, + 'lastlog', + self.command_lastlog, + usage='', + help='Search in the buffer and returns results' + 'on the screen') def command_lastlog(self, input_): """Define lastlog command""" text_buffer = self.api.current_tab()._text_buffer - search_re = re.compile(input_) + search_re = re.compile(input_, re.I) res = [] + add_line(text_buffer, "Lastlog:") for message in text_buffer.messages: - if message.nickname is not None: - self.core.information('Foo: %s> %s' % (message.nickname, message.txt), 'Info') if message.nickname is not None and \ search_re.search(message.txt) is not None: res.append(message) - - add_line(text_buffer, "Lastlog for '%s', %d match(es)" % (input_, len(res))) - - for message in res: - message.nickname = None - add_message(text_buffer, message) + add_line(text_buffer, "%s" % (message.txt)) + add_line(text_buffer, "End of Lastlog") + self.api.current_tab().text_win.pos = 0 + self.api.current_tab().core.refresh_window() From 6cfd23196c935dbf4c6ef15091342576ef507c95 Mon Sep 17 00:00:00 2001 From: Maxime Buquet Date: Thu, 13 Jun 2019 00:23:48 +0530 Subject: [PATCH 02/14] patch from Maxime Buquet --- plugins/lastlog.py | 58 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/plugins/lastlog.py b/plugins/lastlog.py index 5198527e..ae946f46 100644 --- a/plugins/lastlog.py +++ b/plugins/lastlog.py @@ -12,7 +12,7 @@ import re from poezio.plugin import BasePlugin -from poezio import tabs +from poezio.tabs import ConversationTab, PrivateTab, MucTab from poezio.text_buffer import Message, TextBuffer @@ -32,32 +32,60 @@ def add_line(text_buffer: TextBuffer, text: str) -> None: ) +def add_message(text_buffer: TextBuffer, msg: Message) -> None: + """Adds a message to the TextBuffer""" + text_buffer.add_message( + msg.txt, + msg.time, + None, # Nickname + None, # Nick Color + False, # History + None, # User + msg.highlight, + msg.identifier, + msg.str_time, + None, # Jid + ) + + class Plugin(BasePlugin): """Lastlog Plugin""" def init(self): - for tab in tabs.ConversationTab, tabs.PrivateTab, tabs.MucTab: - self.api.add_tab_command( - tab, - 'lastlog', - self.command_lastlog, - usage='', - help='Search in the buffer and returns results' - 'on the screen') + self.api.add_tab_command( + ConversationTab, 'lastlog', self.command_lastlog, + usage='', help=( + 'Search in the buffer and returns results' + 'on the screen' + ), + ) + self.api.add_tab_command( + MucTab, 'lastlog', self.command_lastlog, usage='', + help=('Search in the buffer and returns results' + 'on the screen'), + ) + self.api.add_tab_command( + PrivateTab, 'lastlog', self.command_lastlog, usage='', + help=('Search in the buffer and returns results' + 'on the screen'), + ) def command_lastlog(self, input_): """Define lastlog command""" text_buffer = self.api.current_tab()._text_buffer - search_re = re.compile(input_, re.I) + search_re = re.compile(input_) res = [] - add_line(text_buffer, "Lastlog:") for message in text_buffer.messages: + if message.nickname is not None: + self.core.information('Foo: %s> %s' % (message.nickname, message.txt), 'Info') if message.nickname is not None and \ search_re.search(message.txt) is not None: res.append(message) - add_line(text_buffer, "%s" % (message.txt)) - add_line(text_buffer, "End of Lastlog") - self.api.current_tab().text_win.pos = 0 - self.api.current_tab().core.refresh_window() + + add_line(text_buffer, "Lastlog for '%s', %d match(es)" % (input_, len(res))) + + for message in res: + message.nickname = None + add_message(text_buffer, message) From d528a2ff557a5c01f5d9cab6c67034c9237497f3 Mon Sep 17 00:00:00 2001 From: Madhur Garg Date: Thu, 13 Jun 2019 00:29:43 +0530 Subject: [PATCH 03/14] Corrected the search for lastlog messages and refresh of the window. --- plugins/lastlog.py | 58 ++++++++++++---------------------------------- 1 file changed, 15 insertions(+), 43 deletions(-) diff --git a/plugins/lastlog.py b/plugins/lastlog.py index ae946f46..5198527e 100644 --- a/plugins/lastlog.py +++ b/plugins/lastlog.py @@ -12,7 +12,7 @@ import re from poezio.plugin import BasePlugin -from poezio.tabs import ConversationTab, PrivateTab, MucTab +from poezio import tabs from poezio.text_buffer import Message, TextBuffer @@ -32,60 +32,32 @@ def add_line(text_buffer: TextBuffer, text: str) -> None: ) -def add_message(text_buffer: TextBuffer, msg: Message) -> None: - """Adds a message to the TextBuffer""" - text_buffer.add_message( - msg.txt, - msg.time, - None, # Nickname - None, # Nick Color - False, # History - None, # User - msg.highlight, - msg.identifier, - msg.str_time, - None, # Jid - ) - - class Plugin(BasePlugin): """Lastlog Plugin""" def init(self): - self.api.add_tab_command( - ConversationTab, 'lastlog', self.command_lastlog, - usage='', help=( - 'Search in the buffer and returns results' - 'on the screen' - ), - ) - self.api.add_tab_command( - MucTab, 'lastlog', self.command_lastlog, usage='', - help=('Search in the buffer and returns results' - 'on the screen'), - ) - self.api.add_tab_command( - PrivateTab, 'lastlog', self.command_lastlog, usage='', - help=('Search in the buffer and returns results' - 'on the screen'), - ) + for tab in tabs.ConversationTab, tabs.PrivateTab, tabs.MucTab: + self.api.add_tab_command( + tab, + 'lastlog', + self.command_lastlog, + usage='', + help='Search in the buffer and returns results' + 'on the screen') def command_lastlog(self, input_): """Define lastlog command""" text_buffer = self.api.current_tab()._text_buffer - search_re = re.compile(input_) + search_re = re.compile(input_, re.I) res = [] + add_line(text_buffer, "Lastlog:") for message in text_buffer.messages: - if message.nickname is not None: - self.core.information('Foo: %s> %s' % (message.nickname, message.txt), 'Info') if message.nickname is not None and \ search_re.search(message.txt) is not None: res.append(message) - - add_line(text_buffer, "Lastlog for '%s', %d match(es)" % (input_, len(res))) - - for message in res: - message.nickname = None - add_message(text_buffer, message) + add_line(text_buffer, "%s" % (message.txt)) + add_line(text_buffer, "End of Lastlog") + self.api.current_tab().text_win.pos = 0 + self.api.current_tab().core.refresh_window() From 75554d3a6640a36fcee602d78aee93f38704849e Mon Sep 17 00:00:00 2001 From: Madhur Garg Date: Fri, 31 May 2019 20:34:39 +0530 Subject: [PATCH 04/14] Initial version of scrollback --- poezio/tabs/basetabs.py | 67 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py index dbe92a32..f2f2d26f 100644 --- a/poezio/tabs/basetabs.py +++ b/poezio/tabs/basetabs.py @@ -490,6 +490,11 @@ class ChatTab(Tab): self.command_say, usage='', shortdesc='Send the message.') + self.register_command( + 'sb', + self.command_sb, + usage="", + shortdesc='Scrollback to the given line number, meassage, or clear the buffer.') self.register_command( 'xhtml', self.command_xhtml, @@ -782,6 +787,68 @@ class ChatTab(Tab): def command_say(self, line, correct=False): pass + @command_args_parser.quoted(0, 2) + def command_sb(self, args): + """ + /sb + """ + if args is None or len(args) == 0: + self.text_win.scroll_down(len(self.text_win.built_lines)) + self.core.refresh_window() + self.core.information('Command Usage: clear goto home end status', 'Info') + elif len(args) == 1: + if args[0] == 'end': + self.text_win.scroll_down(len(self.text_win.built_lines)) + self.core.refresh_window() + elif args[0] == 'home': + self.text_win.scroll_up(len(self.text_win.built_lines)) + self.core.refresh_window() + elif args[0] == 'clear': + self._text_buffer.messages = [] + self.text_win.rebuild_everything(self._text_buffer) + self.core.refresh_window() + elif args[0] == 'status': + self.core.information('Total %s lines in this tab.' %len(self.text_win.built_lines), 'Info') + elif len(args) == 2 and args[0] == 'goto': + try: + datetime.strptime(args[1], '%Y-%m-%d %H:%M:%S') + except ValueError: + if '+' in args[1]: + scroll_len = args[1].strip('+') + self.text_win.scroll_up(int(scroll_len)) + self.core.refresh_window() + return + elif '-' in args[1]: + scroll_len = args[1].strip('-') + self.text_win.scroll_down(int(scroll_len)) + self.core.refresh_window() + return + elif int(args[1]): + if len(self.text_win.built_lines) - self.text_win.height >= int(args[1]): + self.text_win.pos = len(self.text_win.built_lines) - self.text_win.height - int(args[1]) + 1 + self.core.refresh_window() + return + else: + self.text_win.pos = 0 + self.core.refresh_window() + return + text_buffer = self._text_buffer + line_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 + self.core.refresh_window() + return + else: + self.text_win.pos = 0 + self.core.refresh_window() + return + def on_line_up(self): return self.text_win.scroll_up(1) From 20a609433150471b513af26bba1f1bccc9260744 Mon Sep 17 00:00:00 2001 From: Madhur Garg Date: Thu, 6 Jun 2019 03:30:54 +0530 Subject: [PATCH 05/14] Documentation for scrollback command. --- doc/source/commands.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/source/commands.rst b/doc/source/commands.rst index 87d72198..529ad274 100644 --- a/doc/source/commands.rst +++ b/doc/source/commands.rst @@ -316,6 +316,11 @@ These commands will work in any conversation tab (MultiUserChat, Private, or /clear Clear the current buffer. + /sb + **Usage:** ``/end home clear status goto <+|-linecount>||`` + + Allows to go to the given line or message in the window. + .. _muctab-commands: MultiUserChat tab commands From 6db84c6dc6206fa25ed9865f0a9b9ad1a4128f20 Mon Sep 17 00:00:00 2001 From: Madhur Garg Date: Thu, 6 Jun 2019 03:38:24 +0530 Subject: [PATCH 06/14] Few imports for scrollback command --- poezio/tabs/basetabs.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py index f2f2d26f..ef2e44a9 100644 --- a/poezio/tabs/basetabs.py +++ b/poezio/tabs/basetabs.py @@ -26,12 +26,15 @@ from poezio.core.structs import Command, Completion, Status from poezio import timed_events from poezio import windows from poezio import xhtml +from poezio import poopt +from math import ceil, log10 +from poezio.windows.funcs import truncate_nick, parse_attrs from poezio.common import safeJID from poezio.config import config from poezio.decorators import refresh_wrapper from poezio.logger import logger from poezio.text_buffer import TextBuffer -from poezio.theming import get_theme, dump_tuple +from poezio.theming import to_curses_attr, get_theme, dump_tuple from poezio.decorators import command_args_parser log = logging.getLogger(__name__) From 0d2e2b084b5df92cdeef75349fd1a6ea1a2223f0 Mon Sep 17 00:00:00 2001 From: Madhur Garg Date: Thu, 6 Jun 2019 03:40:04 +0530 Subject: [PATCH 07/14] Corrected description of the scrollback command --- poezio/tabs/basetabs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py index ef2e44a9..a5e4bf4a 100644 --- a/poezio/tabs/basetabs.py +++ b/poezio/tabs/basetabs.py @@ -497,7 +497,7 @@ class ChatTab(Tab): 'sb', self.command_sb, usage="", - shortdesc='Scrollback to the given line number, meassage, or clear the buffer.') + shortdesc='Scrollback to the given line number, message, or clear the buffer.') self.register_command( 'xhtml', self.command_xhtml, From d8f53e82662fb2d9e445605b4552538e3ef4187c Mon Sep 17 00:00:00 2001 From: Madhur Garg Date: Thu, 6 Jun 2019 03:46:09 +0530 Subject: [PATCH 08/14] Corrected code duplication --- poezio/tabs/basetabs.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py index a5e4bf4a..bf2ef9d9 100644 --- a/poezio/tabs/basetabs.py +++ b/poezio/tabs/basetabs.py @@ -796,10 +796,8 @@ class ChatTab(Tab): /sb """ if args is None or len(args) == 0: - self.text_win.scroll_down(len(self.text_win.built_lines)) - self.core.refresh_window() - self.core.information('Command Usage: clear goto home end status', 'Info') - elif len(args) == 1: + args = ['end'] + if len(args) == 1: if args[0] == 'end': self.text_win.scroll_down(len(self.text_win.built_lines)) self.core.refresh_window() @@ -826,15 +824,12 @@ class ChatTab(Tab): self.text_win.scroll_down(int(scroll_len)) self.core.refresh_window() return - elif int(args[1]): - if len(self.text_win.built_lines) - self.text_win.height >= int(args[1]): - self.text_win.pos = len(self.text_win.built_lines) - self.text_win.height - int(args[1]) + 1 - self.core.refresh_window() - return - else: - self.text_win.pos = 0 - self.core.refresh_window() - return + else: + self.text_win.pos = 0 + self.core.refresh_window() + return + elif args[1] == '0': + args = ['home'] text_buffer = self._text_buffer line_count=0 for message in text_buffer.messages: From b2c38497d499017c31d1d27538569afc9a4562cd Mon Sep 17 00:00:00 2001 From: Madhur Garg Date: Thu, 6 Jun 2019 03:50:34 +0530 Subject: [PATCH 09/14] Code work for /sb goto <+|-linecount>|| --- poezio/tabs/basetabs.py | 46 +++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py index bf2ef9d9..f90f1a2b 100644 --- a/poezio/tabs/basetabs.py +++ b/poezio/tabs/basetabs.py @@ -809,19 +809,47 @@ class ChatTab(Tab): self.text_win.rebuild_everything(self._text_buffer) self.core.refresh_window() elif args[0] == 'status': - self.core.information('Total %s lines in this tab.' %len(self.text_win.built_lines), 'Info') + self.core.information('Total %s lines in this tab.' % len(self.text_win.built_lines), 'Info') elif len(args) == 2 and args[0] == 'goto': - try: - datetime.strptime(args[1], '%Y-%m-%d %H:%M:%S') - except ValueError: - if '+' in args[1]: - scroll_len = args[1].strip('+') + for fmt in ('%d %H:%M', '%d %H:%M:%S', '%d:%m %H:%M', '%d:%m %H:%M:%S', '%H:%M', '%H:%M:%S'): + try: + new_date = datetime.strptime(args[1], fmt) + if 'm' and 'd' in fmt: + new_date = new_date.replace(year=datetime.now().year) + elif 'd' in fmt: + new_date = new_date.replace(year=datetime.now().year, month=datetime.now().month) + else: + new_date = new_date.replace(year=datetime.now().year, month=datetime.now().month, day=datetime.now().day) + except ValueError: + pass + if '-' in args[1]: + if ' ' in args[1]: + new_args = args[1].split(' ') + new_args[0] = new_args[0].strip('-') + new_date = datetime.now() + if new_args[0].isdigit(): + new_date = new_date.replace(day=new_date.day - int(new_args[0])) + for fmt in ('%H:%M', '%H:%M:%S'): + try: + arg_date = datetime.strptime(new_args[1], fmt) + new_date = new_date.replace(hour=arg_date.hour, minute=arg_date.minute, second=arg_date.second) + except ValueError: + pass + else: + scroll_len = args[1].strip('-') + if scroll_len.isdigit(): + self.text_win.scroll_down(int(scroll_len)) + self.core.refresh_window() + return + elif '+' in args[1]: + scroll_len = args[1].strip('+') + if scroll_len.isdigit(): self.text_win.scroll_up(int(scroll_len)) self.core.refresh_window() return - elif '-' in args[1]: - scroll_len = args[1].strip('-') - self.text_win.scroll_down(int(scroll_len)) + elif args[1].isdigit(): + if len(self.text_win.built_lines) - self.text_win.height >= int(args[1]): + self.text_win.pos = len(self.text_win.built_lines) - self.text_win.height - int(args[1]) self.core.refresh_window() return else: From a1aad86a5bbf98db4a27f83aa6f9b45a0e83eb56 Mon Sep 17 00:00:00 2001 From: Madhur Garg Date: Thu, 6 Jun 2019 03:54:42 +0530 Subject: [PATCH 10/14] Getting the line number of the message in the tab based on the searched timestamp --- poezio/tabs/basetabs.py | 46 ++++++++++++++++++++++++++++++++--------- 1 file 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) From ca72ac8d26d79f0edd620e3d0366166a6c1b768c Mon Sep 17 00:00:00 2001 From: Madhur Garg Date: Thu, 6 Jun 2019 05:52:19 +0530 Subject: [PATCH 11/14] Updated usage of /sb in documentation --- doc/source/commands.rst | 2 +- poezio/tabs/basetabs.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/commands.rst b/doc/source/commands.rst index 529ad274..d67b5351 100644 --- a/doc/source/commands.rst +++ b/doc/source/commands.rst @@ -317,7 +317,7 @@ These commands will work in any conversation tab (MultiUserChat, Private, or Clear the current buffer. /sb - **Usage:** ``/end home clear status goto <+|-linecount>||`` + **Usage:** ``/sb end home clear status goto <+|-linecount>||`` Allows to go to the given line or message in the window. diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py index 0db53a47..0d636c66 100644 --- a/poezio/tabs/basetabs.py +++ b/poezio/tabs/basetabs.py @@ -496,7 +496,7 @@ class ChatTab(Tab): self.register_command( 'sb', self.command_sb, - usage="", + usage="end home clear status goto <+|-linecount>||", shortdesc='Scrollback to the given line number, message, or clear the buffer.') self.register_command( 'xhtml', From 2c4a2d3d010bceacba6c54988d5eed228e671f31 Mon Sep 17 00:00:00 2001 From: Madhur Garg Date: Sun, 9 Jun 2019 06:10:10 +0530 Subject: [PATCH 12/14] Corrects the repeated refresh of the window --- poezio/tabs/basetabs.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py index 0d636c66..1de73052 100644 --- a/poezio/tabs/basetabs.py +++ b/poezio/tabs/basetabs.py @@ -801,20 +801,24 @@ class ChatTab(Tab): if args[0] == 'end': self.text_win.scroll_down(len(self.text_win.built_lines)) self.core.refresh_window() + return elif args[0] == 'home': self.text_win.scroll_up(len(self.text_win.built_lines)) self.core.refresh_window() + return elif args[0] == 'clear': self._text_buffer.messages = [] self.text_win.rebuild_everything(self._text_buffer) self.core.refresh_window() + return elif args[0] == 'status': self.core.information('Total %s lines in this tab.' % len(self.text_win.built_lines), 'Info') + return elif len(args) == 2 and args[0] == 'goto': for fmt in ('%d %H:%M', '%d %H:%M:%S', '%d:%m %H:%M', '%d:%m %H:%M:%S', '%H:%M', '%H:%M:%S'): try: new_date = datetime.strptime(args[1], fmt) - if 'm' and 'd' in fmt: + if 'd' in fmt and 'm' in fmt: new_date = new_date.replace(year=datetime.now().year) elif 'd' in fmt: new_date = new_date.replace(year=datetime.now().year, month=datetime.now().month) @@ -893,13 +897,11 @@ class ChatTab(Tab): 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() else: self.text_win.pos = 0 - self.core.refresh_window() if message_count == 0: self.text_win.scroll_up(len(self.text_win.built_lines)) - self.core.refresh_window() + self.core.refresh_window() def on_line_up(self): return self.text_win.scroll_up(1) From 569efdec36d7e2200f90e23572c2a88127ec5022 Mon Sep 17 00:00:00 2001 From: Madhur Garg Date: Wed, 12 Jun 2019 04:55:02 +0530 Subject: [PATCH 13/14] Fixed some mistakes in coding style --- poezio/tabs/basetabs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py index 1de73052..c3f1fbe1 100644 --- a/poezio/tabs/basetabs.py +++ b/poezio/tabs/basetabs.py @@ -826,7 +826,7 @@ class ChatTab(Tab): new_date = new_date.replace(year=datetime.now().year, month=datetime.now().month, day=datetime.now().day) except ValueError: pass - if '-' in args[1]: + if args[1].startswith('-'): if ' ' in args[1]: new_args = args[1].split(' ') new_args[0] = new_args[0].strip('-') @@ -845,7 +845,7 @@ class ChatTab(Tab): self.text_win.scroll_down(int(scroll_len)) self.core.refresh_window() return - elif '+' in args[1]: + elif args[1].startswith('+'): scroll_len = args[1].strip('+') if scroll_len.isdigit(): self.text_win.scroll_up(int(scroll_len)) From f505c83c484cec35b5ef772d318c1ff286dad74b Mon Sep 17 00:00:00 2001 From: Madhur Garg Date: Thu, 20 Jun 2019 01:11:36 +0530 Subject: [PATCH 14/14] Added few comments in the code and splitted a part of code into different function. --- poezio/tabs/basetabs.py | 95 +++++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 41 deletions(-) diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py index c3f1fbe1..e947482b 100644 --- a/poezio/tabs/basetabs.py +++ b/poezio/tabs/basetabs.py @@ -790,10 +790,59 @@ class ChatTab(Tab): def command_say(self, line, correct=False): pass + def goto_build_lines(self, new_date): + text_buffer = self._text_buffer + built_lines = [] + message_count = 0 + for message in text_buffer.messages: + # Build lines of a message + 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) + # Find the message with timestamp less than or equal to the queried + # timestamp and goto that location in the tab. + 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 + else: + self.text_win.pos = 0 + if message_count == 0: + self.text_win.scroll_up(len(self.text_win.built_lines)) + self.core.refresh_window() + @command_args_parser.quoted(0, 2) def command_sb(self, args): """ - /sb + /sb clear + /sb home + /sb end + /sb goto <+|-linecount>|| + The format of timestamp must be ‘[dd[.mm]-] hh:mi[:ss]’ """ if args is None or len(args) == 0: args = ['end'] @@ -827,6 +876,7 @@ class ChatTab(Tab): except ValueError: pass if args[1].startswith('-'): + # Check if the user is giving argument of type goto <-linecount> or goto [-] hh:mi[:ss] if ' ' in args[1]: new_args = args[1].split(' ') new_args[0] = new_args[0].strip('-') @@ -851,6 +901,7 @@ class ChatTab(Tab): self.text_win.scroll_up(int(scroll_len)) self.core.refresh_window() return + # Check for the argument of type goto elif args[1].isdigit(): if len(self.text_win.built_lines) - self.text_win.height >= int(args[1]): self.text_win.pos = len(self.text_win.built_lines) - self.text_win.height - int(args[1]) @@ -862,46 +913,8 @@ class ChatTab(Tab): return elif args[1] == '0': args = ['home'] - text_buffer = self._text_buffer - built_lines = [] - message_count = 0 - for message in text_buffer.messages: - 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 - else: - self.text_win.pos = 0 - if message_count == 0: - self.text_win.scroll_up(len(self.text_win.built_lines)) - self.core.refresh_window() + # new_date is the timestamp for which the user has queried. + self.goto_build_lines(new_date) def on_line_up(self): return self.text_win.scroll_up(1)