]> git.armaanb.net Git - lightcards.git/blobdiff - lightcards/display.py
Modify mvwin() positioning
[lightcards.git] / lightcards / display.py
index abf3a7c4c1c107b710ff717abdeb89dd07d647ee..d0c24208b5fb11b19b73be81f15e9ede6fb776e6 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",
@@ -64,8 +63,7 @@ class Help:
     def disp(self):
         """Display help screen"""
         (mlines, mcols) = self.outer.win.getmaxyx()
-        self.win.mvwin(int(mlines / 2) - 10, int(mcols / 2) - 26)
-        self.outer.update_panels()
+        self.win.mvwin(int(mlines / 2) - 10, int(mcols / 2) - 25)
         self.panel.show()
 
         while True:
@@ -110,7 +108,6 @@ class Menu:
             self.win.addstr(t[0] + 3, 1, t[1])
 
         self.win.box()
-        self.outer.update_panels()
 
     def menu_print(self, string, err=False):
         """Print messages on the menu screen"""
@@ -123,7 +120,6 @@ class Menu:
             self.win.addch(15, i + 1, " ")
 
         self.win.addstr(15, 1, string, color)
-        self.outer.update_panels()
         self.menu_grab()
 
     def menu_grab(self):
@@ -132,7 +128,6 @@ class Menu:
             key = self.win.getkey()
             if key in ["r", "m"]:
                 self.panel.hide()
-                self.outer.update_panels()
                 self.outer.get_key()
             elif key == "q":
                 self.outer.leave()
@@ -178,9 +173,6 @@ class Menu:
                     self.menu_print("Stars only!")
                 else:
                     self.menu_print("ERR: None are starred!", err=True)
-            elif key in ["h", "KEY_LEFT"]:
-                self.outer.obj.index = len(self.outer.stack) - 1
-                self.outer.get_key()
             elif key == "r":
                 self.outer.obj.index = 0
                 self.outer.get_key()
@@ -191,9 +183,8 @@ class Menu:
         and to continue
         """
         (mlines, mcols) = self.outer.win.getmaxyx()
-        self.win.mvwin(int(mlines / 2) - 9, int(mcols / 2) - 22)
+        self.win.mvwin(int(mlines / 2) - 9, int(mcols / 2) - 21)
         self.panel.show()
-        self.outer.update_panels()
 
         self.menu_grab()
 
@@ -207,14 +198,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)
 
@@ -224,26 +214,20 @@ 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:
             self.disp_card()
 
-    def update_panels(self):
-        """Update panel and window contents"""
-        curses.panel.update_panels()
-        self.win.refresh()
-
     def leave(self):
         """Pickle stack before quitting"""
         if self.obj.index + 1 == len(self.stack):
@@ -314,9 +298,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))))
@@ -331,11 +316,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="…"),
@@ -343,10 +329,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(
@@ -354,7 +340,7 @@ class Display:
                 width=self.wrap_width(),
             ),
         )
-        self.update_panels()
+
         self.disp_bar()
         self.disp_sidebar()
 
@@ -410,9 +396,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,