]> git.armaanb.net Git - lightcards.git/blobdiff - lightcards/display.py
Reduce number of screen refreshes
[lightcards.git] / lightcards / display.py
index aa5beed58c70c7b4a14a4b86ed9c8648ffde9eb1..6f572ad470ad2b90d8dd36b2b6084db749fd5b1a 100644 (file)
@@ -26,7 +26,6 @@ class Help:
         (self.win, self.panel) = panel_create(mlines, mcols)
         self.panel.top()
         self.panel.hide()
-        self.win.clear()
 
         text = [
             "Welcome to runner. Here are some keybindings",
@@ -204,14 +203,13 @@ class Display:
     def run(self, stdscr):
         """Set important options that require stdscr before starting"""
         self.win = stdscr
-        (mlines, mcols) = self.win.getmaxyx()
         curses.curs_set(0)  # Hide cursor
         curses.use_default_colors()  # Allow transparency
         curses.init_pair(1, curses.COLOR_CYAN, -1)
         curses.init_pair(2, curses.COLOR_RED, -1)
         curses.init_pair(3, curses.COLOR_YELLOW, -1)
 
-        (self.main_win, self.main_panel) = panel_create(mlines, mcols)
+        self.main_panel = curses.panel.new_panel(self.win)
         self.menu_obj = Menu(self)
         self.help_obj = Help(self)
 
@@ -221,16 +219,15 @@ class Display:
         (mlines, mcols) = self.win.getmaxyx()
 
         while mlines < 24 or mcols < 60:
-            self.main_win.clear()
-            self.main_win.addstr(
+            self.win.clear()
+            self.win.addstr(
                 0,
                 0,
                 textwrap.fill(
                     "Terminal too small! Min size 60x24", width=mcols
                 ),
             )
-            self.main_win.redrawwin()
-            self.main_win.refresh()
+            self.win.refresh()
             (mlines, mcols) = self.win.getmaxyx()
             time.sleep(0.1)
         else:
@@ -239,7 +236,7 @@ class Display:
     def update_panels(self):
         """Update panel and window contents"""
         curses.panel.update_panels()
-        self.win.refresh()
+        curses.doupdate()
 
     def leave(self):
         """Pickle stack before quitting"""
@@ -311,9 +308,10 @@ class Display:
         Shows a header, a horizontal line, and the contents of the current
         side.
         """
-        (mlines, mcols) = self.win.getmaxyx()
+        (_, mcols) = self.win.getmaxyx()
         self.main_panel.bottom()
-        self.main_win.clear()
+        self.win.clear()
+
         # If on the back of the card, show the content of the front side in
         # the header
         num_done = str(self.obj.index + 1).zfill(len(str(len(self.stack))))
@@ -328,11 +326,12 @@ class Display:
                 + str(self.current_card().front)
                 + '"'
             )
+
         header_width = mcols
         if mcols > 80:
             header_width = 80
 
-        self.main_win.addstr(
+        self.win.addstr(
             0,
             0,
             textwrap.shorten(top, width=header_width, placeholder="…"),
@@ -340,10 +339,10 @@ class Display:
         )
 
         # Add horizontal line
-        self.main_win.hline(1, 0, curses.ACS_HLINE, mcols)
+        self.win.hline(1, 0, curses.ACS_HLINE, mcols)
 
         # Show current side
-        self.main_win.addstr(
+        self.win.addstr(
             2,
             0,
             textwrap.fill(
@@ -407,9 +406,6 @@ class Display:
         (mlines, mcols) = self.win.getmaxyx()
         left = mcols - 19
 
-        for i in range(20):
-            self.win.addch(0, mcols - 20 + i, " ")
-
         self.win.addstr(
             0,
             mcols - 16,