From 1bd5fd514514de4b12b530700ae14c7121af723b Mon Sep 17 00:00:00 2001 From: KKlochko Date: Tue, 12 Dec 2023 18:03:11 +0200 Subject: [PATCH] Add the MessagePrinter to print a message in Markdown. --- notification_client/MessagePrinter.py | 12 ++++++++++++ notification_client/client.py | 3 +++ 2 files changed, 15 insertions(+) create mode 100644 notification_client/MessagePrinter.py diff --git a/notification_client/MessagePrinter.py b/notification_client/MessagePrinter.py new file mode 100644 index 0000000..db06a16 --- /dev/null +++ b/notification_client/MessagePrinter.py @@ -0,0 +1,12 @@ +from rich.console import Console +from rich.markdown import Markdown + +class MessagePrinter: + @staticmethod + def print(title: str, message: str): + console = Console() + + full_message = f'# {title}\n{message}' + + console.print(Markdown(full_message)) + diff --git a/notification_client/client.py b/notification_client/client.py index de86e33..154d639 100644 --- a/notification_client/client.py +++ b/notification_client/client.py @@ -19,6 +19,7 @@ import asyncio import struct +from notification_client.MessagePrinter import MessagePrinter class Client: @@ -44,6 +45,8 @@ class Client: title = await self.receive_message(reader) message = await self.receive_message(reader) + MessagePrinter.print(title, message) + except asyncio.CancelledError: print('Something went wrong') finally: