From: Frank Brehm Date: Thu, 1 Feb 2024 16:45:41 +0000 (+0100) Subject: Fixing classmethod cursor_position() of class BaseDPXApplication. X-Git-Tag: 1.0.0~1^2~16 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=73155bd306d215b0a28953fc2336b65066acf98a;p=pixelpark%2Fpp-admin-tools.git Fixing classmethod cursor_position() of class BaseDPXApplication. --- diff --git a/lib/pp_admintools/app/__init__.py b/lib/pp_admintools/app/__init__.py index d2b4332..81a5689 100644 --- a/lib/pp_admintools/app/__init__.py +++ b/lib/pp_admintools/app/__init__.py @@ -16,6 +16,7 @@ import sys import termios from collections import namedtuple +from io import UnsupportedOperation # Third party modules from fb_tools.cfg_app import FbConfigApplication @@ -36,7 +37,7 @@ LOG = logging.getLogger(__name__) _ = XLATOR.gettext ngettext = XLATOR.ngettext -__version__ = '0.9.0' +__version__ = '0.9.1' # ============================================================================= @@ -158,7 +159,11 @@ class BaseDPXApplication(FbConfigApplication): It returns these position as a CursorPosition object. A position of (-1, -1) means, the position could not be evaluated. """ - old_stdin_mode = termios.tcgetattr(sys.stdin) + try: + old_stdin_mode = termios.tcgetattr(sys.stdin) + except UnsupportedOperation: + return CursorPosition(-1, -1) + stdin_mode = termios.tcgetattr(sys.stdin) stdin_mode[3] = stdin_mode[3] & ~(termios.ECHO | termios.ICANON) termios.tcsetattr(sys.stdin, termios.TCSAFLUSH, stdin_mode) diff --git a/test/test_10_base_app.py b/test/test_10_base_app.py index 67c2ae4..b84c926 100755 --- a/test/test_10_base_app.py +++ b/test/test_10_base_app.py @@ -64,12 +64,15 @@ class TestBaseApp(PpAdminToolsTestcase): print('0123456789', end='', flush=True) pos = BaseDPXApplication.cursor_position() - print() - if pos.x != -1 and pos.y != -1: - LOG.debug("Got {}.".format(pos)) - self.assertEqual(pos.x, 11) + if pos.x == -1 and pos.y == -1: + LOG.info("Terminal has no cursor.") else: - LOG.info("Could not detect position of screen cursor.") + print() + if pos.x != -1 and pos.y != -1: + LOG.debug("Got {}.".format(pos)) + self.assertEqual(pos.x, 11) + else: + LOG.info("Could not detect position of screen cursor.") # =============================================================================