]> git.armaanb.net Git - lightcards.git/commitdiff
Add status class
authorArmaan Bhojwani <me@armaanb.net>
Sat, 30 Jan 2021 22:12:57 +0000 (17:12 -0500)
committerArmaan Bhojwani <me@armaanb.net>
Sat, 30 Jan 2021 22:12:57 +0000 (17:12 -0500)
src/display.py

index 0ed78638772889399e0b7ab253965a6a13d263ff..988270ba28f2fb92ef60605fd43d26dd1c5ebfc9 100755 (executable)
@@ -3,31 +3,57 @@
 
 import os
 
-def disp_card(stdscr, stack, idx, side):
+class Status():
+    index = 0
+    side = 0
+
+    def forward(self, stack):
+        if not self.index == len(stack) - 1:
+            self.index += 1
+
+    def back(self):
+        if not self.index < 1:
+            self.index -= 1
+
+    def flip(self):
+        if self.side == 0:
+            self.side = 1
+        else:
+            self.side = 0
+
+    def setSide(self, inp):
+        self.side = inp
+
+    def getSide(self):
+        return self.side
+
+    def getIdx(self):
+        return self.index
+
+
+def disp_card(stdscr, stack, obj):
     stdscr.clear()
-    stdscr.addstr(str(stack[idx][side]))
+    stdscr.addstr(str(stack[obj.getIdx()][obj.getSide()]))
 
 def get_key(stdscr, stack):
-    idx = 0
-    side = 0
+    idx = Status()
+    disp_card(stdscr, stack, idx)
+
     while True:
         key = stdscr.getkey()
-
         try:
             if key == "q" or key == os.linesep:
                 exit(0)
-            if key == "l":
-                idx += 1
-                disp_card(stdscr, stack, idx, 0)
-            if key == "h":
-                idx -= 1
-                side = 0
-                disp_card(stdscr, stack, idx, 0)
+            if key == "j":
+                idx.forward(stack)
+                idx.setSide(0)
+                disp_card(stdscr, stack, idx)
             if key == "k":
-                if side == 0:
-                    side = 1
-                else:
-                    side = 0
-                disp_card(stdscr, stack, idx, side)
+                idx.back()
+                idx.setSide(0)
+                disp_card(stdscr, stack, idx)
+            if key == "l" or key == "h":
+                idx.flip()
+                disp_card(stdscr, stack, idx)
         except Exception:
             pass