From 4849ee912094587c48d9015507cd7155dfd4ed0a Mon Sep 17 00:00:00 2001 From: nojhan Date: Fri, 17 Jan 2025 10:50:43 +0100 Subject: [PATCH] feat: changing layout changes theme --- pyproject.toml | 15 +++++++++++++++ src/clibard/clibard.py | 38 +++++++++++++++++++++++++++++++------- 2 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..b959cb2 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,15 @@ +[tool.poetry] +name = "clibard" +version = "0.1.0" +description = "See all your notifications in the terminal" +authors = ["nojhan "] +readme = "README.md" + +[tool.poetry.dependencies] +python = "^3.11" +faker = "^0.7.4" +humanize = "^4.11" +rich = "^13.9" +dbus-python = "^1.3" +PyGObject = "^3.50" # You may need to install the system package for libgirepository1.0-dev + diff --git a/src/clibard/clibard.py b/src/clibard/clibard.py index 0127dba..aeee8fd 100755 --- a/src/clibard/clibard.py +++ b/src/clibard/clibard.py @@ -201,6 +201,7 @@ class Message: self.last_color = f"{self.style(key)}" +class MessageLine(Message): def print_on(self, console = None, end = ""): hdate = humanize.naturaltime(self.date) if console != None: @@ -208,18 +209,41 @@ class Message: self.print_segment("date", hdate, console) self.print_segment(self.urgency, self.app, console, prefix = "bold") self.print_segment(f"summary_{self.urgency}", self.summary, console, prefix = "bold") - self.print_segment("body", self.body, console) + body = " ".join(self.body.split()) + self.print_segment("body", body, console) self.print_segment("none", "", console) + console.print("", end="\n") console.print(end, end="") return len(hdate) + len(self.app) + len(self.summary) + len(self.body) + 6 +class MessageParagraph(Message): + def print_on(self, console = None, end = ""): + hdate = humanize.naturaltime(self.date) + if console != None: + # console.print(" ", end="") + # self.print_segment("date", hdate, console) + self.print_segment(self.urgency, self.app, console, prefix = "bold") + self.print_segment(f"summary_{self.urgency}", self.summary, console, prefix = "bold") + self.print_segment("none", "", console) + console.print("\n", end="") + body = " ".join(self.body.split()) + self.print_segment("body", body, console) + self.print_segment("none", "", console) + console.print("", end="\n") + console.print(end, end="") + + return len(hdate) + len(self.app) + len(self.summary) + len(self.body) + 6 + + + class Broker: - def __init__(self, max_msg = 100, bounds = ""): + def __init__(self, max_msg = 100, bounds = "", msg_cls = Message): self.max_msg = max_msg self.bounds = bounds + self.msg_cls = msg_cls self.deck = collections.deque() @@ -245,7 +269,7 @@ class Broker: # print("Interface:", notification.get_interface(), flush = True) if notification.get_member() == "Notify" and notification.get_interface() == 'org.freedesktop.Notifications': - msg = Message(notification) + msg = self.msg_cls(notification) mlen = msg.print_on(None) if len(self.deck) == 0: self.deck.append( (msg, mlen) ) @@ -274,8 +298,8 @@ class Broker: class HorizontalBroker(Broker): - def __init__(self, max_msg = 100, bounds = ""): - super().__init__(max_msg, bounds) + def __init__(self, max_msg = 100, bounds = "", msg_cls = MessageLine): + super().__init__(max_msg, bounds, msg_cls) def width(self, deck): @@ -315,8 +339,8 @@ class HorizontalBroker(Broker): class VerticalBroker(Broker): - def __init__(self, max_msg = 100, bounds = ""): - super().__init__(max_msg, bounds) + def __init__(self, max_msg = 100, bounds = "", msg_cls = MessageParagraph): + super().__init__(max_msg, bounds, msg_cls) def print(self):