From: Armaan Bhojwani Date: Fri, 12 Feb 2021 01:21:36 +0000 (-0500) Subject: Add size checker to terminal X-Git-Tag: v0.6.0~14 X-Git-Url: https://git.armaanb.net/?p=lightcards.git;a=commitdiff_plain;h=babbdb2c2646f6e885061dcad77d23aeeab3e058 Add size checker to terminal Program now gracefully warns if the terminal is too small for proper display --- 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,