X-Git-Url: https://git.armaanb.net/?a=blobdiff_plain;f=lightcards%2Fdisplay.py;h=d6d8de22b02d7722d52b785cf973888a91b24923;hb=c529b7f5860936920af3d22a77e4b0a02f612c9d;hp=fd11158b789eccac7c0902aca69811e915b68af4;hpb=fdb8037c1207d21fd5c233cc771237e20f494ec7;p=lightcards.git 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)