From 7038e8f852d9038f295afdf599c2633d8613f04e Mon Sep 17 00:00:00 2001 From: Richard Date: Mon, 25 Dec 2023 07:53:38 +0100 Subject: [PATCH] exit gracefully on ctrlc --- main.py | 0 nullptr/command_line.py | 6 ++++-- nullptr/commander.py | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) mode change 100755 => 100644 main.py diff --git a/main.py b/main.py old mode 100755 new mode 100644 diff --git a/nullptr/command_line.py b/nullptr/command_line.py index 100fe2c..e61e9b7 100644 --- a/nullptr/command_line.py +++ b/nullptr/command_line.py @@ -87,11 +87,13 @@ class CommandLine: p = self.prompt() try: c = input(p) - except EOFError: + except (EOFError, KeyboardInterrupt): self.handle_eof() break try: self.handle_cmd(c) - except Exception as e: + except KeyboardInterrupt: + print("Interrupted") + except (Exception) as e: logging.error(e, exc_info=True) diff --git a/nullptr/commander.py b/nullptr/commander.py index a2c3069..34a8694 100644 --- a/nullptr/commander.py +++ b/nullptr/commander.py @@ -24,6 +24,10 @@ class Commander(CommandLine): self.stop_auto= False super().__init__() + def handle_eof(self): + self.store.close() + print("Goodbye!") + def prompt(self): if self.ship: return f'{self.ship.symbol}> '