]> git.armaanb.net Git - lightcards.git/commitdiff
Add size checker to terminal
authorArmaan Bhojwani <me@armaanb.net>
Fri, 12 Feb 2021 01:21:36 +0000 (20:21 -0500)
committerArmaan Bhojwani <me@armaanb.net>
Fri, 12 Feb 2021 01:21:36 +0000 (20:21 -0500)
Program now gracefully warns if the terminal is too small for proper
display

lightcards/display.py

index 06e8148833254b30e58a810b86f04bd5547e8bed..abf3a7c4c1c107b710ff717abdeb89dd07d647ee 100644 (file)
@@ -6,6 +6,7 @@ import curses.panel
 from random import shuffle
 import sys
 import textwrap
+import time
 
 from . import runner, progress
 
@@ -219,6 +220,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()
@@ -347,8 +367,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()
@@ -390,6 +410,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,