From 615cfcd232099d99847f854a6deb21493a601b2d Mon Sep 17 00:00:00 2001 From: Neil Johnson Date: Fri, 28 Apr 2023 14:05:35 -0400 Subject: [PATCH] fix special SESSION_PS_SIZE values (#68) --- tnz/ati.py | 11 +++++++--- tnz/tnz.py | 4 ++-- tnz/zti.py | 64 ++++++++++++++++++++++++++++++------------------------ 3 files changed, 46 insertions(+), 33 deletions(-) diff --git a/tnz/ati.py b/tnz/ati.py index be8efe0..2fa3b9a 100644 --- a/tnz/ati.py +++ b/tnz/ati.py @@ -79,7 +79,7 @@ COLORTERM (see _termlib.py) DATEFORM ESCDELAY (see zti.py) - SESSION_PS_SIZE (see tnz.py) + SESSION_PS_SIZE TERM_PROGRAM (see _termlib.py) TNZ_COLORS (see tnz.py) TNZ_LOGGING (see tnz.py) @@ -88,7 +88,7 @@ ZTI_TITLE (see zti.py) _BPX_TERMPATH (see _termlib.py) -Copyright 2021 IBM Inc. All Rights Reserved. +Copyright 2021, 2023 IBM Inc. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 """ @@ -2607,7 +2607,12 @@ def __set_session(self, name, verifycert, lognew): if ps_size: self.__logresult("%s = %r", "SESSION_PS_SIZE", ps_size) try: - asize = _util.session_ps_size(ps_size) + if ps_size in ("MAX", "MAX255", "FULL", "FULL255"): + from .zti import Zti + asize = Zti._rows_cols(ps_size) + else: + asize = _util.session_ps_size(ps_size) + tns.amaxrow, tns.amaxcol = asize except ValueError: pass diff --git a/tnz/tnz.py b/tnz/tnz.py index 7d91142..94c272c 100644 --- a/tnz/tnz.py +++ b/tnz/tnz.py @@ -11,7 +11,7 @@ TNZ_LOGGING ZTI_SECLEVEL -Copyright 2021 IBM Inc. All Rights Reserved. +Copyright 2021, 2023 IBM Inc. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 """ @@ -251,7 +251,7 @@ def __init__(self, name=None): self.capable_color = True ps_size = os.getenv("SESSION_PS_SIZE", None) - if ps_size: + if ps_size not in (None, "MAX", "MAX255", "FULL", "FULL255"): try: from . import _util asize = _util.session_ps_size(ps_size) diff --git a/tnz/zti.py b/tnz/zti.py index 9b86678..c87cc56 100644 --- a/tnz/zti.py +++ b/tnz/zti.py @@ -21,7 +21,7 @@ Environment variables used: COLORTERM (see _termlib.py) ESCDELAY - SESSION_PS_SIZE (see tnz.py) + SESSION_PS_SIZE TERM_PROGRAM (see _termlib.py) TNZ_COLORS (see tnz.py) TNZ_LOGGING (see tnz.py) @@ -30,7 +30,7 @@ ZTI_TITLE _BPX_TERMPATH (see _termlib.py) -Copyright 2021, 2022 IBM Inc. All Rights Reserved. +Copyright 2021, 2023 IBM Inc. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 """ @@ -63,10 +63,10 @@ from . import _sigx as sigx from ._termlib import Term as curses -from ._util import session_ps_14bit from . import ati from . import rexx from . import tnz +from . import _util from . import __version__ __author__ = "Neil Johnson" @@ -507,31 +507,9 @@ def do_goto(self, arg): oldsize = ati.ati["SESSION_PS_SIZE"] newsize = oldsize if not oldsize: - if os.getenv("SESSION_PS_SIZE") == "MAX": - (columns, lines) = os.get_terminal_size() - lines -= 4 - columns = min(columns - 17, 160) - lines, columns = session_ps_14bit(lines, columns) - newsize = f"{lines}x{columns}" - ati.set("SESSION_PS_SIZE", newsize) - elif os.getenv("SESSION_PS_SIZE") == "MAX255": - (columns, lines) = os.get_terminal_size() - lines -= 4 - columns = max(columns - 17, 255) - lines, columns = session_ps_14bit(lines, columns) - newsize = f"{lines}x{columns}" - ati.set("SESSION_PS_SIZE", newsize) - elif os.getenv("SESSION_PS_SIZE") == "FULL": - (columns, lines) = os.get_terminal_size() - columns = min(columns, 160) # 160 for ispf - lines, columns = session_ps_14bit(lines, columns) - newsize = f"{lines}x{columns}" - ati.set("SESSION_PS_SIZE", newsize) - elif os.getenv("SESSION_PS_SIZE") == "FULL255": - (columns, lines) = os.get_terminal_size() - columns = min(columns, 255) - lines, columns = session_ps_14bit(lines, columns) - newsize = f"{lines}x{columns}" + ps_size = os.getenv("SESSION_PS_SIZE", None) + if ps_size: + newsize = ps_size ati.set("SESSION_PS_SIZE", newsize) ati.ati.session = new_session @@ -3625,6 +3603,36 @@ def __repr__(self): actcmd, stat)) + # Private static methods + + @staticmethod + def _rows_cols(session_ps_size): + """rows, cols for SESSION_PS_SIZE value + """ + if session_ps_size == "MAX": + columns, lines = os.get_terminal_size() + lines -= 4 + columns = min(columns - 17, 160) + return _util.session_ps_14bit(lines, columns) + + if session_ps_size == "MAX255": + columns, lines = os.get_terminal_size() + lines -= 4 + columns = max(columns - 17, 255) + return _util.session_ps_14bit(lines, columns) + + if session_ps_size == "FULL": + columns, lines = os.get_terminal_size() + columns = min(columns, 160) # 160 for ispf + return _util.session_ps_14bit(lines, columns) + + if session_ps_size == "FULL255": + columns, lines = os.get_terminal_size() + columns = min(columns, 255) + return _util.session_ps_14bit(lines, columns) + + return _util.session_ps_size(session_ps_size) + # Internal data and other attributes _zti = None