1 # Markdown flashcard utility
7 from random import shuffle
10 from . import parse, progress, config
11 from .display import Display, CursesError
12 from .deck import Status
16 """Parse command line arguments"""
17 parser = argparse.ArgumentParser(
18 description="Terminal flashcards from Markdown"
24 help="specify custom config file",
33 help="specify which view to start in (default = 1)",
35 parser.add_argument("inp", metavar="input file", type=str, nargs=1)
40 help="alphabetize card order",
46 help="don't check cached info before starting",
49 "-r", "--reverse", action="store_true", help="reverse card order"
52 "-s", "--shuffle", action="store_true", help="shuffle card order"
58 version=f"lightcards {pkg_resources.require('lightcards')[0].version}",
60 return parser.parse_args()
63 def show(args, stack, headers, conf):
65 Get objects from cache, manipulate deck according to passed arguments, and
66 send it to the display functions
68 # Purge caches if asked
70 progress.purge(get_orig()[1])
74 cache = progress.dive(get_orig()[1])
82 stack.sort(key=lambda x: x.front)
87 win = Display(stack, headers, idx, args.view, args, conf)
89 curses.wrapper(win.run)
90 except curses.error as e:
91 raise CursesError() from e
95 """Return original header and stack"""
96 return (headers, stack)
99 def main(args=sys.argv):
101 global headers, stack
102 (headers, stack) = parse.parse_html(parse.md2html(args.inp[0]))
103 conf = config.read_file(args.config)
105 if not conf["debug"]:
106 sys.tracebacklimit = 0
108 show(args, stack, headers, conf)
111 if __name__ == "__main__":