]> git.armaanb.net Git - lightcards.git/commitdiff
Allow for config files to be incomplete
authorArmaan Bhojwani <me@armaanb.net>
Sat, 13 Feb 2021 17:26:06 +0000 (12:26 -0500)
committerArmaan Bhojwani <me@armaanb.net>
Sat, 13 Feb 2021 17:26:06 +0000 (12:26 -0500)
config.py
lightcards/config.py
lightcards/display.py
lightcards/runner.py

index 64296bbbb3e7d5c27c3f356f944555fad85e7589..46d6bf0761805faed8ae477ed06bc581c3d12a0b 100644 (file)
--- a/config.py
+++ b/config.py
@@ -1,6 +1,32 @@
-###############
-# KEYBINDINGS #
-###############
+###############################################################################
+# LIGHTCARDS DEFAULT CONFIG FILE                                              #
+###############################################################################
+
+###############################################################################
+# STARTUP OPTIONS
+
+alphabetize = False
+shuffle = False
+reverse = False
+cache = True
+
+default_view = 1
+
+###############################################################################
+# APPEARANCE
+
+disp_progress = True
+progress_char = "ยป"
+disp_sidebar = True
+disp_bar = True
+
+bar_sections = ["starred_status", "starred_count", "side", "view"]
+
+highlight_color = "green"
+starred_color = "yellow"
+
+###############################################################################
+# KEYBINDINGS
 
 card_prev = ["h", "KEY_LEFT"]
 card_next = ["l", "KEY_RIGHT"]
 
 card_prev = ["h", "KEY_LEFT"]
 card_next = ["l", "KEY_RIGHT"]
@@ -16,3 +42,11 @@ menu_disp = "m"
 view_one = "1"
 view_two = "2"
 view_three = "3"
 view_one = "1"
 view_two = "2"
 view_three = "3"
+
+###############################################################################
+# OTHER
+
+confirm_quit = True
+debug = False
+
+###############################################################################
index 56f72617a72d0d529b45a95d68afd249a5a7a534..3c99dc263304795cfcee5b61791ba0a8fc7182ea 100644 (file)
@@ -13,8 +13,10 @@ class ConfigException(BaseException):
         sys.exit(4)
 
 
         sys.exit(4)
 
 
-def find_file(file):
+def read_file(file):
+    config = {}
     file = str(file)
     file = str(file)
+    files = []
     local_xdg = f"{os.path.expanduser('~')}/{os.environ.get('XDG_CACHE_HOME')}/lightcards/config.py"
     local = f"{os.path.expanduser('~')}/.config/lightcards/config.py"
     world = "/etc/lightcards/config.py"
     local_xdg = f"{os.path.expanduser('~')}/{os.environ.get('XDG_CACHE_HOME')}/lightcards/config.py"
     local = f"{os.path.expanduser('~')}/.config/lightcards/config.py"
     world = "/etc/lightcards/config.py"
@@ -23,22 +25,20 @@ def find_file(file):
         f"{os.path.expanduser('~')}/.local/share/doc/lightcards/config.py"
     )
 
         f"{os.path.expanduser('~')}/.local/share/doc/lightcards/config.py"
     )
 
+    if os.path.exists(world_default):
+        files.append(world_default)
+    if os.path.exists(local_default):
+        files.append(local_default)
+    if os.path.exists(world):
+        files.append(world)
+    if os.path.exists(local_xdg):
+        files.append(local_xdg)
+    if os.path.exists(local):
+        files.append(local)
     if os.path.exists(file):
     if os.path.exists(file):
-        return file
-    elif os.path.exists(local_xdg):
-        return local_xdg
-    elif os.path.exists(local):
-        return local
-    elif os.path.exists(world):
-        return world
-    elif os.path.exists(world_default):
-        return world_default
-    elif os.path.exists(local_default):
-        return local_default
-
+        files.append(file)
 
 
-def read_file(file):
-    config = {}
-    exec(Path(str(find_file(file))).read_text(), {}, config)
+    for f in files:
+        exec(Path(str(f)).read_text(), {}, config)
 
     return config
 
     return config
index 8023ff37338fe273f00345cafe0591696fb189b8..cb52c8d93565952252ccda0e762002d6eaedbf32 100644 (file)
@@ -9,7 +9,7 @@ import sys
 import textwrap
 import time
 
 import textwrap
 import time
 
-from . import runner, progress, parse, config
+from . import runner, progress, parse
 
 
 def panel_create(x, y):
 
 
 def panel_create(x, y):
@@ -231,13 +231,13 @@ class Menu:
 
 
 class Display:
 
 
 class Display:
-    def __init__(self, stack, headers, obj, view, args):
+    def __init__(self, stack, headers, obj, view, args, conf):
         self.stack = stack
         self.headers = headers
         self.obj = obj
         self.view = view
         self.input_file = args.inp[0]
         self.stack = stack
         self.headers = headers
         self.obj = obj
         self.view = view
         self.input_file = args.inp[0]
-        self.config = config.read_file(args.config)
+        self.config = conf
 
     def run(self, stdscr):
         """Set important options that require stdscr before starting"""
 
     def run(self, stdscr):
         """Set important options that require stdscr before starting"""
index 6cb87d40d3f36c4db647e955cd3a70455b208044..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
 
@@ -61,7 +60,7 @@ def parse_args():
     return parser.parse_args()
 
 
     return parser.parse_args()
 
 
-def show(args, stack, headers, input_file):
+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
@@ -85,7 +84,7 @@ def show(args, stack, headers, input_file):
         stack.reverse()
 
     # Send to display
         stack.reverse()
 
     # Send to display
-    win = Display(stack, headers, idx, args.view, input_file)
+    win = Display(stack, headers, idx, args.view, args, conf)
     try:
         curses.wrapper(win.run)
     except curses.error as e:
     try:
         curses.wrapper(win.run)
     except curses.error as e:
@@ -98,11 +97,15 @@ def get_orig():
 
 
 def main(args=sys.argv):
 
 
 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, args)
+    conf = config.read_file(args.config)
+
+    if not conf["debug"]:
+        sys.tracebacklimit = 0
+
+    show(args, stack, headers, conf)
 
 
 if __name__ == "__main__":
 
 
 if __name__ == "__main__":