Fix issue with option ansi/xterm256=False not correctly turning off colors. Change the NOMARKUP session option flag to NOCOLOR to better reflect its function.

This commit is contained in:
Griatch 2017-01-26 21:08:27 +01:00
parent b6a4997a97
commit 4699b38b31
8 changed files with 24 additions and 22 deletions

View file

@ -563,7 +563,7 @@ class CmdOption(COMMAND_DEFAULT_CLASS):
"ENCODING": validate_encoding, "ENCODING": validate_encoding,
"MCCP": validate_bool, "MCCP": validate_bool,
"MXP": validate_bool, "MXP": validate_bool,
"NOMARKUP": validate_bool, "NOCOLOR": validate_bool,
"NOPKEEPALIVE": validate_bool, "NOPKEEPALIVE": validate_bool,
"OOB": validate_bool, "OOB": validate_bool,
"RAW": validate_bool, "RAW": validate_bool,

View file

@ -181,7 +181,7 @@ def client_options(session, *args, **kwargs):
screenheight (int): Screen height in lines screenheight (int): Screen height in lines
screenwidth (int): Screen width in characters screenwidth (int): Screen width in characters
inputdebug (bool): Debug input functions inputdebug (bool): Debug input functions
nomarkup (bool): Strip markup nocolor (bool): Strip color
raw (bool): Turn off parsing raw (bool): Turn off parsing
""" """
@ -193,7 +193,7 @@ def client_options(session, *args, **kwargs):
"UTF-8", "SCREENREADER", "ENCODING", "UTF-8", "SCREENREADER", "ENCODING",
"MCCP", "SCREENHEIGHT", "MCCP", "SCREENHEIGHT",
"SCREENWIDTH", "INPUTDEBUG", "SCREENWIDTH", "INPUTDEBUG",
"RAW", "NOMARKUP")) "RAW", "NOCOLOR"))
session.msg(client_options=options) session.msg(client_options=options)
return return
@ -240,8 +240,8 @@ def client_options(session, *args, **kwargs):
flags["SCREENWIDTH"] = validate_size(value) flags["SCREENWIDTH"] = validate_size(value)
elif key == "inputdebug": elif key == "inputdebug":
flags["INPUTDEBUG"] = validate_bool(value) flags["INPUTDEBUG"] = validate_bool(value)
elif key == "nomarkup": elif key == "nocolor":
flags["NOMARKUP"] = validate_bool(value) flags["NOCOLOR"] = validate_bool(value)
elif key == "raw": elif key == "raw":
flags["RAW"] = validate_bool(value) flags["RAW"] = validate_bool(value)
elif key in ('Char 1', 'Char.Skills 1', 'Char.Items 1', elif key in ('Char 1', 'Char.Skills 1', 'Char.Items 1',

View file

@ -289,6 +289,7 @@ class PortalSessionHandler(SessionHandler):
# save protocols # save protocols
for sessid in to_save: for sessid in to_save:
self[sessid].load_sync_data(serversessions[sessid]) self[sessid].load_sync_data(serversessions[sessid])
print ("portalsessionhandler synced:", self[sessid].protocol_flags)
if clean: if clean:
# disconnect out-of-sync missing protocols # disconnect out-of-sync missing protocols
to_delete = [sessid for sessid in self if sessid not in to_save] to_delete = [sessid for sessid in self if sessid not in to_save]

View file

@ -246,8 +246,7 @@ class SshProtocol(Manhole, session.Session):
- mxp: Enforce MXP link support. - mxp: Enforce MXP link support.
- ansi: Enforce no ANSI colors. - ansi: Enforce no ANSI colors.
- xterm256: Enforce xterm256 colors, regardless of TTYPE setting. - xterm256: Enforce xterm256 colors, regardless of TTYPE setting.
- noxterm256: Enforce no xterm256 color support, regardless of TTYPE. - nocolor: Strip all colors.
- nomarkup: Strip all ANSI markup. This is the same as noxterm256,noansi
- raw: Pass string through without any ansi processing - raw: Pass string through without any ansi processing
(i.e. include Evennia ansi markers but do not (i.e. include Evennia ansi markers but do not
convert them into ansi tokens) convert them into ansi tokens)
@ -265,10 +264,10 @@ class SshProtocol(Manhole, session.Session):
# handle arguments # handle arguments
options = kwargs.get("options", {}) options = kwargs.get("options", {})
flags = self.protocol_flags flags = self.protocol_flags
xterm256 = options.get("xterm256", flags.get('XTERM256', False) if flags.get("TTYPE") else True) xterm256 = options.get("xterm256", flags.get('XTERM256', True))
useansi = options.get("ansi", flags.get('ANSI', False) if flags.get("TTYPE") else True) useansi = options.get("ansi", flags.get('ANSI', True))
raw = options.get("raw", flags.get("RAW", False)) raw = options.get("raw", flags.get("RAW", False))
nomarkup = options.get("nomarkup", flags.get("NOMARKUP", not (xterm256 or useansi))) nocolor = options.get("nocolor", flags.get("NOCOLOR") or not (xterm256 or useansi))
#echo = options.get("echo", None) #echo = options.get("echo", None)
screenreader = options.get("screenreader", flags.get("SCREENREADER", False)) screenreader = options.get("screenreader", flags.get("SCREENREADER", False))
@ -284,7 +283,7 @@ class SshProtocol(Manhole, session.Session):
else: else:
# we need to make sure to kill the color at the end in order # we need to make sure to kill the color at the end in order
# to match the webclient output. # to match the webclient output.
linetosend = ansi.parse_ansi(_RE_N.sub("", text) + "{n", strip_ansi=nomarkup, xterm256=xterm256, mxp=False) linetosend = ansi.parse_ansi(_RE_N.sub("", text) + "{n", strip_ansi=nocolor, xterm256=xterm256, mxp=False)
self.sendLine(linetosend) self.sendLine(linetosend)
def send_prompt(self, *args, **kwargs): def send_prompt(self, *args, **kwargs):

View file

@ -274,7 +274,7 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session):
- ansi: Enforce no ANSI colors. - ansi: Enforce no ANSI colors.
- xterm256: Enforce xterm256 colors, regardless of TTYPE. - xterm256: Enforce xterm256 colors, regardless of TTYPE.
- noxterm256: Enforce no xterm256 color support, regardless of TTYPE. - noxterm256: Enforce no xterm256 color support, regardless of TTYPE.
- nomarkup: Strip all ANSI markup. This is the same as noxterm256,noansi - nocolor: Strip all Color, regardless of ansi/xterm256 setting.
- raw: Pass string through without any ansi processing - raw: Pass string through without any ansi processing
(i.e. include Evennia ansi markers but do not (i.e. include Evennia ansi markers but do not
convert them into ansi tokens) convert them into ansi tokens)
@ -294,7 +294,7 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session):
xterm256 = options.get("xterm256", flags.get('XTERM256', 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) useansi = options.get("ansi", flags.get('ANSI', False) if flags["TTYPE"] else True)
raw = options.get("raw", flags.get("RAW", False)) raw = options.get("raw", flags.get("RAW", False))
nomarkup = options.get("nomarkup", flags.get("NOMARKUP", not (xterm256 or useansi))) nocolor = options.get("nocolor", flags.get("NOCOLOR") or not (xterm256 or useansi))
echo = options.get("echo", None) echo = options.get("echo", None)
mxp = options.get("mxp", flags.get("MXP", False)) mxp = options.get("mxp", flags.get("MXP", False))
screenreader = options.get("screenreader", flags.get("SCREENREADER", False)) screenreader = options.get("screenreader", flags.get("SCREENREADER", False))
@ -308,7 +308,7 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session):
# send a prompt instead. # send a prompt instead.
if not raw: if not raw:
# processing # processing
prompt = ansi.parse_ansi(_RE_N.sub("", text) + "{n", strip_ansi=nomarkup, xterm256=xterm256) prompt = ansi.parse_ansi(_RE_N.sub("", text) + "{n", strip_ansi=nocolor, xterm256=xterm256)
if mxp: if mxp:
prompt = mxp_parse(prompt) prompt = mxp_parse(prompt)
prompt = prompt.replace(IAC, IAC + IAC).replace('\n', '\r\n') prompt = prompt.replace(IAC, IAC + IAC).replace('\n', '\r\n')
@ -335,7 +335,7 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session):
else: else:
# we need to make sure to kill the color at the end in order # we need to make sure to kill the color at the end in order
# to match the webclient output. # to match the webclient output.
linetosend = ansi.parse_ansi(_RE_N.sub("", text) + "{n", strip_ansi=nomarkup, xterm256=xterm256, mxp=mxp) linetosend = ansi.parse_ansi(_RE_N.sub("", text) + "{n", strip_ansi=nocolor, xterm256=xterm256, mxp=mxp)
if mxp: if mxp:
linetosend = mxp_parse(linetosend) linetosend = mxp_parse(linetosend)
self.sendLine(linetosend) self.sendLine(linetosend)

View file

@ -164,7 +164,7 @@ class WebSocketClient(Protocol, Session):
Kwargs: Kwargs:
options (dict): Options-dict with the following keys understood: options (dict): Options-dict with the following keys understood:
- raw (bool): No parsing at all (leave ansi-to-html markers unparsed). - raw (bool): No parsing at all (leave ansi-to-html markers unparsed).
- nomarkup (bool): Clean out all ansi/html markers and tokens. - nocolor (bool): Clean out all color.
- screenreader (bool): Use Screenreader mode. - screenreader (bool): Use Screenreader mode.
- send_prompt (bool): Send a prompt with parsed html - send_prompt (bool): Send a prompt with parsed html
@ -182,7 +182,7 @@ class WebSocketClient(Protocol, Session):
options = kwargs.pop("options", {}) options = kwargs.pop("options", {})
raw = options.get("raw", flags.get("RAW", False)) raw = options.get("raw", flags.get("RAW", False))
nomarkup = options.get("nomarkup", flags.get("NOMARKUP", False)) nocolor = options.get("nocolor", flags.get("NOCOLOR", False))
screenreader = options.get("screenreader", flags.get("SCREENREADER", False)) screenreader = options.get("screenreader", flags.get("SCREENREADER", False))
prompt = options.get("send_prompt", False) prompt = options.get("send_prompt", False)
@ -194,7 +194,7 @@ class WebSocketClient(Protocol, Session):
if raw: if raw:
args[0] = text args[0] = text
else: else:
args[0] = parse_html(text, strip_ansi=nomarkup) args[0] = parse_html(text, strip_ansi=nocolor)
# send to client on required form [cmdname, args, kwargs] # send to client on required form [cmdname, args, kwargs]
self.sendLine(json.dumps([cmd, args, kwargs])) self.sendLine(json.dumps([cmd, args, kwargs]))

View file

@ -325,7 +325,7 @@ class WebClientSession(session.Session):
Kwargs: Kwargs:
options (dict): Options-dict with the following keys understood: options (dict): Options-dict with the following keys understood:
- raw (bool): No parsing at all (leave ansi-to-html markers unparsed). - raw (bool): No parsing at all (leave ansi-to-html markers unparsed).
- nomarkup (bool): Clean out all ansi/html markers and tokens. - nocolor (bool): Remove all color.
- screenreader (bool): Use Screenreader mode. - screenreader (bool): Use Screenreader mode.
- send_prompt (bool): Send a prompt with parsed html - send_prompt (bool): Send a prompt with parsed html
@ -343,7 +343,9 @@ class WebClientSession(session.Session):
options = kwargs.pop("options", {}) options = kwargs.pop("options", {})
raw = options.get("raw", flags.get("RAW", False)) raw = options.get("raw", flags.get("RAW", False))
nomarkup = options.get("nomarkup", flags.get("NOMARKUP", False)) xterm256 = options.get("xterm256", flags.get('XTERM256', True))
useansi = options.get("ansi", flags.get('ANSI', True))
nocolor = options.get("nocolor", flags.get("NOCOLOR") or not (xterm256 or useansi))
screenreader = options.get("screenreader", flags.get("SCREENREADER", False)) screenreader = options.get("screenreader", flags.get("SCREENREADER", False))
prompt = options.get("send_prompt", False) prompt = options.get("send_prompt", False)
@ -355,7 +357,7 @@ class WebClientSession(session.Session):
if raw: if raw:
args[0] = text args[0] = text
else: else:
args[0] = parse_html(text, strip_ansi=nomarkup) args[0] = parse_html(text, strip_ansi=nocolor)
# send to client on required form [cmdname, args, kwargs] # send to client on required form [cmdname, args, kwargs]
self.client.lineSend(self.csessid, [cmd, args, kwargs]) self.client.lineSend(self.csessid, [cmd, args, kwargs])

View file

@ -86,7 +86,7 @@ class Session(object):
"SCREENREADER":False, "SCREENREADER":False,
"INPUTDEBUG": False, "INPUTDEBUG": False,
"RAW": False, "RAW": False,
"NOMARKUP": False} "NOCOLOR": False}
self.server_data = {} self.server_data = {}
# map of input data to session methods # map of input data to session methods