From 5bfca8a704b14bc4ba2d8cb1e5cfeb3cfa0afdca Mon Sep 17 00:00:00 2001 From: mathieui Date: Sun, 17 May 2020 19:47:29 +0200 Subject: Fix highlights color --- poezio/windows/base_wins.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/poezio/windows/base_wins.py b/poezio/windows/base_wins.py index d6c72912..f371c106 100644 --- a/poezio/windows/base_wins.py +++ b/poezio/windows/base_wins.py @@ -80,15 +80,18 @@ class Win: @contextmanager def colored_text(self, color: Optional[Tuple]=None, attr: Optional[int]=None): """Context manager which sets up an attr/color when inside""" - if attr is None: - if color is not None: - attr = to_curses_attr(color) - else: - yield None - return - self._win.attron(attr) + if color is None and attr is None: + yield None + return + if color is not None: + mode = to_curses_attr(color) + if attr is not None: + mode = mode | attr + else: + mode = attr + self._win.attron(mode) yield None - self._win.attroff(attr) + self._win.attroff(mode) def addstr(self, *args) -> None: """ -- cgit v1.2.3 From 01ebe78401de1a550935c489033800cbd8fd768a Mon Sep 17 00:00:00 2001 From: mathieui Date: Sun, 17 May 2020 19:48:42 +0200 Subject: Remove extra logging --- poezio/ui/render.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/poezio/ui/render.py b/poezio/ui/render.py index b8368312..a431b4e7 100644 --- a/poezio/ui/render.py +++ b/poezio/ui/render.py @@ -1,4 +1,3 @@ -import logging import curses from datetime import datetime @@ -133,7 +132,6 @@ def write_pre_message(msg: Message, win: 'Win', with_timestamps: bool, nick_size """ offset = 0 if with_timestamps: - logging.debug(msg) offset += PreMessageHelpers.write_time(win, msg.history, msg.time) if not msg.nickname: # not a message, nothing to do afterwards @@ -243,7 +241,6 @@ class PreMessageHelpers: format = LONG_FORMAT else: format = SHORT_FORMAT - logging.debug(time) time_str = time.strftime(format) color = get_theme().COLOR_TIME_STRING with buffer.colored_text(color=color): -- cgit v1.2.3 From aec4c279f27564e2e83a4f42b1c626ba50b67f95 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sun, 17 May 2020 20:37:54 +0200 Subject: Fix highlight navigation --- poezio/core/handlers.py | 6 ++++-- poezio/tabs/muctab.py | 51 ++++++++++++++++++---------------------------- poezio/windows/text_win.py | 3 +-- 3 files changed, 25 insertions(+), 35 deletions(-) diff --git a/poezio/core/handlers.py b/poezio/core/handlers.py index 01fb6062..445d8b74 100644 --- a/poezio/core/handlers.py +++ b/poezio/core/handlers.py @@ -783,6 +783,7 @@ class HandlerCore: # Messages coming from MUC barejid (Server maintenance, IRC mode # changes from biboumi, etc.) are displayed as info messages. if message['from'].resource: + highlight = tab.message_is_highlight(body, nick_from, delayed) ui_msg = PMessage( txt=body, time=date, @@ -792,6 +793,7 @@ class HandlerCore: identifier=message['id'], jid=message['from'], user=user, + highlight=highlight, ) typ = 1 else: @@ -801,8 +803,8 @@ class HandlerCore: identifier=message['id'], ) typ = 2 - - if tab.add_message(ui_msg, typ): + tab.add_message(ui_msg, typ) + if highlight: self.core.events.trigger('highlight', message, tab) if message['from'].resource == tab.own_nick: diff --git a/poezio/tabs/muctab.py b/poezio/tabs/muctab.py index f0c055b1..02964395 100644 --- a/poezio/tabs/muctab.py +++ b/poezio/tabs/muctab.py @@ -1077,13 +1077,8 @@ class MucTab(ChatTab): return user return None - def add_message(self, msg: BaseMessage, typ=1): - """ - Note that user can be None even if nickname is not None. It happens - when we receive an history message said by someone who is not - in the room anymore - Return True if the message highlighted us. False otherwise. - """ + def add_message(self, msg: BaseMessage, typ=1) -> None: + """Add a message to the text buffer and set various tab status""" # reset self-ping interval if self.self_ping_event: self.enable_self_ping_event() @@ -1095,8 +1090,7 @@ class MucTab(ChatTab): if config.get_by_tabname('notify_messages', self.jid.bare) and self.state != 'current': if msg.nickname != self.own_nick and not msg.history: self.state = 'message' - msg.highlight = self.do_highlight(msg.txt, msg.nickname, msg.delayed) - return msg.highlight + self.do_highlight(msg.txt, msg.nickname, msg.delayed) def modify_message(self, txt, @@ -1314,15 +1308,19 @@ class MucTab(ChatTab): def build_highlight_regex(self, nickname): return re.compile(r"(^|\W)" + re.escape(nickname) + r"(\W|$)", re.I) - def is_highlight(self, txt: str, nick: str, highlight_on: List[str], - delayed, corrected: bool = False): - """ - Highlight algorithm for MUC tabs - """ - + def message_is_highlight(self, txt: str, nickname: str, delayed: bool, + corrected: bool = False) -> bool: + """Highlight algorithm for MUC tabs""" + # Don't highlight on info message or our own messages + if not nickname or nickname == self.own_nick: + return False + highlight_on = config.get_by_tabname( + 'highlight_on', + self.general_jid, + ).split(':') highlighted = False if not delayed and not corrected: - if self.build_highlight_regex(nick).search(txt): + if self.build_highlight_regex(self.own_nick).search(txt): highlighted = True else: for word in highlight_on: @@ -1331,21 +1329,12 @@ class MucTab(ChatTab): break return highlighted - def do_highlight(self, txt, nickname, delayed, corrected=False): - """ - Set the tab color and returns the nick color - """ - own_nick = self.own_nick - highlight_on = config.get_by_tabname( - 'highlight_on', - self.general_jid, - ).split(':') - - # Don't highlight on info message or our own messages - if not nickname or nickname == own_nick: - return False - - highlighted = self.is_highlight(txt, own_nick, highlight_on, delayed, corrected) + def do_highlight(self, txt: str, nickname: str, delayed: bool, + corrected: bool = False) -> bool: + """Set the tab color and returns the highlight state""" + highlighted = self.message_is_highlight( + txt, nickname, delayed, corrected + ) if highlighted and self.joined: if self.state != 'current': self.state = 'highlight' diff --git a/poezio/windows/text_win.py b/poezio/windows/text_win.py index a1b12ae9..fbe3d2fa 100644 --- a/poezio/windows/text_win.py +++ b/poezio/windows/text_win.py @@ -85,7 +85,6 @@ class TextWin(Win): def build_new_message(self, message: BaseMessage, clean: bool = True, - highlight: bool = False, timestamp: bool = False, nick_size: int = 10) -> int: """ @@ -106,7 +105,7 @@ class TextWin(Win): self.built_lines.extend(lines) if not lines or not lines[0]: return 0 - if highlight: + if isinstance(message, Message) and message.highlight: self.highlights.append(lines[0]) self.nb_of_highlights_after_separator += 1 log.debug("Number of highlights after separator is now %s", -- cgit v1.2.3 From 6057d0dc9b7c78090eb2a64e45fd427f5d641131 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sun, 17 May 2020 20:42:21 +0200 Subject: Fix a corner case with correction when moving between highlights (there are still a few but this one would wipe all other highlights, making it a bit painful) --- poezio/windows/text_win.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/poezio/windows/text_win.py b/poezio/windows/text_win.py index fbe3d2fa..9e6641f7 100644 --- a/poezio/windows/text_win.py +++ b/poezio/windows/text_win.py @@ -243,7 +243,7 @@ class TextWin(Win): try: pos = self.built_lines.index(hl) except ValueError: - self.highlights = self.highlights[self.hl_pos + 1:] + del self.highlights[self.hl_pos] if not self.highlights: self.hl_pos = float('nan') self.pos = 0 @@ -277,7 +277,7 @@ class TextWin(Win): try: pos = self.built_lines.index(hl) except ValueError: - self.highlights = self.highlights[self.hl_pos + 1:] + del self.highlights[self.hl_pos] if not self.highlights: self.hl_pos = float('nan') self.pos = 0 -- cgit v1.2.3 From 551828607c7644d7af6b5889c7ffb2f28eeefee9 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sun, 17 May 2020 21:14:23 +0200 Subject: Fix highlight display on corrections --- poezio/tabs/muctab.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/poezio/tabs/muctab.py b/poezio/tabs/muctab.py index 02964395..d4ff1d48 100644 --- a/poezio/tabs/muctab.py +++ b/poezio/tabs/muctab.py @@ -1101,7 +1101,9 @@ class MucTab(ChatTab): nickname=None, user=None, jid=None): - highlight = self.do_highlight(txt, nickname, delayed, corrected=True) + highlight = self.message_is_highlight( + txt, nickname, delayed, corrected=True + ) message = self._text_buffer.modify_message( txt, old_id, @@ -1319,7 +1321,7 @@ class MucTab(ChatTab): self.general_jid, ).split(':') highlighted = False - if not delayed and not corrected: + if not delayed: if self.build_highlight_regex(self.own_nick).search(txt): highlighted = True else: @@ -1335,7 +1337,7 @@ class MucTab(ChatTab): highlighted = self.message_is_highlight( txt, nickname, delayed, corrected ) - if highlighted and self.joined: + if highlighted and self.joined and not corrected: if self.state != 'current': self.state = 'highlight' beep_on = config.get('beep_on').split() -- cgit v1.2.3