Commits

Jason Scheirer  committed 657a246

Better main loop

  • Participants
  • Parent commits 0129943

Comments (0)

Files changed (1)

File curses_ui.py

 import curses
 import datetime
+import signal
 from bikesniff import gpsfix, networks
 
 class CursesUI(object):
         curses.cbreak()
         self.stdscr.keypad(1)
         self.stdscr.nodelay(1)
-    def shutdown(self):
+        signal.signal(signal.SIGINT, self.shutdown)
+    def shutdown(self, sig=None, frame=None):
         curses.nocbreak()
         self.stdscr.keypad(0)
         curses.echo()
         curses.endwin()
+        self.reactor.stop()
     def update(self):
         try:
-            self.stdscr.addstr(0, 0, str(datetime.datetime.now()), curses.A_BOLD)
-            curses.setsyx(self.stdscr.height, self.stdscr.width)
+            self.stdscr.addstr(1, 1, str(datetime.datetime.now()), curses.A_BOLD)
+            self.stdscr.border()
             self.stdscr.refresh()
         except:
             pass
         finally:
-            if self.stdscr.getch() in (27, ord('q'), ord('Q')):
+            if self.stdscr.getch() in (27, ord('q'), ord('Q'), curses.KEY_BREAK):
                 self.shutdown()
-                self.reactor.stop()
             else:
                 self.reactor.callLater(0.5, self.update)