From e17c7827378d59c726c3c532ffcb1eeaa72a2d2a Mon Sep 17 00:00:00 2001 From: Nate Smith Date: Sat, 9 Dec 2023 16:11:02 -0800 Subject: [PATCH] WIP adding curses --- main.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index bb71d19..ace509e 100755 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +import curses import datetime from os import path from getpass import getuser @@ -9,6 +10,7 @@ import sys from typing import Optional, Tuple, TypeVar BOTANY_DIR = ".botany" +MIN_SCREEN_WIDTH = 80 dt = datetime.datetime @@ -88,13 +90,29 @@ def main() -> Optional[Exception]: if e is not None: return e - # TODO restore plant from disk + # TODO rug sweep curses stuff + parentwin = curses.initscr() + parentwin.keypad(True) + curses.noecho() + curses.raw() + if curses.has_colors(): + curses.start_color() + try: + curses.curs_set(0) + except curses.error: + # Not all terminals support this functionality. + # When the error is ignored the screen will be slightly uglier but functional + # so we ignore this error for terminal compatibility. + pass + if curses.COLS < MIN_SCREEN_WIDTH: + return Exception("the terminal window is too narrow") + return None if __name__ == "__main__": ret = 0 e = main() if e is not None: - print(e) + print(e, file=sys.stderr) ret = 1 sys.exit(ret)