From b684ad2b2fa0ba87190a989e15f63eaa73d3b581 Mon Sep 17 00:00:00 2001 From: nojhan Date: Sat, 17 Feb 2024 11:55:19 +0100 Subject: [PATCH] fix duplicate messages and remove Rich's highlighting --- src/clibard/clibard.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/clibard/clibard.py b/src/clibard/clibard.py index 3350970..7dabf93 100755 --- a/src/clibard/clibard.py +++ b/src/clibard/clibard.py @@ -152,6 +152,13 @@ class Message: for k in self.color: self._style[k] = f"color({self.color[k]})" + def __eq__(self, other): + # Do not take date into account if it's already a duplicate. + return self.app == other.app \ + and self.summary == other.summary \ + and self.body == other.body \ + and self.urgency == other.urgency + def style(self, key): if "reset" in key or "none" in key: @@ -235,9 +242,15 @@ class Broker: if notification.get_member() == "Notify" and notification.get_interface() == 'org.freedesktop.Notifications': msg = Message(notification) mlen = msg.print_on(None) - self.deck.append((msg, mlen)) - if len(self.deck) > self.max_msg: - del self.deck[0] + if len(self.deck) == 0: + self.deck.append( (msg, mlen) ) + else: + last_msg,last_mlen = self.deck.pop() + self.deck.append( (last_msg, last_mlen) ) + if msg != last_msg: # We don't want duplicate in the last place. + self.deck.append( (msg, mlen) ) + if len(self.deck) > self.max_msg: + self.deck.popleft() self.print() @@ -250,7 +263,7 @@ class Broker: def print(self): # print(len(self.deck),"message in deck") - console = Console() # Re-instantiate in case the terminal window changed. + console = Console(highlight=False) # Re-instantiate in case the terminal window changed. if len(self.bounds) == 2: console.print(f"\r{self.bounds[0]}", end="\r") else: