1 # Markdown flashcard utility
8 from random import shuffle
11 from . import parse, progress
12 from .display import Display, CursesError
13 from .deck import Status
17 """Parse command line arguments"""
18 parser = argparse.ArgumentParser(
19 description="Terminal flashcards from Markdown"
25 help="specify custom config file",
34 help="specify which view to start in (default = 1)",
36 parser.add_argument("inp", metavar="input file", type=str, nargs=1)
41 help="alphabetize card order",
47 help="don't check cached info before starting",
50 "-r", "--reverse", action="store_true", help="reverse card order"
53 "-s", "--shuffle", action="store_true", help="shuffle card order"
59 version=f"lightcards {pkg_resources.require('lightcards')[0].version}",
61 return parser.parse_args()
64 def show(args, stack, headers, input_file):
66 Get objects from cache, manipulate deck according to passed arguments, and
67 send it to the display functions
69 # Purge caches if asked
71 progress.purge(get_orig()[1])
75 cache = progress.dive(get_orig()[1])
83 stack.sort(key=lambda x: x.front)
88 win = Display(stack, headers, idx, args.view, input_file)
90 curses.wrapper(win.run)
91 except curses.error as e:
92 raise CursesError() from e
96 """Return original header and stack"""
97 return (headers, stack)
100 def main(args=sys.argv):
101 sys.tracebacklimit = 0
103 global headers, stack
104 (headers, stack) = parse.parse_html(parse.md2html(args.inp[0]))
105 show(args, stack, headers, args)
108 if __name__ == "__main__":