]> git.armaanb.net Git - lightcards.git/blobdiff - lightcards/display.py
Do all computation before clearing screen
[lightcards.git] / lightcards / display.py
index e74e554c7d39938c1941c3b43ac7779382889866..1c17a759d2f5182bdb7b2b5a4586d301029ac4cd 100644 (file)
@@ -310,13 +310,8 @@ class Display:
         """Get total number of starred cards"""
         return [card for card in self.stack if card.starred]
 
-    def disp_bar(self):
-        """
-        Display the statusbar at the bottom of the screen with progress, star
-        status, and card side.
-        """
+    def prep_bar(self):
         (mlines, mcols) = self.win.getmaxyx()
-        self.win.hline(mlines - 3, 0, 0, mcols)
 
         # Calculate percent done
         if len(self.stack) <= 1:
@@ -328,42 +323,52 @@ class Display:
 
         # Print yellow if starred
         if self.current_card().starred:
-            star_color = curses.color_pair(3)
+            self.star_color = curses.color_pair(3)
         else:
-            star_color = curses.color_pair(1)
+            self.star_color = curses.color_pair(1)
 
         # Compose bar text
-        bar_start = "["
-        bar_middle = self.current_card().printStar()
-        bar_end = f"] [{len(self.nstarred())}/{str(len(self.stack))} starred] "
+        self.bar_start = "["
+        self.bar_middle = self.current_card().printStar()
+        self.bar_end = (
+            f"] [{len(self.nstarred())}/{str(len(self.stack))} starred] "
+        )
         if self.view != 3:
-            bar_end += (
+            self.bar_end += (
                 f" [{self.get_side()} ("
                 f"{str(int(self.current_card().side) + 1)})]"
             )
-        bar_end += f" [View {str(self.view)}]"
+        self.bar_end += f" [View {str(self.view)}]"
 
+        self.progress = (
+            f"[{percent}% ("
+            f"{str(self.obj.index + 1).zfill(len(str(len(self.stack))))}"
+            f"/{str(len(self.stack))})] "
+        )
+
+    def disp_bar(self):
+        """
+        Display the statusbar at the bottom of the screen with progress, star
+        status, and card side.
+        """
         # Put it all togethor
+        (mlines, mcols) = self.win.getmaxyx()
         height = mlines - 2
-        self.win.addstr(height, 0, bar_start, curses.color_pair(1))
-        self.win.addstr(height, len(bar_start), bar_middle, star_color)
+        self.win.addstr(height, 0, self.bar_start, curses.color_pair(1))
+        self.win.addstr(
+            height, len(self.bar_start), self.bar_middle, self.star_color
+        )
         self.win.addstr(
             height,
-            len(bar_start + bar_middle),
-            textwrap.shorten(bar_end, width=mcols - 20, placeholder="…"),
+            len(self.bar_start + self.bar_middle),
+            textwrap.shorten(self.bar_end, width=mcols - 20, placeholder="…"),
             curses.color_pair(1),
         )
 
-        progress = (
-            f"[{percent}% ("
-            f"{str(self.obj.index + 1).zfill(len(str(len(self.stack))))}"
-            f"/{str(len(self.stack))})] "
-        )
-
         self.win.addstr(
             height + 1,
             0,
-            progress,
+            self.progress,
             curses.color_pair(1),
         )
 
@@ -371,17 +376,19 @@ class Display:
             int(
                 self.obj.index
                 / (len(self.stack) - 1)
-                * (mcols - len(progress))
+                * (mcols - len(self.progress))
                 - 1
             )
         ):
             self.win.addch(
                 height + 1,
-                i + len(progress),
+                i + len(self.progress),
                 self.config["progress_char"],
                 curses.color_pair(1),
             )
 
+        self.win.hline(mlines - 3, 0, 0, mcols)
+
     def wrap_width(self):
         """Calculate the width at which the body text should wrap"""
         (_, mcols) = self.win.getmaxyx()
@@ -399,7 +406,7 @@ class Display:
     def disp_card(self):
         (_, mcols) = self.win.getmaxyx()
         self.main_panel.bottom()
-        self.win.clear()
+        self.prep_bar()
         num_done = str(self.obj.index + 1).zfill(len(str(len(self.stack))))
 
         if self.view in [1, 2, 4]:
@@ -427,6 +434,7 @@ class Display:
                     + '"'
                 )
 
+            self.win.clear()
             self.win.addstr(
                 0,
                 0,
@@ -448,10 +456,7 @@ class Display:
             """
             Display the contents of the card with both the front and back sides.
             """
-            (_, mcols) = self.win.getmaxyx()
-            self.main_panel.bottom()
             self.win.clear()
-
             self.win.addstr(
                 0,
                 0,