]> git.armaanb.net Git - lightcards.git/blobdiff - lightcards/lightcards.py
Add preliminary pickle support
[lightcards.git] / lightcards / lightcards.py
old mode 100755 (executable)
new mode 100644 (file)
index 66d1231..d170b35
@@ -1,13 +1,14 @@
-#!/usr/bin/env python
 # Markdown flashcard utility
 # Armaan Bhojwani 2021
 
 import argparse
 from curses import wrapper
+import os
 from random import shuffle
 import sys
 
-from . import display, parse
+from . import parse, progress
+from .display import Display
 from .deck import Status
 
 
@@ -20,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")
@@ -28,7 +35,7 @@ def parse_args():
                         help="shuffle card order")
     parser.add_argument("-v", "--version",
                         action='version',
-                        version="lightcards 0.3.0")
+                        version="lightcards 0.4.0")
     return parser.parse_args()
 
 
@@ -37,7 +44,17 @@ 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()
+
     if args.flip:
         for x in stack:
             x[0], x[1] = x[1], x[0]
@@ -46,11 +63,24 @@ def show(args, stack, headers):
         shuffle(stack)
     elif args.reverse:
         stack.reverse()
-    wrapper(display.init_disp, stack, headers, idx)
 
+    win = Display(stack, headers, idx)
+    wrapper(win.run)
+
+
+def reparse():
+    """Parse arguments and input file again"""
+    args = parse_args()
+    os.system(f"$EDITOR {args.inp[0]}"),
+    return parse.parse_html(parse.md2html(args.inp[0]))
+
+def get_orig():
+    """Return original header and stack"""
+    return((headers, stack))
 
 def main(args=sys.argv):
     args = parse_args()
+    global headers, stack
     (headers, stack) = parse.parse_html(parse.md2html(args.inp[0]))
     show(args, stack, headers)