1 # Markdown flashcard utility
7 from random import shuffle
10 from . import parse, progress, config
11 from .display import Display
12 from .deck import Status
16 """Parse command line arguments"""
17 parser = argparse.ArgumentParser(
18 description="Terminal flashcards from Markdown"
23 metavar="config_file",
26 help="specify custom config file",
34 help="specify which view to start in",
36 parser.add_argument("inp", metavar="input_files", type=str, nargs="+")
41 help="don't raise exception if tables are malformed",
48 help="specify which table to use if multiple are given",
54 help="alphabetize card order",
60 help="delete cache before starting",
63 "-r", "--reverse", action="store_true", help="reverse card order"
66 "-s", "--shuffle", action="store_true", help="shuffle card order"
72 version=f"lightcards {pkg_resources.require('lightcards')[0].version}",
74 return parser.parse_args()
77 def show(args, stack, headers, conf):
79 Get objects from cache, manipulate deck according to passed arguments, and
80 send it to the display functions
82 # Purge caches if asked
84 progress.purge(get_orig()[1])
88 cache = progress.dive(get_orig()[1])
89 if cache and conf["cache"]:
93 if args.shuffle or conf["shuffle"]:
95 if args.alphabetize or conf["alphabetize"]:
96 stack.sort(key=lambda x: x.front)
97 if args.reverse or conf["reverse"]:
104 view = conf["default_view"]
107 win = Display(stack, headers, idx, view, args, conf)
109 curses.wrapper(win.run)
110 except curses.error as e:
115 """Return original header and stack"""
116 return (headers, stack)
119 def main(args=sys.argv):
121 conf = config.read_file(args.config)
123 if not conf["debug"]:
124 sys.tracebacklimit = 0
126 global headers, stack
127 (headers, stack) = parse.parse_html(parse.md2html(args.inp), args, conf)
129 show(args, stack, headers, conf)
132 if __name__ == "__main__":