Added support for screen readers via the new option command (which merges the ability to set the screenreader mode with the encoding command). The new setting.SCREENREADER_REGEX_STRIP allows to customize what the screenreader mode strips.
This commit is contained in:
parent
10dbae9849
commit
4f384dc514
7 changed files with 85 additions and 55 deletions
|
|
@ -32,7 +32,7 @@ class PlayerCmdSet(CmdSet):
|
||||||
self.add(player.CmdCharCreate())
|
self.add(player.CmdCharCreate())
|
||||||
#self.add(player.CmdSessions())
|
#self.add(player.CmdSessions())
|
||||||
self.add(player.CmdWho())
|
self.add(player.CmdWho())
|
||||||
self.add(player.CmdEncoding())
|
self.add(player.CmdOption())
|
||||||
self.add(player.CmdQuit())
|
self.add(player.CmdQuit())
|
||||||
self.add(player.CmdPassword())
|
self.add(player.CmdPassword())
|
||||||
self.add(player.CmdColorTest())
|
self.add(player.CmdColorTest())
|
||||||
|
|
|
||||||
|
|
@ -22,3 +22,4 @@ class UnloggedinCmdSet(CmdSet):
|
||||||
self.add(unloggedin.CmdUnconnectedLook())
|
self.add(unloggedin.CmdUnconnectedLook())
|
||||||
self.add(unloggedin.CmdUnconnectedHelp())
|
self.add(unloggedin.CmdUnconnectedHelp())
|
||||||
self.add(unloggedin.CmdUnconnectedEncoding())
|
self.add(unloggedin.CmdUnconnectedEncoding())
|
||||||
|
self.add(unloggedin.CmdUnconnectedScreenreader())
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ MULTISESSION_MODE = settings.MULTISESSION_MODE
|
||||||
|
|
||||||
# limit symbol import for API
|
# limit symbol import for API
|
||||||
__all__ = ("CmdOOCLook", "CmdIC", "CmdOOC", "CmdPassword", "CmdQuit",
|
__all__ = ("CmdOOCLook", "CmdIC", "CmdOOC", "CmdPassword", "CmdQuit",
|
||||||
"CmdCharCreate", "CmdEncoding", "CmdSessions", "CmdWho",
|
"CmdCharCreate", "CmdOption", "CmdSessions", "CmdWho",
|
||||||
"CmdColorTest", "CmdQuell")
|
"CmdColorTest", "CmdQuell")
|
||||||
|
|
||||||
# force max nr chars to 1 if mode is 0 or 1
|
# force max nr chars to 1 if mode is 0 or 1
|
||||||
|
|
@ -405,67 +405,62 @@ class CmdWho(MuxPlayerCommand):
|
||||||
self.msg(string)
|
self.msg(string)
|
||||||
|
|
||||||
|
|
||||||
class CmdEncoding(MuxPlayerCommand):
|
class CmdOption(MuxPlayerCommand):
|
||||||
"""
|
"""
|
||||||
set which text encoding to use
|
Set an account option
|
||||||
|
|
||||||
Usage:
|
@option
|
||||||
@encoding/switches [<encoding>]
|
@option encoding = [encoding]
|
||||||
|
@option screenreader = on|off
|
||||||
|
|
||||||
Switches:
|
The text encoding is mostly an issue only if you want to use
|
||||||
clear - clear your custom encoding
|
non-ASCII characters (i.e. letters/symbols not found in English).
|
||||||
|
If you see that your characters look strange (or you get encoding
|
||||||
|
errors), you should use this command to set the server encoding to
|
||||||
|
be the same used in your client program. If given the empty string
|
||||||
|
(default), the custom encoding will be removed and only Evennia's
|
||||||
|
defaults will be used.
|
||||||
|
|
||||||
|
The screenreader setting strips the text output for users using
|
||||||
|
screen readers. It strips based on settings.SCREENREADER_REGEX_STRIP.
|
||||||
|
|
||||||
This sets the text encoding for communicating with Evennia. This is mostly
|
"""
|
||||||
an issue only if you want to use non-ASCII characters (i.e. letters/symbols
|
key = "@option"
|
||||||
not found in English). If you see that your characters look strange (or you
|
aliases = "@options"
|
||||||
get encoding errors), you should use this command to set the server
|
|
||||||
encoding to be the same used in your client program.
|
|
||||||
|
|
||||||
Common encodings are utf-8 (default), latin-1, ISO-8859-1 etc.
|
|
||||||
|
|
||||||
If you don't submit an encoding, the current encoding will be displayed
|
|
||||||
instead.
|
|
||||||
"""
|
|
||||||
|
|
||||||
key = "@encoding"
|
|
||||||
aliases = "@encode"
|
|
||||||
locks = "cmd:all()"
|
locks = "cmd:all()"
|
||||||
|
|
||||||
def func(self):
|
def func(self):
|
||||||
"""
|
"""
|
||||||
Sets the encoding.
|
Implements the command
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self.session is None:
|
if self.session is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
if 'clear' in self.switches:
|
if not self.args:
|
||||||
# remove customization
|
# list the option settings
|
||||||
old_encoding = self.session.encoding
|
string = "{wEncoding{n:\n"
|
||||||
if old_encoding:
|
pencoding = self.session.encoding or "None"
|
||||||
string = "Your custom text encoding ('%s') was cleared." % old_encoding
|
sencodings = settings.ENCODINGS
|
||||||
else:
|
string += " Custom: %s\n Server: %s" % (pencoding, ", ".join(sencodings))
|
||||||
string = "No custom encoding was set."
|
string += "\n{wScreen Reader mode:{n %s" % self.session.screenreader
|
||||||
self.session.encoding = "utf-8"
|
self.caller.msg(string)
|
||||||
elif not self.args:
|
return
|
||||||
# just list the encodings supported
|
|
||||||
pencoding = self.session.encoding
|
if not self.rhs:
|
||||||
string = ""
|
self.caller.msg("Usage: @option [name = [value]]")
|
||||||
if pencoding:
|
|
||||||
string += "Default encoding: {g%s{n (change with {w@encoding <encoding>{n)" % pencoding
|
if self.lhs == "encoding":
|
||||||
encodings = settings.ENCODINGS
|
|
||||||
if encodings:
|
|
||||||
string += "\nServer's alternative encodings (tested in this order):\n {g%s{n" % ", ".join(encodings)
|
|
||||||
if not string:
|
|
||||||
string = "No encodings found."
|
|
||||||
else:
|
|
||||||
# change encoding
|
# change encoding
|
||||||
old_encoding = self.session.encoding
|
old_encoding = self.session.encoding
|
||||||
encoding = self.args
|
new_encoding = self.rhs.strip() or "utf-8"
|
||||||
self.session.encoding = encoding
|
self.session.encoding = new_encoding
|
||||||
string = "Your custom text encoding was changed from '%s' to '%s'." % (old_encoding, encoding)
|
self.caller.msg("Encoding was changed from %s to %s." % (old_encoding, new_encoding))
|
||||||
self.msg(string.strip())
|
return
|
||||||
|
|
||||||
|
if self.lhs == "screenreader":
|
||||||
|
onoff = self.rhs.lower() == "on"
|
||||||
|
self.session.screenreader = onoff
|
||||||
|
self.caller.msg("Screen reader mode was turned {w%s{n." % ("on" if onoff else "off"))
|
||||||
|
|
||||||
|
|
||||||
class CmdPassword(MuxPlayerCommand):
|
class CmdPassword(MuxPlayerCommand):
|
||||||
|
|
|
||||||
|
|
@ -361,6 +361,7 @@ You are not yet logged into the game. Commands available at this point:
|
||||||
{wlook{n - re-show the connection screen
|
{wlook{n - re-show the connection screen
|
||||||
{whelp{n - show this help
|
{whelp{n - show this help
|
||||||
{wencoding{n - change the text encoding to match your client
|
{wencoding{n - change the text encoding to match your client
|
||||||
|
{wscreenreader{n - make the server more suitable for use with screen readers
|
||||||
{wquit{n - abort the connection
|
{wquit{n - abort the connection
|
||||||
|
|
||||||
First create an account e.g. with {wcreate Anna c67jHL8p{n
|
First create an account e.g. with {wcreate Anna c67jHL8p{n
|
||||||
|
|
@ -397,7 +398,7 @@ class CmdUnconnectedEncoding(MuxCommand):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
key = "encoding"
|
key = "encoding"
|
||||||
aliases = "@encoding, @encode"
|
aliases = ("@encoding", "@encode")
|
||||||
locks = "cmd:all()"
|
locks = "cmd:all()"
|
||||||
|
|
||||||
def func(self):
|
def func(self):
|
||||||
|
|
@ -435,6 +436,25 @@ class CmdUnconnectedEncoding(MuxCommand):
|
||||||
string = "Your custom text encoding was changed from '%s' to '%s'." % (old_encoding, encoding)
|
string = "Your custom text encoding was changed from '%s' to '%s'." % (old_encoding, encoding)
|
||||||
self.caller.msg(string.strip())
|
self.caller.msg(string.strip())
|
||||||
|
|
||||||
|
class CmdUnconnectedScreenreader(MuxCommand):
|
||||||
|
"""
|
||||||
|
Activate screenreader mode.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
screenreader
|
||||||
|
|
||||||
|
Used to flip screenreader mode on and off before logging in (when
|
||||||
|
logged in, use @option screenreader on).
|
||||||
|
"""
|
||||||
|
key = "screenreader"
|
||||||
|
aliases = "@screenreader"
|
||||||
|
|
||||||
|
def func(self):
|
||||||
|
"Flips screenreader setting."
|
||||||
|
self.session.screenreader = not self.session.screenreader
|
||||||
|
string = "Screenreader mode turned {w%s{n." % ("on" if self.session.screenreader else "off")
|
||||||
|
self.caller.msg(string)
|
||||||
|
|
||||||
|
|
||||||
def _create_player(session, playername, password, permissions, typeclass=None):
|
def _create_player(session, playername, password, permissions, typeclass=None):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ It is stored on the Server side (as opposed to protocol-specific sessions which
|
||||||
are stored on the Portal side)
|
are stored on the Portal side)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import re
|
||||||
from time import time
|
from time import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
@ -18,11 +19,12 @@ from evennia.commands.cmdhandler import cmdhandler
|
||||||
from evennia.commands.cmdsethandler import CmdSetHandler
|
from evennia.commands.cmdsethandler import CmdSetHandler
|
||||||
from evennia.server.session import Session
|
from evennia.server.session import Session
|
||||||
|
|
||||||
IDLE_COMMAND = settings.IDLE_COMMAND
|
_IDLE_COMMAND = settings.IDLE_COMMAND
|
||||||
_GA = object.__getattribute__
|
_GA = object.__getattribute__
|
||||||
_ObjectDB = None
|
_ObjectDB = None
|
||||||
|
_ANSI = None
|
||||||
INLINEFUNC_ENABLED = settings.INLINEFUNC_ENABLED
|
_INLINEFUNC_ENABLED = settings.INLINEFUNC_ENABLED
|
||||||
|
_RE_SCREENREADER_REGEX = re.compile(r"%s" % settings.SCREENREADER_REGEX_STRIP, re.DOTALL + re.MULTILINE)
|
||||||
|
|
||||||
# i18n
|
# i18n
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
@ -205,7 +207,7 @@ class ServerSession(Session):
|
||||||
# this is treated as a command input
|
# this is treated as a command input
|
||||||
#text = to_unicode(escape_control_sequences(text), encoding=self.encoding)
|
#text = to_unicode(escape_control_sequences(text), encoding=self.encoding)
|
||||||
# handle the 'idle' command
|
# handle the 'idle' command
|
||||||
if text.strip() == IDLE_COMMAND:
|
if text.strip() == _IDLE_COMMAND:
|
||||||
self.update_session_counters(idle=True)
|
self.update_session_counters(idle=True)
|
||||||
return
|
return
|
||||||
if self.player:
|
if self.player:
|
||||||
|
|
@ -227,8 +229,14 @@ class ServerSession(Session):
|
||||||
Send Evennia -> User
|
Send Evennia -> User
|
||||||
"""
|
"""
|
||||||
text = text if text else ""
|
text = text if text else ""
|
||||||
if INLINEFUNC_ENABLED and not "raw" in kwargs:
|
if _INLINEFUNC_ENABLED and not "raw" in kwargs:
|
||||||
text = parse_inlinefunc(text, strip="strip_inlinefunc" in kwargs, session=self)
|
text = parse_inlinefunc(text, strip="strip_inlinefunc" in kwargs, session=self)
|
||||||
|
if self.screenreader:
|
||||||
|
global _ANSI
|
||||||
|
if not _ANSI:
|
||||||
|
from evennia.utils import ansi as _ANSI
|
||||||
|
text = _ANSI.parse_ansi(text, strip_ansi=True, xterm256=False, mxp=False)
|
||||||
|
text = _RE_SCREENREADER_REGEX.sub("", text)
|
||||||
session = kwargs.pop('session', None)
|
session = kwargs.pop('session', None)
|
||||||
session = session or self
|
session = session or self
|
||||||
self.sessionhandler.data_out(session, text=text, **kwargs)
|
self.sessionhandler.data_out(session, text=text, **kwargs)
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ class Session(object):
|
||||||
|
|
||||||
# names of attributes that should be affected by syncing.
|
# names of attributes that should be affected by syncing.
|
||||||
_attrs_to_sync = ('protocol_key', 'address', 'suid', 'sessid', 'uid',
|
_attrs_to_sync = ('protocol_key', 'address', 'suid', 'sessid', 'uid',
|
||||||
'uname', 'logged_in', 'puid', 'encoding',
|
'uname', 'logged_in', 'puid', 'encoding', 'screenreader',
|
||||||
'conn_time', 'cmd_last', 'cmd_last_visible', 'cmd_total',
|
'conn_time', 'cmd_last', 'cmd_last_visible', 'cmd_total',
|
||||||
'protocol_flags', 'server_data', "cmdset_storage_string")
|
'protocol_flags', 'server_data', "cmdset_storage_string")
|
||||||
|
|
||||||
|
|
@ -74,6 +74,7 @@ class Session(object):
|
||||||
self.cmd_last = self.conn_time
|
self.cmd_last = self.conn_time
|
||||||
self.cmd_total = 0
|
self.cmd_total = 0
|
||||||
self.encoding = "utf-8"
|
self.encoding = "utf-8"
|
||||||
|
self.screenreader = False
|
||||||
|
|
||||||
self.protocol_flags = {}
|
self.protocol_flags = {}
|
||||||
self.server_data = {}
|
self.server_data = {}
|
||||||
|
|
|
||||||
|
|
@ -140,6 +140,11 @@ IDLE_COMMAND = "idle"
|
||||||
# Add sets for languages/regions your players are likely to use.
|
# Add sets for languages/regions your players are likely to use.
|
||||||
# (see http://en.wikipedia.org/wiki/Character_encoding)
|
# (see http://en.wikipedia.org/wiki/Character_encoding)
|
||||||
ENCODINGS = ["utf-8", "latin-1", "ISO-8859-1"]
|
ENCODINGS = ["utf-8", "latin-1", "ISO-8859-1"]
|
||||||
|
# Regular expression applied to all output to a given session in order
|
||||||
|
# to strip away characters (usually various forms of decorations) for the benefit
|
||||||
|
# of users with screen readers. Note that ANSI/MXP doesn't need to
|
||||||
|
# be stripped this way, that is handled automatically.
|
||||||
|
SCREENREADER_REGEX_STRIP = r"\+-+|\+$|\+~|--+|~~+|==+"
|
||||||
# The game server opens an AMP port so that the portal can
|
# The game server opens an AMP port so that the portal can
|
||||||
# communicate with it. This is an internal functionality of Evennia, usually
|
# communicate with it. This is an internal functionality of Evennia, usually
|
||||||
# operating between two processes on the same machine. You usually don't need to
|
# operating between two processes on the same machine. You usually don't need to
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue