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"
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_file", type=str, nargs=1)
41 help="alphabetize card order",
47 help="delete cache 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, conf):
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])
76 if cache and conf["cache"]:
80 if args.shuffle or conf["shuffle"]:
82 if args.alphabetize or conf["alphabetize"]:
83 stack.sort(key=lambda x: x.front)
84 if args.reverse or conf["reverse"]:
91 view = conf["default_view"]
94 win = Display(stack, headers, idx, view, args, conf)
96 curses.wrapper(win.run)
97 except curses.error as e:
98 raise CursesError() from e
102 """Return original header and stack"""
103 return (headers, stack)
106 def main(args=sys.argv):
108 conf = config.read_file(args.config)
110 if not conf["debug"]:
111 sys.tracebacklimit = 0
113 global headers, stack
114 (headers, stack) = parse.parse_html(parse.md2html(args.inp[0]))
116 show(args, stack, headers, conf)
119 if __name__ == "__main__":