Skip to content

Commit

Permalink
fix special SESSION_PS_SIZE values (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
najohnsn authored Apr 28, 2023
1 parent 64b26bd commit 615cfcd
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 33 deletions.
11 changes: 8 additions & 3 deletions tnz/ati.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
"""
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tnz/tnz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down Expand Up @@ -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)
Expand Down
64 changes: 36 additions & 28 deletions tnz/zti.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
"""
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 615cfcd

Please sign in to comment.