From 58314c0a25a5ecd1ca044359821b58d837bb5281 Mon Sep 17 00:00:00 2001 From: Armaan Bhojwani Date: Sun, 31 Jan 2021 14:14:38 -0500 Subject: [PATCH] Add keybinding to open file in editor --- lightcards/display.py | 8 +++++++- lightcards/lightcards.py | 7 +++++++ man/lightcards.1 | 6 ++++++ man/lightcards.1.md | 6 ++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lightcards/display.py b/lightcards/display.py index 8e7bba4..fd11158 100755 --- a/lightcards/display.py +++ b/lightcards/display.py @@ -6,6 +6,8 @@ from random import shuffle import sys import textwrap +from . import lightcards + def disp_bar(stdscr, stack, headers, obj): """ @@ -156,7 +158,8 @@ def disp_help(stdscr, stack, headers, idx): "i, / star card\n" + "0, ^, home go to the start of the deck\n" + "$, end go to the end of the deck\n" + - "H, ? open this screen\n\n" + + "H, ? open this screen\n" + + "e open the input file in $EDITOR\n\n" + "More information can be found in the man page, or by\n" + "running `lightcards --help`.\n\n" + "Press [q], [H], or [?] to go back.") @@ -210,3 +213,6 @@ def get_key(stdscr, stack, headers, idx): disp_card(stdscr, stack, headers, idx) elif key in ["H", "?"]: disp_help(stdscr, stack, headers, idx) + elif key == "e": + (headers, stack) = lightcards.reparse() + get_key(stdscr, stack, headers, idx) diff --git a/lightcards/lightcards.py b/lightcards/lightcards.py index 66d1231..41b0db7 100755 --- a/lightcards/lightcards.py +++ b/lightcards/lightcards.py @@ -4,6 +4,7 @@ import argparse from curses import wrapper +import os from random import shuffle import sys @@ -49,6 +50,12 @@ def show(args, stack, headers): wrapper(display.init_disp, stack, headers, idx) +def reparse(): + args = parse_args() + os.system(f"$EDITOR {args.inp[0]}"), + return parse.parse_html(parse.md2html(args.inp[0])) + + def main(args=sys.argv): args = parse_args() (headers, stack) = parse.parse_html(parse.md2html(args.inp[0])) diff --git a/man/lightcards.1 b/man/lightcards.1 index a31e8bc..c8264e4 100644 --- a/man/lightcards.1 +++ b/man/lightcards.1 @@ -53,6 +53,12 @@ Go to start of deck .TP \f[B]$\f[R], \f[B]end\f[R] Go to end of deck +.TP +\f[B]H\f[R], \f[B]?\f[R] +Open help screen +.TP +\f[B]e\f[R] +Open input file in $EDITOR .SH EXIT VALUES .TP \f[B]0\f[R] diff --git a/man/lightcards.1.md b/man/lightcards.1.md index 2871c12..6c3a385 100644 --- a/man/lightcards.1.md +++ b/man/lightcards.1.md @@ -50,6 +50,12 @@ lightcards [[options]] [input file] **$**, **end** : Go to end of deck +**H**, **?** +: Open help screen + +**e** +: Open input file in $EDITOR + # EXIT VALUES **0** : Success -- 2.39.2