+++ /dev/null
-import sys
-import lightcards.lightcards
-
-lightcards.lightcards.main(sys.argv)
import sys
import textwrap
-from . import lightcards
+from . import lightcards, progress
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
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()
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)
from random import shuffle
import sys
-from . import parse
+from . import parse, progress
from .display import Display
from .deck import Status
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")
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]
--- /dev/null
+# Save and resume progress in lightcards
+# Armaan Bhojwani 2021
+
+import hashlib
+import os
+import pickle
+import shutil
+
+
+def gen_hash(inp):
+ hasher = hashlib.md5()
+ hasher.update(inp)
+
+ return(hasher.hexdigest())
+
+
+def name_gen(stra):
+ return gen_hash(str(stra).encode("utf-8"))
+
+
+def dump(obj, typer, stra):
+ dired = f"{os.path.expanduser('~')}/.cache/lightcards/{name_gen(stra)}/"
+ if os.path.exists(dired):
+ shutil.rmtree(dired)
+ os.makedirs(dired)
+
+ pickle.dump(obj, open(f"{dired}/{typer}.p", "wb"))
+
+
+def dive(typer, stra):
+ file = f"{os.path.expanduser('~')}/.cache/lightcards/{name_gen(stra)}/" + \
+ f"{typer}.p"
+ if os.path.exists(file):
+ return pickle.load(open(file, "rb"))
+ else:
+ return False
+
+
+def purge(stra):
+ dired = f"{os.path.expanduser('~')}/.cache/lightcards/{name_gen(stra)}/"
+ shutil.rmtree(dired)
+
+def purge_all():
+ dired = f"{os.path.expanduser('~')}/.cache/lightcards/"
+ shutil.rmtree(dired)
+
+def main():
+ pass
+
+
+if __name__ == "__main__":
+ main()
\f[B]-f\f[R], \f[B]\[en]flip\f[R]
Show second column first
.TP
+\f[B]-p\f[R], \f[B]\[en]purge\f[R]
+Purge cache for chosen set
+.TP
+\f[B]-P\f[R], \f[B]\[en]purge-all\f[R]
+Purge all caches
+.TP
\f[B]-r\f[R], \f[B]\[en]reverse\f[R]
Reverse card order.
Has no effect when shuffling as well
**-f**, **--flip**
: Show second column first
+**-p**, **--purge**
+: Purge cache for chosen set
+
+**-P**, **--purge-all**
+: Purge all caches
+
**-r**, **--reverse**
: Reverse card order. Has no effect when shuffling as well