]> git.armaanb.net Git - lightcards.git/blobdiff - lightcards/runner.py
Allow for config files to be incomplete
[lightcards.git] / lightcards / runner.py
index 7c730776bb3a436ea4084a8e8413acf863e40bdf..15a622983235a671fd6b330b7efe75a6bd42dc55 100644 (file)
@@ -3,12 +3,11 @@
 
 import argparse
 import curses
 
 import argparse
 import curses
-import os
 import pkg_resources
 from random import shuffle
 import sys
 
 import pkg_resources
 from random import shuffle
 import sys
 
-from . import parse, progress
+from . import parse, progress, config
 from .display import Display, CursesError
 from .deck import Status
 
 from .display import Display, CursesError
 from .deck import Status
 
@@ -18,6 +17,12 @@ def parse_args():
     parser = argparse.ArgumentParser(
         description="Terminal flashcards from Markdown"
     )
     parser = argparse.ArgumentParser(
         description="Terminal flashcards from Markdown"
     )
+    parser.add_argument(
+        "-c",
+        "--config",
+        type=str,
+        help="specify custom config file",
+    )
     parser.add_argument(
         "-V",
         "--view",
     parser.add_argument(
         "-V",
         "--view",
@@ -55,7 +60,7 @@ def parse_args():
     return parser.parse_args()
 
 
     return parser.parse_args()
 
 
-def show(args, stack, headers):
+def show(args, stack, headers, conf):
     """
     Get objects from cache, manipulate deck according to passed arguments, and
     send it to the display functions
     """
     Get objects from cache, manipulate deck according to passed arguments, and
     send it to the display functions
@@ -79,31 +84,28 @@ def show(args, stack, headers):
         stack.reverse()
 
     # Send to display
         stack.reverse()
 
     # Send to display
-    win = Display(stack, headers, idx, args.view)
+    win = Display(stack, headers, idx, args.view, args, conf)
     try:
         curses.wrapper(win.run)
     except curses.error as e:
         raise CursesError() from e
 
 
     try:
         curses.wrapper(win.run)
     except curses.error as e:
         raise CursesError() from e
 
 
-def reparse():
-    """Parse arguments and input file again"""
-    args = parse_args()
-    os.system(f"$EDITOR {args.inp[0]}"),
-    return parse.parse_html(parse.md2html(args.inp[0]))
-
-
 def get_orig():
     """Return original header and stack"""
     return (headers, stack)
 
 
 def main(args=sys.argv):
 def get_orig():
     """Return original header and stack"""
     return (headers, stack)
 
 
 def main(args=sys.argv):
-    sys.tracebacklimit = 0
     args = parse_args()
     global headers, stack
     (headers, stack) = parse.parse_html(parse.md2html(args.inp[0]))
     args = parse_args()
     global headers, stack
     (headers, stack) = parse.parse_html(parse.md2html(args.inp[0]))
-    show(args, stack, headers)
+    conf = config.read_file(args.config)
+
+    if not conf["debug"]:
+        sys.tracebacklimit = 0
+
+    show(args, stack, headers, conf)
 
 
 if __name__ == "__main__":
 
 
 if __name__ == "__main__":