Added a new flag in the options/protocol_flags to ignore or follow NAWS updates.

This commit is contained in:
mike 2024-04-09 12:20:52 -07:00
parent 8011750931
commit c94b7f47c1
4 changed files with 17 additions and 1 deletions

View file

@ -635,6 +635,11 @@ class CmdOption(COMMAND_DEFAULT_CLASS):
self.msg(f"Option |w{new_name}|n was kept as '|w{old_val}|n'.")
else:
flags[new_name] = new_val
# If we're manually assign a display size, turn off auto-resizing
if new_name in ['SCREENWIDTH', 'SCREENHEIGHT']:
flags['AUTORESIZE'] = False
self.msg(
f"Option |w{new_name}|n was changed from '|w{old_val}|n' to"
f" '|w{new_val}|n'."
@ -657,6 +662,7 @@ class CmdOption(COMMAND_DEFAULT_CLASS):
"RAW": validate_bool,
"SCREENHEIGHT": validate_size,
"SCREENWIDTH": validate_size,
"AUTORESIZE": validate_bool,
"SCREENREADER": validate_bool,
"TERM": utils.to_str,
"UTF-8": validate_bool,

View file

@ -175,6 +175,7 @@ _CLIENT_OPTIONS = (
"MCCP",
"SCREENHEIGHT",
"SCREENWIDTH",
"AUTORESIZE",
"INPUTDEBUG",
"RAW",
"NOCOLOR",
@ -201,6 +202,7 @@ def client_options(session, *args, **kwargs):
mccp (bool): MCCP compression on/off
screenheight (int): Screen height in lines
screenwidth (int): Screen width in characters
autoresize (bool): Use NAWS updates to dynamically adjust format
inputdebug (bool): Debug input functions
nocolor (bool): Strip color
raw (bool): Turn off parsing
@ -256,6 +258,8 @@ def client_options(session, *args, **kwargs):
flags["SCREENHEIGHT"] = validate_size(value)
elif key == "screenwidth":
flags["SCREENWIDTH"] = validate_size(value)
elif key == "autoresize":
flags["AUTORESIZE"] = validate_size(value)
elif key == "inputdebug":
flags["INPUTDEBUG"] = validate_bool(value)
elif key == "nocolor":

View file

@ -57,6 +57,7 @@ class Naws:
option (Option): Not used.
"""
self.protocol.protocol_flags["AUTORESIZE"] = False
self.protocol.handshake_done()
def do_naws(self, option):
@ -67,6 +68,7 @@ class Naws:
option (Option): Not used.
"""
self.protocol.protocol_flags["AUTORESIZE"] = True
self.protocol.handshake_done()
def negotiate_sizes(self, options):

View file

@ -94,8 +94,12 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, _BASE_SESSION_CLASS):
"""
try:
# Do we have a NAWS update?
if NAWS in data and len([data[i:i+1] for i in range(0, len(data))]) == 9:
if (NAWS in data and
len([data[i:i+1] for i in range(0, len(data))]) == 9 and
# Is auto resizing on?
self.protocol_flags.get('AUTORESIZE')):
self.sessionhandler.sync(self.sessionhandler.get(self.sessid))
super().dataReceived(data)
except ValueError as err:
from evennia.utils import logger