]> git.armaanb.net Git - lightcards.git/commitdiff
Add ability to star cards
authorArmaan Bhojwani <me@armaanb.net>
Sun, 31 Jan 2021 01:25:46 +0000 (20:25 -0500)
committerArmaan Bhojwani <me@armaanb.net>
Sun, 31 Jan 2021 01:33:11 +0000 (20:33 -0500)
lightcards/deck.py
lightcards/display.py
lightcards/parse.py

index d8ee725856b19e8b5bcdfe626edf690ee4a0b578..2136ecc589bdc0f843a2db68399b64385e1934b9 100644 (file)
@@ -1,6 +1,22 @@
 # Classes pertaining to the card deck
 # Armaan Bhojwani 2021
 
+class Card(list):
+    starred = False
+
+    def toggleStar(self):
+        if self.starred:
+            self.starred = False
+        else:
+            self.starred = True
+
+    def getStar(self):
+        if self.starred:
+            return "★ Starred ★"
+        else:
+            return "Not starred"
+
+
 class Status():
     index = 0
     side = 0
index 42a01f220d2e57228f097925cda50bea07bb2a14..86740d6421b43f0ef6f2b5a9426216687305fc2b 100755 (executable)
@@ -28,6 +28,7 @@ def disp_card(stdscr, stack, headers, obj):
             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
 
@@ -53,5 +54,8 @@ def get_key(stdscr, stack, headers):
             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
index 457da136f4b30b503f3350dfdcf3f9dd7d58150c..6f3c25f6baf0d40b75fbdcfcf6ecbe4e850fae98 100755 (executable)
@@ -6,6 +6,8 @@ import sys
 from bs4 import BeautifulSoup
 import markdown
 
+from .deck import Card
+
 
 def md2html(file):
     with open(file, "r", encoding="utf-8") as input_file:
@@ -26,7 +28,7 @@ def parse_html(html):
     outp = []
 
     for x in soup.find_all("tr"):
-        outp.append([clean_text(y) for y in x.find_all("td")])
+        outp.append(Card([clean_text(y) for y in x.find_all("td")]))
 
     return ([clean_text(x) for x in soup.find_all("th")],
             clean_list(outp))