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",
32 help="specify which view to start in (default = 1)",
34 parser.add_argument("inp", metavar="input file", type=str, nargs=1)
39 help="alphabetize card order",
45 help="don't check cached info before starting",
48 "-r", "--reverse", action="store_true", help="reverse card order"
51 "-s", "--shuffle", action="store_true", help="shuffle card order"
57 version=f"lightcards {pkg_resources.require('lightcards')[0].version}",
59 return parser.parse_args()
62 def show(args, stack, headers, conf):
64 Get objects from cache, manipulate deck according to passed arguments, and
65 send it to the display functions
67 # Purge caches if asked
69 progress.purge(get_orig()[1])
73 cache = progress.dive(get_orig()[1])
74 if cache and conf["cache"]:
78 if args.shuffle or conf["shuffle"]:
80 if args.alphabetize or conf["alphabetize"]:
81 stack.sort(key=lambda x: x.front)
82 if args.reverse or conf["reverse"]:
89 view = conf["default_view"]
92 win = Display(stack, headers, idx, view, args, conf)
94 curses.wrapper(win.run)
95 except curses.error as e:
96 raise CursesError() from e
100 """Return original header and stack"""
101 return (headers, stack)
104 def main(args=sys.argv):
106 conf = config.read_file(args.config)
108 global headers, stack
109 (headers, stack) = parse.parse_html(parse.md2html(args.inp[0]))
111 if not conf["debug"]:
112 sys.tracebacklimit = 0
114 show(args, stack, headers, conf)
117 if __name__ == "__main__":