exit gracefully on ctrlc

This commit is contained in:
Richard 2023-12-25 07:53:38 +01:00
parent 7fd6b6ab51
commit 7038e8f852
3 changed files with 8 additions and 2 deletions

0
main.py Executable file → Normal file
View File

View File

@ -87,11 +87,13 @@ class CommandLine:
p = self.prompt() p = self.prompt()
try: try:
c = input(p) c = input(p)
except EOFError: except (EOFError, KeyboardInterrupt):
self.handle_eof() self.handle_eof()
break break
try: try:
self.handle_cmd(c) self.handle_cmd(c)
except Exception as e: except KeyboardInterrupt:
print("Interrupted")
except (Exception) as e:
logging.error(e, exc_info=True) logging.error(e, exc_info=True)

View File

@ -24,6 +24,10 @@ class Commander(CommandLine):
self.stop_auto= False self.stop_auto= False
super().__init__() super().__init__()
def handle_eof(self):
self.store.close()
print("Goodbye!")
def prompt(self): def prompt(self):
if self.ship: if self.ship:
return f'{self.ship.symbol}> ' return f'{self.ship.symbol}> '