]> git.armaanb.net Git - lightcards.git/blobdiff - lightcards/display.py
Add preliminary pickle support
[lightcards.git] / lightcards / display.py
index 940d15efadae8e254c3e14a722ed0dd85a075ecd..1035d76eb337fb81a6af3957c0c586c4090575b3 100644 (file)
@@ -6,7 +6,7 @@ from random import shuffle
 import sys
 import textwrap
 
-from . import lightcards
+from . import lightcards, progress
 
 
 class Display():
@@ -23,6 +23,10 @@ class Display():
         curses.init_pair(3, curses.COLOR_YELLOW, 0)
         self.get_key()
 
+    def leave(self):
+        progress.dump(self.obj, "status", self.stack)
+        sys.exit(0)
+
     def disp_bar(self):
         """
         Display the statusbar at the bottom of the screen with progress, star
@@ -73,7 +77,7 @@ class Display():
             key = self.win.getkey()
             if key == "q":
                 if len(self.stack) == self.obj.getIdx():
-                    sys.exit(0)
+                    self.leave()
                 elif len(self.stack) < self.obj.getIdx():
                     self.obj.setIdx(0)
                 self.get_key()
@@ -226,7 +230,7 @@ class Display():
         while True:
             key = self.win.getkey()
             if key == "q":
-                sys.exit(0)
+                self.leave()
             elif key in ["l", "KEY_RIGHT"]:
                 self.obj.forward(self.stack)
                 self.obj.setSide(0)