From a5b85bbe5a2f430a19433faf06ac80df195fc012 Mon Sep 17 00:00:00 2001 From: troido Date: Wed, 23 May 2018 21:45:51 +0200 Subject: [PATCH] properly clean up after crash put cleanup in finally block so it happens no matter the crash this should prevend scrambled lines all over the terminal --- botany.py | 11 +++++++---- menu_screen.py | 13 ++++++++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/botany.py b/botany.py index f8cd97c..c634fdf 100755 --- a/botany.py +++ b/botany.py @@ -622,7 +622,10 @@ if __name__ == '__main__': # my_plant is either a fresh plant or an existing plant at this point my_plant.start_life() my_data.start_threads(my_plant) - botany_menu = CursedMenu(my_plant,my_data) - my_data.save_plant(my_plant) - my_data.data_write_json(my_plant) - my_data.update_garden_db(my_plant) + try: + botany_menu = CursedMenu(my_plant,my_data) + my_data.save_plant(my_plant) + my_data.data_write_json(my_plant) + my_data.update_garden_db(my_plant) + finally: + cleanup() diff --git a/menu_screen.py b/menu_screen.py index 4cb7a1b..177c2f7 100644 --- a/menu_screen.py +++ b/menu_screen.py @@ -670,7 +670,14 @@ class CursedMenu(object): def __exit__(self): self.exit = True - curses.curs_set(2) - curses.endwin() - os.system('clear') + cleanup() + +def cleanup(): + try: + curses.curs_set(2) + except curses.error: + # cursor not supported; just ignore + pass + curses.endwin() + os.system('clear')