From 115e9188b91a84e19e82e61e04a87a67df93caf7 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Tue, 12 Dec 2023 20:37:58 +0200 Subject: [PATCH] Add the exit interrupt and the exit message. --- notification_client/MessagePrinter.py | 7 +++++++ notification_client/cli.py | 11 +++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/notification_client/MessagePrinter.py b/notification_client/MessagePrinter.py index db06a16..a978aff 100644 --- a/notification_client/MessagePrinter.py +++ b/notification_client/MessagePrinter.py @@ -10,3 +10,10 @@ class MessagePrinter: console.print(Markdown(full_message)) + + @staticmethod + def bye(): + console = Console() + + console.print('[green]bye[/]') + diff --git a/notification_client/cli.py b/notification_client/cli.py index b6551ec..19cd4e6 100644 --- a/notification_client/cli.py +++ b/notification_client/cli.py @@ -18,7 +18,10 @@ ############################################################################### import asyncio +import sys import typer +from notification_client.MessagePrinter import MessagePrinter + from notification_client.client import Client cli_app = typer.Typer(rich_markup_mode="rich") @@ -40,5 +43,9 @@ def up( This command [b]start[/] the [yellow b]client[/] and connects to the notification server. """ - client = Client(ip, port) - asyncio.run(client.connect()) + try: + client = Client(ip, port) + asyncio.run(client.connect()) + except KeyboardInterrupt: + MessagePrinter.bye() + sys.exit(0)