]> git.armaanb.net Git - lightcards.git/commitdiff
Redo menu at end of stack
authorArmaan Bhojwani <me@armaanb.net>
Sun, 31 Jan 2021 21:17:57 +0000 (16:17 -0500)
committerArmaan Bhojwani <me@armaanb.net>
Sun, 31 Jan 2021 21:17:57 +0000 (16:17 -0500)
Instead of choosing one option, you now can do as many actions as you
would like before restarting

lightcards/display.py
lightcards/lightcards.py

index fd11158b789eccac7c0902aca69811e915b68af4..d6d8de22b02d7722d52b785cf973888a91b24923 100755 (executable)
@@ -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)
 
 
index 41b0db738a5d5520fdd2ee6e0e3b15ec2fd8a025..779f347f2093bb8526a1ece20c7a797efdebcb87 100755 (executable)
@@ -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)