]> git.armaanb.net Git - lightcards.git/blobdiff - lightcards/lightcards.py
Cache the stack and headers
[lightcards.git] / lightcards / lightcards.py
index a3aa5cff0a1529cecfc7b8ccbc1a654b32dec29e..b4b459860ae535e95bc7a8fe72165d66b79d11a1 100644 (file)
@@ -7,7 +7,7 @@ import os
 from random import shuffle
 import sys
 
-from . import parse
+from . import parse, progress
 from .display import Display
 from .deck import Status
 
@@ -21,6 +21,12 @@ def parse_args():
     parser.add_argument("-f", "--flip",
                         action='store_true',
                         help="show second column first")
+    parser.add_argument("-p", "--purge",
+                        action='store_true',
+                        help="don't check cached info before starting")
+    parser.add_argument("-P", "--purge-all",
+                        action='store_true',
+                        help="don't check cached info before starting")
     parser.add_argument("-r", "--reverse",
                         action='store_true',
                         help="reverse card order")
@@ -38,7 +44,25 @@ def show(args, stack, headers):
     Manipulate deck according to passed arguments, and send it to the display
     functions
     """
-    idx = Status()
+    if args.purge:
+        progress.purge(stack)
+    if args.purge_all:
+        progress.purge_all()
+
+    ida = progress.dive("status", stack)
+    if ida and not args.purge:
+        idx = ida
+    else:
+        idx = Status()
+
+    stackb = progress.dive("stack", stack)
+    if stackb and not args.purge:
+        stack = stackb
+
+    headerb = progress.dive("headers", stack)
+    if headerb and not args.purge:
+        headers = headerb
+
     if args.flip:
         for x in stack:
             x[0], x[1] = x[1], x[0]