mirror of
https://github.com/evennia/evennia.git
synced 2026-03-30 12:37:16 +02:00
Converted encoding setting to use protocol_flags rather than being stored on-session. Also renamed the 256 COLORS TTYPE setting to XTERM256 which is more accurate (and doesn't have a space)
This commit is contained in:
parent
1ddfbca7ea
commit
11ecdef7c8
8 changed files with 39 additions and 29 deletions
|
|
@ -401,12 +401,19 @@ class CmdOption(MuxPlayerCommand):
|
|||
|
||||
if not self.args:
|
||||
# list the option settings
|
||||
string = "{wEncoding{n:\n"
|
||||
pencoding = self.session.encoding or "None"
|
||||
sencodings = settings.ENCODINGS
|
||||
string += " Custom: %s\n Server: %s" % (pencoding, ", ".join(sencodings))
|
||||
string += "\n{wScreen Reader mode:{n %s" % self.session.protocol_flags.get("SCREENREADER", False)
|
||||
self.msg(string)
|
||||
flags = self.session.protocol_flags
|
||||
keys = sorted(flags)
|
||||
options = "\n".join(" {w%s{n: %s" % (key, flags[key]) for key in keys)
|
||||
self.msg("{wClient settings:\n%s" % options)
|
||||
#string = "{wEncoding{n:\n"
|
||||
#pencoding = flags.get("ENCODING", "None")
|
||||
#sencodings = settings.ENCODINGS
|
||||
#string += " Custom: %s\n Server: %s" % (pencoding, ", ".join(sencodings))
|
||||
#string += "\n{wScreen Reader mode:{n %s" % flags.get("SCREENREADER", False)
|
||||
## display all
|
||||
#keys =
|
||||
#string += "\n{wClient settings (read-only):\n%s" % options
|
||||
#self.msg(string)
|
||||
return
|
||||
|
||||
if not self.rhs:
|
||||
|
|
@ -417,14 +424,14 @@ class CmdOption(MuxPlayerCommand):
|
|||
|
||||
if self.lhs == "encoding":
|
||||
# change encoding
|
||||
old_encoding = self.session.encoding
|
||||
old_encoding = self.session.protocol_flags["ENCODING"]
|
||||
new_encoding = self.rhs.strip() or "utf-8"
|
||||
try:
|
||||
utils.to_str(utils.to_unicode("test-string"), encoding=new_encoding)
|
||||
except LookupError:
|
||||
string = "|rThe encoding '|w%s|r' is invalid. Keeping the previous encoding '|w%s|r'.|n" % (new_encoding, old_encoding)
|
||||
else:
|
||||
self.session.encoding = new_encoding
|
||||
self.session.protocol_flags["ENCODING"] = new_encoding
|
||||
string = "Encoding was changed from '|w%s|n' to '|w%s|n'." % (old_encoding, new_encoding)
|
||||
self.msg(string)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -459,17 +459,19 @@ class CmdUnconnectedEncoding(MuxCommand):
|
|||
if self.session is None:
|
||||
return
|
||||
|
||||
sync = False
|
||||
if 'clear' in self.switches:
|
||||
# remove customization
|
||||
old_encoding = self.session.encoding
|
||||
old_encoding = self.session.protocol_flags.get("ENCODING", None)
|
||||
if old_encoding:
|
||||
string = "Your custom text encoding ('%s') was cleared." % old_encoding
|
||||
else:
|
||||
string = "No custom encoding was set."
|
||||
self.session.encoding = "utf-8"
|
||||
self.session.protocol_flags["ENCODING"] = "utf-8"
|
||||
sync = True
|
||||
elif not self.args:
|
||||
# just list the encodings supported
|
||||
pencoding = self.session.encoding
|
||||
pencoding = self.session.protocol_flags.get("ENCODING", None)
|
||||
string = ""
|
||||
if pencoding:
|
||||
string += "Default encoding: {g%s{n (change with {w@encoding <encoding>{n)" % pencoding
|
||||
|
|
@ -480,15 +482,18 @@ class CmdUnconnectedEncoding(MuxCommand):
|
|||
string = "No encodings found."
|
||||
else:
|
||||
# change encoding
|
||||
old_encoding = self.session.encoding
|
||||
old_encoding = self.session.protocol_flags.get("ENCODING", None)
|
||||
encoding = self.args
|
||||
try:
|
||||
utils.to_str(utils.to_unicode("test-string"), encoding=encoding)
|
||||
except LookupError:
|
||||
string = "|rThe encoding '|w%s|r' is invalid. Keeping the previous encoding '|w%s|r'.|n" % (encoding, old_encoding)
|
||||
else:
|
||||
self.session.encoding = encoding
|
||||
self.session.protocol_flags["ENCODING"] = encoding
|
||||
string = "Your custom text encoding was changed from '|w%s|n' to '|w%s|n'." % (old_encoding, encoding)
|
||||
sync = True
|
||||
if sync:
|
||||
self.session.sessionhandler.session_portal_sync(self.session)
|
||||
self.caller.msg(string.strip())
|
||||
|
||||
class CmdUnconnectedScreenreader(MuxCommand):
|
||||
|
|
|
|||
|
|
@ -54,7 +54,6 @@ def text(session, *args, **kwargs):
|
|||
if text is None:
|
||||
return
|
||||
# this is treated as a command input
|
||||
#text = to_unicode(escape_control_sequences(text), encoding=self.encoding)
|
||||
# handle the 'idle' command
|
||||
if text.strip() == _IDLE_COMMAND:
|
||||
session.update_session_counters(idle=True)
|
||||
|
|
@ -122,7 +121,7 @@ def client_settings(session, *args, **kwargs):
|
|||
elif key == "ansi":
|
||||
flags["ANSI"] = bool(value)
|
||||
elif key == "xterm256":
|
||||
flags["256 COLORS"] = bool(value)
|
||||
flags["XTERM256"] = bool(value)
|
||||
elif key == "mxp":
|
||||
flags["MXP"] = bool(value)
|
||||
elif key == "utf-8":
|
||||
|
|
|
|||
|
|
@ -254,7 +254,7 @@ class SshProtocol(Manhole, session.Session):
|
|||
# handle arguments
|
||||
options = kwargs.get("options", {})
|
||||
flags = self.protocol_flags
|
||||
xterm256 = options.get("xterm256", flags.get('256 COLORS', False) if flags["TTYPE"] else True)
|
||||
xterm256 = options.get("xterm256", flags.get('XTERM256', False) if flags["TTYPE"] else True)
|
||||
useansi = options.get("ansi", flags.get('ANSI', False) if flags["TTYPE"] else True)
|
||||
raw = options.get("raw", False)
|
||||
nomarkup = options.get("nomarkup", not (xterm256 or useansi))
|
||||
|
|
|
|||
|
|
@ -304,7 +304,7 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session):
|
|||
# handle arguments
|
||||
options = kwargs.get("options", {})
|
||||
flags = self.protocol_flags
|
||||
xterm256 = options.get("xterm256", flags.get('256 COLORS', False) if flags["TTYPE"] else True)
|
||||
xterm256 = options.get("xterm256", flags.get('XTERM256', False) if flags["TTYPE"] else True)
|
||||
useansi = options.get("ansi", flags.get('ANSI', False) if flags["TTYPE"] else True)
|
||||
raw = options.get("raw", False)
|
||||
nomarkup = options.get("nomarkup", not (xterm256 or useansi))
|
||||
|
|
|
|||
|
|
@ -19,10 +19,10 @@ SEND = chr(1)
|
|||
|
||||
# terminal capabilities and their codes
|
||||
MTTS = [(128, 'PROXY'),
|
||||
(64, 'SCREEN READER'),
|
||||
(32, 'OSC COLOR PALETTE'),
|
||||
(16, 'MOUSE TRACKING'),
|
||||
(8, '256 COLORS'),
|
||||
(64, 'SCREENREADER'),
|
||||
(32, 'OSC_COLOR_PALETTE'),
|
||||
(16, 'MOUSE_TRACKING'),
|
||||
(8, 'XTERM256'),
|
||||
(4, 'UTF-8'),
|
||||
(2, 'VT100'),
|
||||
(1, 'ANSI')]
|
||||
|
|
@ -120,7 +120,7 @@ class Ttype(object):
|
|||
|
||||
# all clients supporting TTYPE at all seem to support ANSI
|
||||
self.protocol.protocol_flags['ANSI'] = True
|
||||
self.protocol.protocol_flags['256 COLORS'] = xterm256
|
||||
self.protocol.protocol_flags['XTERM256'] = xterm256
|
||||
self.protocol.protocol_flags['CLIENTNAME'] = clientname
|
||||
self.protocol.requestNegotiation(TTYPE, SEND)
|
||||
|
||||
|
|
@ -133,7 +133,7 @@ class Ttype(object):
|
|||
not term.endswith("-color"))
|
||||
if xterm256:
|
||||
self.protocol.protocol_flags['ANSI'] = True
|
||||
self.protocol.protocol_flags['256 COLORS'] = xterm256
|
||||
self.protocol.protocol_flags['XTERM256'] = xterm256
|
||||
self.protocol.protocol_flags['TERM'] = term
|
||||
# request next information
|
||||
self.protocol.requestNegotiation(TTYPE, SEND)
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class Session(object):
|
|||
|
||||
# names of attributes that should be affected by syncing.
|
||||
_attrs_to_sync = ('protocol_key', 'address', 'suid', 'sessid', 'uid',
|
||||
'uname', 'logged_in', 'puid', 'encoding',
|
||||
'uname', 'logged_in', 'puid',
|
||||
'conn_time', 'cmd_last', 'cmd_last_visible', 'cmd_total',
|
||||
'protocol_flags', 'server_data', "cmdset_storage_string")
|
||||
|
||||
|
|
@ -79,9 +79,8 @@ class Session(object):
|
|||
self.cmd_last_visible = self.conn_time
|
||||
self.cmd_last = self.conn_time
|
||||
self.cmd_total = 0
|
||||
self.encoding = "utf-8"
|
||||
|
||||
self.protocol_flags = {}
|
||||
self.protocol_flags = {"ENCODING": "utf-8", "SCREENREADER":False}
|
||||
self.server_data = {}
|
||||
|
||||
# map of input data to session methods
|
||||
|
|
|
|||
|
|
@ -168,11 +168,11 @@ class SessionHandler(dict):
|
|||
elif isinstance(data, basestring):
|
||||
# make sure strings are in a valid encoding
|
||||
try:
|
||||
data = data and to_str(to_unicode(data), encoding=session.encoding)
|
||||
data = data and to_str(to_unicode(data), encoding=session.protocol_flags["ENCODING"])
|
||||
except LookupError:
|
||||
# wrong encoding set on the session. Set it to a safe one
|
||||
session.encoding = "utf-8"
|
||||
data = to_str(to_unicode(data), encoding=session.encoding)
|
||||
session.protocol_flags["ENCODING"] = "utf-8"
|
||||
data = to_str(to_unicode(data), encoding=session.protocol_flags["ENCODING"])
|
||||
if _INLINEFUNC_ENABLED and not raw:
|
||||
data = parse_inlinefunc(data, strip=strip_inlinefunc, session=session) # deprecated!
|
||||
data = parse_nested_inlinefunc(data, strip=strip_inlinefunc, session=session)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue