]> git.armaanb.net Git - lightcards.git/blobdiff - lightcards/display.py
Add ability to star cards
[lightcards.git] / lightcards / display.py
index 10f2f4d86c6a6e2f3b193139d4c06b5bc5874eeb..86740d6421b43f0ef6f2b5a9426216687305fc2b 100755 (executable)
@@ -1,34 +1,10 @@
 # Display card output and retreive input
 # Armaan Bhojwani 2021
 
+import curses
 import os
 
-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
+from .deck import Status
 
 
 def disp_card(stdscr, stack, headers, obj):
@@ -39,8 +15,27 @@ def disp_card(stdscr, stack, headers, obj):
         stdscr.addstr("=")
     stdscr.addstr("\n" + str(stack[obj.getIdx()][obj.getSide()]))
 
+    (mlines, mcols) = stdscr.getmaxyx()
+    mlines -= 1
+    mcols -= 5
+
+    try:
+        stdscr.insch(mlines, mcols, str(obj.getIdx() + 1))
+        stdscr.insch(mlines, mcols+1, '-')
+        if obj.getSide() == 0:
+            stdscr.insch(mlines, mcols+2, '1')
+        else:
+            stdscr.insch(mlines, mcols+2, '2')
+        stdscr.insch(mlines, mcols+3, '/')
+        stdscr.insch(mlines, mcols+4, str(len(stack)))
+        stdscr.insstr(mlines, 1, stack[obj.getIdx()].getStar())
+    except Exception:
+        pass
+
+
 def get_key(stdscr, stack, headers):
     idx = Status()
+    curses.curs_set(0)
     disp_card(stdscr, stack, headers, idx)
 
     while True:
@@ -48,16 +43,19 @@ def get_key(stdscr, stack, headers):
         try:
             if key == "q" or key == os.linesep:
                 exit(0)
-            if key == "j":
+            elif key in ["l", "KEY_LEFT"]:
                 idx.forward(stack)
                 idx.setSide(0)
                 disp_card(stdscr, stack, headers, idx)
-            if key == "k":
+            elif key in ["h", "KEY_RIGHT"]:
                 idx.back()
                 idx.setSide(0)
                 disp_card(stdscr, stack, headers,  idx)
-            if key == "l" or key == "h":
+            elif key in ["j", "k", "KEY_UP", "KEY_DOWN"]:
                 idx.flip()
                 disp_card(stdscr, stack, headers, idx)
+            elif key in ["i", "/"]:
+                stack[idx.getIdx()].toggleStar()
+                disp_card(stdscr, stack, headers, idx)
         except Exception:
             pass