diff options
author | Madhur Garg <madhurgarg96@gmail.com> | 2019-06-13 00:29:43 +0530 |
---|---|---|
committer | Madhur Garg <madhurgarg96@gmail.com> | 2019-06-13 00:29:43 +0530 |
commit | d528a2ff557a5c01f5d9cab6c67034c9237497f3 (patch) | |
tree | 462c203bb4095b221d22fbf5ca933e53b200c303 /plugins/lastlog.py | |
parent | 6cfd23196c935dbf4c6ef15091342576ef507c95 (diff) | |
download | poezio-d528a2ff557a5c01f5d9cab6c67034c9237497f3.tar.gz poezio-d528a2ff557a5c01f5d9cab6c67034c9237497f3.tar.bz2 poezio-d528a2ff557a5c01f5d9cab6c67034c9237497f3.tar.xz poezio-d528a2ff557a5c01f5d9cab6c67034c9237497f3.zip |
Corrected the search for lastlog messages and refresh of the window.
Diffstat (limited to 'plugins/lastlog.py')
-rw-r--r-- | plugins/lastlog.py | 58 |
1 files 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='<keyword>', help=( - 'Search <keyword> in the buffer and returns results' - 'on the screen' - ), - ) - self.api.add_tab_command( - MucTab, 'lastlog', self.command_lastlog, usage='<keyword>', - help=('Search <keyword> in the buffer and returns results' - 'on the screen'), - ) - self.api.add_tab_command( - PrivateTab, 'lastlog', self.command_lastlog, usage='<keyword>', - help=('Search <keyword> 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='<keyword>', + help='Search <keyword> 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() |