Skip to content

Commit

Permalink
Merge pull request #304 from Haidra-Org/detect-curses-init-fail
Browse files Browse the repository at this point in the history
fix do not crash if curses failed to init
  • Loading branch information
tazlin authored Sep 24, 2023
2 parents cf340bb + 63f10f3 commit 7832249
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions worker/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ def __init__(self, bridge_data):
self.audio_alerts = False
self.last_audio_alert = 0
self.stdout = DequeOutputCollector()
self._bck_stdout = sys.stdout
self.stderr = DequeOutputCollector()
self._bck_stderr = sys.stderr
self.reset_stats()
self.download_label = ""
self.download_current = None
Expand Down Expand Up @@ -801,6 +803,11 @@ def poll(self):
return None

def main_loop(self, stdscr):
if not stdscr:
self.stop()
logger.error("Failed to initialise curses")
return

self.main = stdscr
while True:
if self.should_stop:
Expand All @@ -824,6 +831,14 @@ def run(self):

def stop(self):
self.should_stop = True
# Restore the terminal
sys.stdout = self._bck_stdout
sys.stderr = self._bck_stderr

curses.nocbreak()
self.main.keypad(False)
curses.echo()
curses.endwin()

def get_hordelib_version(self):
try:
Expand Down

0 comments on commit 7832249

Please sign in to comment.