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"
28 help="specify which view to start in (default = 1)",
30 parser.add_argument("inp", metavar="input file", type=str, nargs=1)
35 help="alphabetize card order",
41 help="don't check cached info before starting",
44 "-r", "--reverse", action="store_true", help="reverse card order"
47 "-s", "--shuffle", action="store_true", help="shuffle card order"
53 version=f"lightcards {pkg_resources.require('lightcards')[0].version}",
55 return parser.parse_args()
58 def show(args, stack, headers):
60 Get objects from cache, manipulate deck according to passed arguments, and
61 send it to the display functions
63 # Purge caches if asked
65 progress.purge(get_orig()[1])
69 cache = progress.dive(get_orig()[1])
77 stack.sort(key=lambda x: x.front)
82 win = Display(stack, headers, idx, args.view)
84 curses.wrapper(win.run)
85 except curses.error as e:
86 raise CursesError() from e
90 """Parse arguments and input file again"""
92 os.system(f"$EDITOR {args.inp[0]}"),
93 return parse.parse_html(parse.md2html(args.inp[0]))
97 """Return original header and stack"""
98 return (headers, stack)
101 def main(args=sys.argv):
102 sys.tracebacklimit = 0
104 global headers, stack
105 (headers, stack) = parse.parse_html(parse.md2html(args.inp[0]))
106 show(args, stack, headers)
109 if __name__ == "__main__":