From d9359f2d441e354af6365300601729f10e00a306 Mon Sep 17 00:00:00 2001 From: dimyme Date: Tue, 19 Nov 2019 22:04:08 +0100 Subject: [PATCH] clean exit of curses console --- src/bitmessagecurses/__init__.py | 50 ++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/src/bitmessagecurses/__init__.py b/src/bitmessagecurses/__init__.py index 80dc3f14..21420f8d 100644 --- a/src/bitmessagecurses/__init__.py +++ b/src/bitmessagecurses/__init__.py @@ -1,7 +1,9 @@ -""" +# -*- coding: UTF-8 -*- +# kate: syntax Python ; +''' src/bitmessagecurses/__init__.py ================================ -""" +''' # Copyright (c) 2014 Luke Montalvo # This file adds a alternative commandline interface, feel free to critique and fork @@ -9,7 +11,7 @@ src/bitmessagecurses/__init__.py # This has only been tested on Arch Linux and Linux Mint # Dependencies: # * from python2-pip -# * python2-pythondialog +# * python2-pythondialog # * dialog import ConfigParser @@ -144,9 +146,9 @@ def resetlookups(): Timer(1, resetlookups, ()).start() -def drawtab(stdscr): # pylint: disable=too-many-branches, too-many-statements - """Method for drawing different tabs""" - if menutab in range(1, len(menu) + 1): +def drawtab(stdscr): # pylint: disable=too-many-branches, too-many-statements + '''Method for drawing different tabs''' + if menutab in range(1, len(menu) + 1): # pylint: disable=too-many-nested-blocks if menutab == 1: # Inbox stdscr.addstr(3, 5, "To", curses.A_BOLD) stdscr.addstr(3, 40, "From", curses.A_BOLD) @@ -253,19 +255,21 @@ def drawtab(stdscr): # pylint: disable=too-many-branches, too-many-statem stdscr.addstr(6, 18, "Connections", curses.A_BOLD) stdscr.hline(7, 6, '-', 23) streamcount = [] - for host, stream in connected_hosts: - if stream >= len(streamcount): - streamcount.append(1) - else: - streamcount[stream] += 1 - for i, item in enumerate(streamcount): - if i < 4: - if i == 0: - stdscr.addstr(8 + i, 6, "?") + try: + for host, stream in connected_hosts: + if stream >= len(streamcount): + streamcount.append(1) else: - stdscr.addstr(8 + i, 6, str(i)) - stdscr.addstr(8 + i, 18, str(item).ljust(2)) - + streamcount[stream] += 1 + for i, item in enumerate(streamcount): + if i < 4: + if i == 0: + stdscr.addstr(8 + i, 6, "?") + else: + stdscr.addstr(8 + i, 6, str(i)) + stdscr.addstr(8 + i, 18, str(item).ljust(2)) + except: + pass # Uptime and processing data stdscr.addstr(6, 35, "Since startup on " + l10n.formatTimestamp(startuptime, False)) stdscr.addstr(7, 40, "Processed " + str( @@ -1202,8 +1206,12 @@ def runwrapper(): curses.curs_set(0) stdscr.timeout(1000) - curses.wrapper(run) - doShutdown() + try: + curses.wrapper(run) + except BaseException: + pass + finally: + doShutdown() def run(stdscr): @@ -1259,5 +1267,5 @@ def doShutdown(): shutdown.doCleanShutdown() sys.stdout = sys.__stdout__ sys.stderr = sys.__stderr__ - + curses.endwin() os._exit(0) # pylint: disable=protected-access