From ef51c95a08228de5ae0e5e0f9a803a6835dc74fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 6 Mar 2019 16:23:39 +0100 Subject: [PATCH] buffer: Allow the buffer name to be human readable. --- matrix/buffer.py | 21 +++++++++++++++++---- matrix/config.py | 17 +++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/matrix/buffer.py b/matrix/buffer.py index 663ebaf..232265b 100644 --- a/matrix/buffer.py +++ b/matrix/buffer.py @@ -803,15 +803,23 @@ class WeechatChannelBuffer(object): def short_name(self): return W.buffer_get_string(self._ptr, "short_name") + @short_name.setter + def short_name(self, name): + W.buffer_set(self._ptr, "short_name", name) + + @property + def name(self): + return W.buffer_get_string(self._ptr, "name") + + @name.setter + def name(self, name): + W.buffer_set(self._ptr, "name", name) + @property def number(self): """Get the buffer number, starts at 1.""" return int(W.buffer_get_integer(self._ptr, "number")) - @short_name.setter - def short_name(self, name): - W.buffer_set(self._ptr, "short_name", name) - def find_lines(self, predicate, max_lines=None): lines = [] count = 0 @@ -846,6 +854,7 @@ class RoomBuffer(object): self.last_read_event = None self._read_markers_enabled = True + self.server_name = server_name buffer_name = "{}.{}".format(server_name, room.room_id) @@ -1073,6 +1082,10 @@ class RoomBuffer(object): room_name = self.room.display_name self.weechat_buffer.short_name = room_name + if G.CONFIG.human_buffer_names: + buffer_name = "{}.{}".format(self.server_name, room_name) + self.weechat_buffer.name = buffer_name + def _redact_line(self, event): def predicate(event_id, line): def already_redacted(tags): diff --git a/matrix/config.py b/matrix/config.py index d8676db..6426c9d 100644 --- a/matrix/config.py +++ b/matrix/config.py @@ -399,6 +399,7 @@ class MatrixConfig(WeechatConfig): self.upload_buffer = "" self.debug_category = "all" self.page_up_hook = None + self.human_buffer_names = None look_options = [ Option( @@ -519,6 +520,18 @@ class MatrixConfig(WeechatConfig): ("Number of spaces to add as a margin around around a code " "block"), ), + Option( + "human_buffer_names", + "boolean", + "", + 0, + 0, + "off", + ("If turned on the buffer name will consist of the server " + "name and the room name instead of the room_id. Note, this " + "requires a change to the logger.file.mask setting since " + "conflicts can happen otherwise."), + ), ] network_options = [ @@ -769,6 +782,10 @@ class MatrixConfig(WeechatConfig): "", ) + def read(self): + super().read() + self.human_buffer_names = self.look.human_buffer_names + def free(self): section_ptr = W.config_search_section(self._ptr, "server") W.config_section_free(section_ptr)