]> git.armaanb.net Git - lightcards.git/blobdiff - lightcards/display.py
Remove ability to go left to quit the menu
[lightcards.git] / lightcards / display.py
index f51259396cd04cd2587cbdf92f993267531159aa..aa5beed58c70c7b4a14a4b86ed9c8648ffde9eb1 100644 (file)
@@ -6,6 +6,7 @@ import curses.panel
 from random import shuffle
 import sys
 import textwrap
+import time
 
 from . import runner, progress
 
@@ -19,10 +20,10 @@ def panel_create(x, y):
 
 
 class Help:
-    def __init__(self, outer):
+    def __init__(self, outer, mlines=20, mcols=52):
         """Initialize help screen"""
         self.outer = outer
-        (self.win, self.panel) = panel_create(20, 52)
+        (self.win, self.panel) = panel_create(mlines, mcols)
         self.panel.top()
         self.panel.hide()
         self.win.clear()
@@ -48,9 +49,12 @@ class Help:
         ]
 
         self.win.addstr(
-            1, 1, "LIGHTCARDS HELP", curses.color_pair(1) + curses.A_BOLD
+            1,
+            int(mcols / 2) - 8,
+            "LIGHTCARDS HELP",
+            curses.color_pair(1) + curses.A_BOLD,
         )
-        self.win.hline(2, 1, curses.ACS_HLINE, 15)
+        self.win.hline(2, 1, curses.ACS_HLINE, mcols)
 
         for t in enumerate(text):
             self.win.addstr(t[0] + 3, 1, t[1])
@@ -74,17 +78,20 @@ class Help:
 
 
 class Menu:
-    def __init__(self, outer):
+    def __init__(self, outer, mlines=17, mcols=44):
         """Initialize the menu with content"""
         self.outer = outer
-        (self.win, self.panel) = panel_create(17, 44)
+        (self.win, self.panel) = panel_create(mlines, mcols)
         self.panel.top()
         self.panel.hide()
 
         self.win.addstr(
-            1, 1, "LIGHTCARDS MENU", curses.color_pair(1) + curses.A_BOLD
+            1,
+            int(mcols / 2) - 8,
+            "LIGHTCARDS MENU",
+            curses.color_pair(1) + curses.A_BOLD,
         )
-        self.win.hline(2, 1, curses.ACS_HLINE, 15)
+        self.win.hline(2, 1, curses.ACS_HLINE, mcols)
         text = [
             "[y]: reset stack to original state",
             "[a]: alphabetize stack",
@@ -133,7 +140,7 @@ class Menu:
                 self.outer.stack = runner.get_orig()[1]
                 self.menu_print("Stack reset!")
             elif key == "a":
-                self.outer.stack.sort()
+                self.outer.stack.sort(key=lambda x: x.front)
                 self.menu_print("Stack alphabetized!")
             elif key == "u":
                 [x.unStar() for x in self.outer.stack]
@@ -171,9 +178,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()
@@ -213,6 +217,25 @@ class Display:
 
         self.get_key()
 
+    def check_size(self):
+        (mlines, mcols) = self.win.getmaxyx()
+
+        while mlines < 24 or mcols < 60:
+            self.main_win.clear()
+            self.main_win.addstr(
+                0,
+                0,
+                textwrap.fill(
+                    "Terminal too small! Min size 60x24", width=mcols
+                ),
+            )
+            self.main_win.redrawwin()
+            self.main_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()
@@ -235,7 +258,8 @@ class Display:
         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()
+        self.win.hline(mlines - 2, 0, 0, mcols)
 
         # Calculate percent done
         if len(self.stack) <= 1:
@@ -269,7 +293,7 @@ class Display:
         self.win.addstr(
             mlines - 1,
             len(bar_start + bar_middle),
-            bar_end,
+            textwrap.shorten(bar_end, width=mcols - 20, placeholder="…"),
             curses.color_pair(1),
         )
 
@@ -316,10 +340,7 @@ class Display:
         )
 
         # Add horizontal line
-        lin_width = header_width
-        if len(top) < header_width:
-            lin_width = len(top)
-        self.main_win.hline(1, 0, curses.ACS_HLINE, lin_width)
+        self.main_win.hline(1, 0, curses.ACS_HLINE, mcols)
 
         # Show current side
         self.main_win.addstr(
@@ -333,7 +354,6 @@ class Display:
         self.update_panels()
         self.disp_bar()
         self.disp_sidebar()
-        self.win.hline(mlines - 2, 0, 0, mcols)
 
     def current_card(self):
         """Get current card object"""
@@ -344,8 +364,8 @@ class Display:
         Display a card and wait for the input.
         Used as a general way of getting back into the card flow from a menu
         """
-        self.disp_card()
         while True:
+            self.check_size()
             key = self.win.getkey()
             if key == "q":
                 self.leave()
@@ -387,6 +407,9 @@ 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,
@@ -394,7 +417,6 @@ class Display:
             curses.color_pair(3) + curses.A_BOLD,
         )
         self.win.vline(0, mcols - 20, 0, mlines - 2)
-        self.win.hline(1, left, 0, mlines)
 
         nstarred = self.nstarred()
         if mlines - 5 < len(self.nstarred()):