]> git.armaanb.net Git - lightcards.git/blobdiff - lightcards/display.py
Update status bar
[lightcards.git] / lightcards / display.py
index c2b7eb0ade79a7c18a5093c619f298ec665ebf2d..349d77abbb9417c9b363ea6943c59cf2166ae78e 100755 (executable)
@@ -4,32 +4,7 @@
 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):
@@ -40,23 +15,25 @@ 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)))
-    except:
+        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()
     curses.curs_set(0)
@@ -67,16 +44,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