]> git.armaanb.net Git - lightcards.git/blobdiff - lightcards/display.py
Add alphabetize option
[lightcards.git] / lightcards / display.py
index a2a97c3c2e1284e886daac3015c2200f6338de23..09f1e52cdda7cab58d70c6c7f076c3e84ec41d3d 100644 (file)
@@ -24,6 +24,9 @@ class Display():
         self.get_key()
 
     def leave(self):
+        if self.obj.getIdx() == len(self.stack):
+            self.obj.setIdx(0)
+
         progress.dump((self.obj, self.stack, self.headers), self.stack)
         sys.exit(0)
 
@@ -57,12 +60,12 @@ class Display():
             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))
 
     def menu_print(self, string, err=False):
-        (mlines, mcols) = self.win.getmaxyx()
         self.win.clear()
         if err:
             color = curses.color_pair(2)
@@ -124,12 +127,16 @@ class Display():
                 self.obj.setIdx(0)
                 self.get_key()
 
-    def disp_menu(self, keygrab=True):
+    def disp_menu(self, keygrab=True, quit=False):
         """
         Display a menu once the end of the deck has been reached, offering
         multiple options on how to continue.
         """
 
+        quit_text = "[q]: back"
+        if quit:
+            quit_text = "[q]: quit"
+
         self.win.addstr("LIGHTCARDS MENU", curses.color_pair(1) +
                         curses.A_BOLD)
         self.win.hline(1, 0, curses.ACS_HLINE, 15)
@@ -141,15 +148,15 @@ class Display():
                         "[d]: star all\n" +
                         "[s]: update stack to include starred only\n\n" +
                         "[r]: restart\n" +
-                        "[q]: back")
+                        quit_text)
 
         if keygrab:
             self.menu_grab()
 
     def wrap_width(self):
-        (mlines, mcols) = self.win.getmaxyx()
-        wrap_width = mcols
-        if mcols > 80:
+        (_, mcols) = self.win.getmaxyx()
+        wrap_width = mcols - 20
+        if wrap_width > 80:
             wrap_width = 80
         return wrap_width
 
@@ -160,9 +167,9 @@ class Display():
         side.
         """
         self.win.clear()
-        (mlines, mcols) = self.win.getmaxyx()
+        (_, mcols) = self.win.getmaxyx()
         if self.obj.getIdx() == len(self.stack):
-            self.disp_menu()
+            self.disp_menu(quit=True)
         else:
             # If on the back of the card, show the content of the front side in
             # the header
@@ -191,6 +198,7 @@ class Display():
                 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"""
@@ -261,3 +269,31 @@ class Display():
             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))}")