From c529b7f5860936920af3d22a77e4b0a02f612c9d Mon Sep 17 00:00:00 2001 From: Armaan Bhojwani Date: Sun, 31 Jan 2021 16:17:57 -0500 Subject: [PATCH] Redo menu at end of stack Instead of choosing one option, you now can do as many actions as you would like before restarting --- lightcards/display.py | 80 ++++++++++++++++++++++------------------ lightcards/lightcards.py | 4 ++ 2 files changed, 49 insertions(+), 35 deletions(-) diff --git a/lightcards/display.py b/lightcards/display.py index fd11158..d6d8de2 100755 --- a/lightcards/display.py +++ b/lightcards/display.py @@ -49,23 +49,50 @@ def disp_menu(stdscr, stack, headers, idx): Display a menu once the end of the deck has been reached, offering multiple options on how to continue. """ - stdscr.addstr("Good job, you've completed a round!\n\n", - curses.color_pair(1)) - stdscr.addstr("Choose one of the following options:\n" + + def menu_print(stdscr, stack, headers, idx, string, err=False): + stdscr.clear() + if err: + stdscr.addstr(string + "\n\n", curses.color_pair(2)) + else: + stdscr.addstr(string + "\n\n", curses.color_pair(1)) + disp_menu(stdscr, stack, headers, idx) + + stdscr.addstr("Choose one of the following options:\n\n" + + "[y]: reset stack to original state\n" + + "[z]: shuffle stack\n" + + "[f]: flip all cards in stack\n" + + "[t]: reverse stack order\n" + + "[u]: unstar all\n" + + "[s]: update stack to include starred only\n\n" + "[r]: restart\n" + - "[s]: restart with starred only\n" + - "[u]: restart and unstar all\n" + - "[z]: restart and shuffle cards\n" + - "[f]: restart and show the other side first\n" + - "[t]: restart in reverse order\n" + "[q]: quit") + idx.setIdx(0) while True: key = stdscr.getkey() if key == "q": sys.exit(0) - elif key == "r": - idx.setIdx(0) - get_key(stdscr, stack, headers, idx) + elif key == "y": + stack = lightcards.get_orig()[1] + menu_print(stdscr, stack, headers, idx, + "Stack reset!") + elif key == "u": + [x.unStar() for x in stack] + menu_print(stdscr, stack, headers, idx, + "All unstarred!") + elif key == "t": + stack.reverse() + menu_print(stdscr, stack, headers, idx, + "Stack reversed!") + elif key == "z": + shuffle(stack) + menu_print(stdscr, stack, headers, idx, + "Stack shuffled!") + elif key == "f": + for x in stack: + x[0], x[1] = x[1], x[0] + headers[0], headers[1] = headers[1], headers[0] + menu_print(stdscr, stack, headers, idx, + "Cards flipped!") elif key == "s": # Check if there are any starred cards before proceeding, and if # not, don't allow to proceed and show an error message @@ -73,34 +100,17 @@ def disp_menu(stdscr, stack, headers, idx): for x in stack: if x.getStar(): cont = True + break if cont: - idx.setIdx(0) stack = [x for x in stack if x.getStar()] - get_key(stdscr, stack, headers, idx) + menu_print(stdscr, stack, headers, idx, + "Stars only!") else: - stdscr.clear() - stdscr.addstr("ERR: Stack empty. Choose another option\n\n", - curses.color_pair(2)) - disp_menu(stdscr, stack, headers, idx) - elif key == "u": - idx.setIdx(0) - for x in stack: - x.unStar() - get_key(stdscr, stack, headers, idx) - elif key == "z": - idx.setIdx(0) - shuffle(stack) - get_key(stdscr, stack, headers, idx) - elif key == "f": - idx.setIdx(0) - for x in stack: - x[0], x[1] = x[1], x[0] - headers[0], headers[1] = headers[1], headers[0] - get_key(stdscr, stack, headers, idx) - elif key == "t": - idx.setIdx(0) - stack.reverse() + menu_print(stdscr, stack, headers, idx, + "ERR: None are starred!", + err=True) + elif key == "r": get_key(stdscr, stack, headers, idx) diff --git a/lightcards/lightcards.py b/lightcards/lightcards.py index 41b0db7..779f347 100755 --- a/lightcards/lightcards.py +++ b/lightcards/lightcards.py @@ -55,10 +55,14 @@ def reparse(): os.system(f"$EDITOR {args.inp[0]}"), return parse.parse_html(parse.md2html(args.inp[0])) +def get_orig(): + return((headers2, stack2)) def main(args=sys.argv): args = parse_args() (headers, stack) = parse.parse_html(parse.md2html(args.inp[0])) + global headers2, stack2 + (headers2, stack2) = (headers, stack) show(args, stack, headers) -- 2.39.2