summaryrefslogtreecommitdiff
path: root/plugins/lastlog.py
diff options
context:
space:
mode:
authorMaxime “pep” Buquet <pep@bouah.net>2019-06-17 14:49:10 +0200
committerMaxime “pep” Buquet <pep@bouah.net>2019-06-17 14:49:10 +0200
commitd35256ccc9cd205aa72a5599ab25db7cd7263527 (patch)
tree121ef7def819dcf41cc7a036e1985d3e2ab4b6df /plugins/lastlog.py
parent91eabbd17d6ef85c92ac3d9711cf9fc92b22d5be (diff)
parentf9d34fc789e038280b63f5b76ae0130bf05c269e (diff)
downloadpoezio-d35256ccc9cd205aa72a5599ab25db7cd7263527.tar.gz
poezio-d35256ccc9cd205aa72a5599ab25db7cd7263527.tar.bz2
poezio-d35256ccc9cd205aa72a5599ab25db7cd7263527.tar.xz
poezio-d35256ccc9cd205aa72a5599ab25db7cd7263527.zip
Merge remote-tracking branch 'origin/mr/35'
Diffstat (limited to 'plugins/lastlog.py')
-rw-r--r--plugins/lastlog.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/plugins/lastlog.py b/plugins/lastlog.py
new file mode 100644
index 00000000..fd500e08
--- /dev/null
+++ b/plugins/lastlog.py
@@ -0,0 +1,64 @@
+#! /usr/bin/env python3
+# -*- coding: utf-8 -*-
+# vim:fenc=utf-8
+#
+# Copyright © 2018 Maxime “pep” Buquet
+# Copyright © 2019 Madhur Garg
+#
+# Distributed under terms of the zlib license. See the COPYING file.
+
+"""
+ Search provided string in the buffer and return all results on the screen
+"""
+
+import re
+from poezio.plugin import BasePlugin
+from poezio import tabs
+from poezio.text_buffer import Message, TextBuffer
+
+
+def add_line(text_buffer: TextBuffer, text: str) -> None:
+ """Adds a textual entry in the TextBuffer"""
+ text_buffer.add_message(
+ text,
+ None, # Time
+ None, # Nickname
+ None, # Nick Color
+ False, # History
+ None, # User
+ False, # Highlight
+ None, # Identifier
+ None, # 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='<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_, re.I)
+
+ res = []
+ add_line(text_buffer, "Lastlog:")
+ for message in text_buffer.messages:
+ 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()