]> git.armaanb.net Git - lightcards.git/blobdiff - lightcards/display.py
Update status bar
[lightcards.git] / lightcards / display.py
index 988270ba28f2fb92ef60605fd43d26dd1c5ebfc9..349d77abbb9417c9b363ea6943c59cf2166ae78e 100755 (executable)
@@ -1,59 +1,62 @@
 # Display card output and retreive input
 # Armaan Bhojwani 2021
 
+import curses
 import os
 
-class Status():
-    index = 0
-    side = 0
+from .deck import Status
 
-    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):
+def disp_card(stdscr, stack, headers, obj):
     stdscr.clear()
-    stdscr.addstr(str(stack[obj.getIdx()][obj.getSide()]))
-
-def get_key(stdscr, stack):
+    side_title = headers[obj.getSide()]
+    stdscr.addstr(side_title + "\n")
+    for i in range(len(side_title)):
+        stdscr.addstr("=")
+    stdscr.addstr("\n" + str(stack[obj.getIdx()][obj.getSide()]))
+
+    (mlines, mcols) = stdscr.getmaxyx()
+    try:
+        stdscr.insstr(mlines - 1, 1,
+                      "[" +
+                      stack[obj.getIdx()].getStar() +
+                      "] [" +
+                      str(round(obj.getIdx() / (len(stack) - 1) * 100)).zfill(3) +
+                      "% (" +
+                      str(obj.getIdx() + 1) +
+                      "/" +
+                      str(len(stack)) +
+                      ")]" +
+                      " [" +
+                      headers[obj.getSide()] +
+                      "]")
+    except Exception:
+        pass
+
+
+def get_key(stdscr, stack, headers):
     idx = Status()
-    disp_card(stdscr, stack, idx)
+    curses.curs_set(0)
+    disp_card(stdscr, stack, headers, idx)
 
     while True:
         key = stdscr.getkey()
         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, idx)
-            if key == "k":
+                disp_card(stdscr, stack, headers, idx)
+            elif key in ["h", "KEY_RIGHT"]:
                 idx.back()
                 idx.setSide(0)
-                disp_card(stdscr, stack, idx)
-            if key == "l" or key == "h":
+                disp_card(stdscr, stack, headers,  idx)
+            elif key in ["j", "k", "KEY_UP", "KEY_DOWN"]:
                 idx.flip()
-                disp_card(stdscr, stack, idx)
+                disp_card(stdscr, stack, headers, idx)
+            elif key in ["i", "/"]:
+                stack[idx.getIdx()].toggleStar()
+                disp_card(stdscr, stack, headers, idx)
         except Exception:
             pass