From: Armaan Bhojwani Date: Sun, 31 Jan 2021 01:25:46 +0000 (-0500) Subject: Add ability to star cards X-Git-Tag: v0.1.0~11 X-Git-Url: https://git.armaanb.net/?p=lightcards.git;a=commitdiff_plain;h=da5f204dfb0e33a99bba1fa00842b253bf9947e0 Add ability to star cards --- diff --git a/lightcards/deck.py b/lightcards/deck.py index d8ee725..2136ecc 100644 --- a/lightcards/deck.py +++ b/lightcards/deck.py @@ -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 diff --git a/lightcards/display.py b/lightcards/display.py index 42a01f2..86740d6 100755 --- a/lightcards/display.py +++ b/lightcards/display.py @@ -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 diff --git a/lightcards/parse.py b/lightcards/parse.py index 457da13..6f3c25f 100755 --- a/lightcards/parse.py +++ b/lightcards/parse.py @@ -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))