From babbdb2c2646f6e885061dcad77d23aeeab3e058 Mon Sep 17 00:00:00 2001 From: Armaan Bhojwani Date: Thu, 11 Feb 2021 20:21:36 -0500 Subject: [PATCH] Add size checker to terminal Program now gracefully warns if the terminal is too small for proper display --- lightcards/display.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lightcards/display.py b/lightcards/display.py index 06e8148..abf3a7c 100644 --- a/lightcards/display.py +++ b/lightcards/display.py @@ -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, -- 2.39.2