## Input file
`contrib/example.md` is an example input file. Lightcards takes the first table from a valid Markdown or HTML file. Each row is a card, and the two columns are the front and back.
+## Configuration
+An example config file is provided at `/usr/share/doc/lightcards/config.py`, or `~/.local/share/doc/lightcards/config.py` if installed without root privileges. Copy it to `~/.config/lightcards/config.py` or `/etc/lightcards/config.py` and modify the given values.
+
## License
Copyright Armaan Bhojwani 2021, MIT license
--- /dev/null
+###############
+# KEYBINDINGS #
+###############
+
+card_prev = ["h", "KEY_LEFT"]
+card_next = ["l", "KEY_RIGHT"]
+card_flip = ["j", "k", "KEY_UP", "KEY_DOWN"]
+card_star = ["i", "/"]
+card_first = ["0", "^", "KEY_HOME"]
+card_last = ["$", "KEY_END"]
+
+help_disp = ["H", "?"]
+
+menu_disp = "m"
+
+view_one = "1"
+view_two = "2"
+view_three = "3"
--- /dev/null
+# Parse lightcards config file
+# Armaan Bhojwani 2021
+
+import sys
+from pathlib import Path
+import os
+
+
+class ConfigException(BaseException):
+ def __init__(self, message):
+ self.message = message
+ print(f"lightcards: {self.message}")
+ sys.exit(4)
+
+
+def find_file(file):
+ file = str(file)
+ 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"
+ world_default = "/usr/share/doc/lightcards/config.py"
+ local_default = (
+ f"{os.path.expanduser('~')}/.local/share/doc/lightcards/config.py"
+ )
+
+ 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
+
+
+def read_file(file):
+ config = {}
+ exec(Path(str(find_file(file))).read_text(), {}, config)
+
+ return config
import textwrap
import time
-from . import runner, progress, parse
+from . import runner, progress, parse, config
def panel_create(x, y):
self.panel.hide()
text = [
- "Welcome to runner. Here are some keybindings",
- "to get you started:",
+ "Welcome to Lightcards. Here are the default",
+ "keybindings to get you started:",
"",
"h, left previous card",
"l, right next card",
class Display:
- def __init__(self, stack, headers, obj, view, input_file):
+ def __init__(self, stack, headers, obj, view, args):
self.stack = stack
self.headers = headers
self.obj = obj
self.view = view
- self.input_file = input_file
+ self.input_file = args.inp[0]
+ self.config = config.read_file(args.config)
def run(self, stdscr):
"""Set important options that require stdscr before starting"""
key = self.win.getkey()
if key == "q":
self.leave()
- elif key in ["h", "KEY_LEFT"]:
+ elif key in self.config["card_prev"]:
self.obj.back()
self.current_card().side = 0
self.disp_card()
- elif key in ["l", "KEY_RIGHT"]:
+ elif key in self.config["card_next"]:
if self.obj.index + 1 == len(self.stack):
self.menu_obj.disp()
else:
self.obj.forward(self.stack)
self.current_card().side = 0
self.disp_card()
- elif key in ["j", "k", "KEY_UP", "KEY_DOWN"] and self.view != 3:
+ elif key in self.config["card_flip"] and self.view != 3:
self.current_card().flip()
self.disp_card()
- elif key in ["i", "/"]:
+ elif key in self.config["card_star"]:
self.current_card().toggleStar()
self.disp_card()
- elif key in ["0", "^", "KEY_HOME"]:
+ elif key in self.config["card_first"]:
self.obj.index = 0
self.current_card().side = 0
self.disp_card()
- elif key in ["$", "KEY_END"]:
+ elif key in self.config["card_last"]:
self.obj.index = len(self.stack) - 1
self.current_card().side = 0
self.disp_card()
- elif key in ["H", "?"]:
+ elif key in self.config["help_disp"]:
self.help_obj.disp()
- elif key == "m":
+ elif key in self.config["menu_disp"]:
self.menu_obj.disp()
- elif key in ["1", "2", "3", "4"]:
- self.view = int(key)
+ elif key in self.config["view_one"]:
+ self.view = 1
+ elif key in self.config["view_two"]:
+ self.view = 2
+ elif key in self.config["view_three"]:
+ self.view = 3
def disp_sidebar(self):
"""Display a sidebar with the starred terms"""
import os
import pickle
+# TODO: Check for $XDG_CACHE_HOME
dired = f"{os.path.expanduser('~')}/.cache/lightcards/"
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",
sys.tracebacklimit = 0
args = parse_args()
global headers, stack
- input_file = args.inp[0]
- (headers, stack) = parse.parse_html(parse.md2html(input_file))
- show(args, stack, headers, input_file)
+ (headers, stack) = parse.parse_html(parse.md2html(args.inp[0]))
+ show(args, stack, headers, args)
if __name__ == "__main__":
.TP
\f[B]-V\f[R] [1-3], \f[B]--view\f[R] [1-3]
Specify startup view
+.TP
+\f[B]-c\f[R], \f[B]--config\f[R]
+Specify a custom config file
.SH KEYS
.TP
\f[B]l\f[R], \f[B]right\f[R]
.TP
\f[B]3\f[R]
Curses error
+.TP
+\f[B]4\f[R]
+Config error
.SH BUGS
.PP
https://lists.sr.ht/\[ti]armaan/public-inbox
**-V** \[1-3\], **\--view** \[1-3\]
: Specify startup view
+**-c**, **\--config**
+: Specify a custom config file
+
# KEYS
**l**, **right**
: Next card
**3**
: Curses error
+**4**
+: Config error
+
# BUGS
https://lists.sr.ht/~armaan/public-inbox
license="MIT",
packages=["lightcards"],
install_requires=["beautifulsoup4", "markdown"],
- data_files=[("man/man1", ["man/lightcards.1"])],
+ data_files=[
+ ("man/man1", ["man/lightcards.1"]),
+ (
+ "share/doc/lightcards/",
+ [
+ "./config.py",
+ "./README.md",
+ "man/lightcards.1.md",
+ "./LICENSE",
+ ],
+ ),
+ ],
entry_points={
"console_scripts": ["lightcards=lightcards:main"],
},