]> git.armaanb.net Git - lightcards.git/commitdiff
Add sidebar of starred cards
authorArmaan Bhojwani <me@armaanb.net>
Mon, 1 Feb 2021 16:35:02 +0000 (11:35 -0500)
committerArmaan Bhojwani <me@armaanb.net>
Mon, 1 Feb 2021 16:35:02 +0000 (11:35 -0500)
lightcards/display.py

index b4076e57a5e8ac20a6d262c43c2d467d93f75421..09f1e52cdda7cab58d70c6c7f076c3e84ec41d3d 100644 (file)
@@ -35,7 +35,7 @@ class Display():
         Display the statusbar at the bottom of the screen with progress, star
         status, and card side.
         """
         Display the statusbar at the bottom of the screen with progress, star
         status, and card side.
         """
-        (mlines, _) = self.win.getmaxyx()
+        (mlines, mcols) = self.win.getmaxyx()
 
         # Calculate percent done
         if len(self.stack) <= 1:
 
         # Calculate percent done
         if len(self.stack) <= 1:
@@ -60,6 +60,7 @@ class Display():
             str(self.obj.getSide() + 1) + ")]"
 
         # Put it all togethor
             str(self.obj.getSide() + 1) + ")]"
 
         # Put it all togethor
+        self.win.hline(mlines - 2, 0, 0, mcols)
         self.win.addstr(mlines - 1, 0, bar_start, curses.color_pair(1))
         self.win.addstr(bar_middle, star_color)
         self.win.insstr(bar_end, curses.color_pair(1))
         self.win.addstr(mlines - 1, 0, bar_start, curses.color_pair(1))
         self.win.addstr(bar_middle, star_color)
         self.win.insstr(bar_end, curses.color_pair(1))
@@ -154,8 +155,8 @@ class Display():
 
     def wrap_width(self):
         (_, mcols) = self.win.getmaxyx()
 
     def wrap_width(self):
         (_, mcols) = self.win.getmaxyx()
-        wrap_width = mcols
-        if mcols > 80:
+        wrap_width = mcols - 20
+        if wrap_width > 80:
             wrap_width = 80
         return wrap_width
 
             wrap_width = 80
         return wrap_width
 
@@ -197,6 +198,7 @@ class Display():
                 self.stack[self.obj.getIdx()][self.obj.getSide()],
                 width=self.wrap_width()))
         self.disp_bar()
                 self.stack[self.obj.getIdx()][self.obj.getSide()],
                 width=self.wrap_width()))
         self.disp_bar()
+        self.disp_sidebar()
 
     def disp_help(self):
         """Display help screen"""
 
     def disp_help(self):
         """Display help screen"""
@@ -267,3 +269,31 @@ class Display():
             elif key == "e":
                 (self.headers, self.stack) = lightcards.reparse()
                 self.get_key()
             elif key == "e":
                 (self.headers, self.stack) = lightcards.reparse()
                 self.get_key()
+
+    def disp_sidebar(self):
+        (mlines, mcols) = self.win.getmaxyx()
+        self.win.addstr(0, mcols - 16, "STARRED CARDS",
+                        curses.color_pair(3) + curses.A_BOLD)
+        self.win.vline(0, mcols - 20, 0, mlines)
+        self.win.hline(1, mcols - 19, 0, mlines)
+
+        total = [card for card in self.stack if card.getStar()]
+        ntotal = len(total)
+
+        i = 0
+        for card in self.stack:
+            if i > mlines - 6:
+                self.win.addstr(2 + i, mcols - 19, f"... ({ntotal - i} more)")
+                break
+            elif card.getStar():
+                term = card[0]
+                if len(card[0]) > 18:
+                    term = card[0][:18] + "…"
+                self.win.addstr(2 + i, mcols - 19, term)
+
+                i += 1
+
+        if i == 0:
+            self.win.addstr(2, mcols - 19, "None starred")
+
+        self.win.addstr(mlines - 1, mcols - 19, f"{ntotal}/{str(len(self.stack))}")