Merge pull request #3498 from michaelfaith84/terminal_resizing

Automatic Terminal resizing
This commit is contained in:
Griatch 2024-04-27 18:58:15 +02:00 committed by GitHub
commit 97119bc21a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 22 additions and 3 deletions

View file

@ -636,6 +636,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'."
@ -658,6 +663,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

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

View file

@ -467,7 +467,7 @@ class PortalSessionHandler(SessionHandler):
kwargs (any): Each key is a command instruction to the
protocol on the form key = [[args],{kwargs}]. This will
call a method send_<key> on the protocol. If no such
method exixts, it sends the data to a method send_default.
method exits, it sends the data to a method send_default.
"""
# from evennia.server.profiling.timetrace import timetrace # DEBUG

View file

@ -31,6 +31,7 @@ from twisted.internet.task import LoopingCall
from evennia.server.portal import mssp, naws, suppress_ga, telnet_oob, ttype
from evennia.server.portal.mccp import MCCP, Mccp, mccp_compress
from evennia.server.portal.mxp import Mxp, mxp_parse
from evennia.server.portal.naws import NAWS
from evennia.utils import ansi
from evennia.utils.utils import class_from_module, to_bytes
@ -91,8 +92,14 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, _BASE_SESSION_CLASS):
of incoming data.
"""
# print(f"telnet dataReceived: {data}")
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 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

View file

@ -269,7 +269,7 @@ class ServerSession(_BASE_SESSION_CLASS):
Notes:
Since protocols can vary, no checking is done
as to the existene of the flag or not. The input
as to the existence of the flag or not. The input
data should have been validated before this call.
"""