Made various parts of the core respect the CLIENT_DEFAULT_WIDTH setting. Resolves #710.

This commit is contained in:
Griatch 2015-03-19 19:21:05 +01:00
parent a01493bfa0
commit c781160225
7 changed files with 35 additions and 24 deletions

View file

@ -35,6 +35,7 @@ except ImportError:
CHAR_TYPECLASS = settings.BASE_CHARACTER_TYPECLASS CHAR_TYPECLASS = settings.BASE_CHARACTER_TYPECLASS
ROOM_TYPECLASS = settings.BASE_ROOM_TYPECLASS ROOM_TYPECLASS = settings.BASE_ROOM_TYPECLASS
EXIT_TYPECLASS = settings.BASE_EXIT_TYPECLASS EXIT_TYPECLASS = settings.BASE_EXIT_TYPECLASS
_DEFAULT_WIDTH = settings.CLIENT_DEFAULT_WIDTH
_PROTOTYPE_PARENTS = None _PROTOTYPE_PARENTS = None
@ -1874,7 +1875,7 @@ class CmdExamine(ObjManipCommand):
if things: if things:
string += "\n{wContents{n: %s" % ", ".join(["%s(%s)" % (cont.name, cont.dbref) for cont in obj.contents string += "\n{wContents{n: %s" % ", ".join(["%s(%s)" % (cont.name, cont.dbref) for cont in obj.contents
if cont not in exits and cont not in pobjs]) if cont not in exits and cont not in pobjs])
separator = "-" * 78 separator = "-" * _DEFAULT_WIDTH
#output info #output info
return '%s\n%s\n%s' % (separator, string.strip(), separator) return '%s\n%s\n%s' % (separator, string.strip(), separator)

View file

@ -23,6 +23,7 @@ __all__ = ("CmdAddCom", "CmdDelCom", "CmdAllCom",
"CmdCWho", "CmdChannelCreate", "CmdClock", "CmdCdesc", "CmdCWho", "CmdChannelCreate", "CmdClock", "CmdCdesc",
"CmdPage", "CmdIRC2Chan", "CmdRSS2Chan")#, "CmdIMC2Chan", "CmdIMCInfo", "CmdPage", "CmdIRC2Chan", "CmdRSS2Chan")#, "CmdIMC2Chan", "CmdIMCInfo",
#"CmdIMCTell") #"CmdIMCTell")
_DEFAULT_WIDTH = settings.CLIENT_DEFAULT_WIDTH
def find_channel(caller, channelname, silent=False, noaliases=False): def find_channel(caller, channelname, silent=False, noaliases=False):
@ -276,7 +277,7 @@ class CmdChannels(MuxPlayerCommand):
if self.cmdstring == "comlist": if self.cmdstring == "comlist":
# just display the subscribed channels with no extra info # just display the subscribed channels with no extra info
comtable = evtable.EvTable("{wchannel{n", "{wmy aliases{n", "{wdescription{n", align="l", maxwidth=78) comtable = evtable.EvTable("{wchannel{n", "{wmy aliases{n", "{wdescription{n", align="l", maxwidth=_DEFAULT_WIDTH)
#comtable = prettytable.PrettyTable(["{wchannel", "{wmy aliases", "{wdescription"]) #comtable = prettytable.PrettyTable(["{wchannel", "{wmy aliases", "{wdescription"])
for chan in subs: for chan in subs:
clower = chan.key.lower() clower = chan.key.lower()
@ -289,7 +290,7 @@ class CmdChannels(MuxPlayerCommand):
caller.msg("\n{wChannel subscriptions{n (use {w@channels{n to list all, {waddcom{n/{wdelcom{n to sub/unsub):{n\n%s" % comtable) caller.msg("\n{wChannel subscriptions{n (use {w@channels{n to list all, {waddcom{n/{wdelcom{n to sub/unsub):{n\n%s" % comtable)
else: else:
# full listing (of channels caller is able to listen to) # full listing (of channels caller is able to listen to)
comtable = evtable.EvTable("{wsub{n", "{wchannel{n", "{wmy aliases{n", "{wlocks{n", "{wdescription{n", maxwidth=78) comtable = evtable.EvTable("{wsub{n", "{wchannel{n", "{wmy aliases{n", "{wlocks{n", "{wdescription{n", maxwidth=_DEFAULT_WIDTH)
#comtable = prettytable.PrettyTable(["{wsub", "{wchannel", "{wmy aliases", "{wlocks", "{wdescription"]) #comtable = prettytable.PrettyTable(["{wsub", "{wchannel", "{wmy aliases", "{wlocks", "{wdescription"])
for chan in channels: for chan in channels:
clower = chan.key.lower() clower = chan.key.lower()
@ -796,7 +797,7 @@ class CmdIRC2Chan(MuxCommand):
ircbots = [bot for bot in PlayerDB.objects.filter(db_is_bot=True, username__startswith="ircbot-")] ircbots = [bot for bot in PlayerDB.objects.filter(db_is_bot=True, username__startswith="ircbot-")]
if ircbots: if ircbots:
from evennia.utils.evtable import EvTable from evennia.utils.evtable import EvTable
table = EvTable("{wdbid{n", "{wbotname{n", "{wev-channel{n", "{wirc-channel{n", maxwidth=78) table = EvTable("{wdbid{n", "{wbotname{n", "{wev-channel{n", "{wirc-channel{n", maxwidth=_DEFAULT_WIDTH)
for ircbot in ircbots: for ircbot in ircbots:
ircinfo = "%s (%s:%s)" % (ircbot.db.irc_channel, ircbot.db.irc_network, ircbot.db.irc_port) ircinfo = "%s (%s:%s)" % (ircbot.db.irc_channel, ircbot.db.irc_network, ircbot.db.irc_port)
table.add_row(ircbot.id, ircbot.db.irc_botname, ircbot.db.ev_channel, ircinfo) table.add_row(ircbot.id, ircbot.db.irc_botname, ircbot.db.ev_channel, ircinfo)
@ -905,7 +906,8 @@ class CmdRSS2Chan(MuxCommand):
rssbots = [bot for bot in PlayerDB.objects.filter(db_is_bot=True, username__startswith="rssbot-")] rssbots = [bot for bot in PlayerDB.objects.filter(db_is_bot=True, username__startswith="rssbot-")]
if rssbots: if rssbots:
from evennia.utils.evtable import EvTable from evennia.utils.evtable import EvTable
table = EvTable("{wdbid{n", "{wupdate rate{n", "{wev-channel", "{wRSS feed URL{n", border="cells", maxwidth=78) table = EvTable("{wdbid{n", "{wupdate rate{n", "{wev-channel",
"{wRSS feed URL{n", border="cells", maxwidth=_DEFAULT_WIDTH)
for rssbot in rssbots: for rssbot in rssbots:
table.add_row(rssbot.id, rssbot.db.rss_rate, rssbot.db.ev_channel, rssbot.db.rss_url) table.add_row(rssbot.id, rssbot.db.rss_rate, rssbot.db.ev_channel, rssbot.db.rss_url)
self.caller.msg(table) self.caller.msg(table)

View file

@ -6,6 +6,7 @@ set. The normal, database-tied help system is used for collaborative
creation of other help topics such as RP help or game-world aides. creation of other help topics such as RP help or game-world aides.
""" """
from django.conf import settings
from collections import defaultdict from collections import defaultdict
from evennia.utils.utils import fill, dedent from evennia.utils.utils import fill, dedent
from evennia.commands.command import Command from evennia.commands.command import Command
@ -16,16 +17,15 @@ from evennia.commands.default.muxcommand import MuxCommand
# limit symbol import for API # limit symbol import for API
__all__ = ("CmdHelp", "CmdSetHelp") __all__ = ("CmdHelp", "CmdSetHelp")
_DEFAULT_WIDTH = settings.CLIENT_DEFAULT_WIDTH
_SEP = "{C" + "-" * _DEFAULT_WIDTH + "{n"
SEP = "{C" + "-" * 78 + "{n"
def format_help_entry(title, help_text, aliases=None, suggested=None): def format_help_entry(title, help_text, aliases=None, suggested=None):
""" """
This visually formats the help entry. This visually formats the help entry.
""" """
string = SEP + "\n" string = _SEP + "\n"
if title: if title:
string += "{CHelp topic for {w%s{n" % title string += "{CHelp topic for {w%s{n" % title
if aliases: if aliases:
@ -36,7 +36,7 @@ def format_help_entry(title, help_text, aliases=None, suggested=None):
string += "\n\n{CSuggested:{n " string += "\n\n{CSuggested:{n "
string += "{w%s{n" % fill(", ".join(suggested)) string += "{w%s{n" % fill(", ".join(suggested))
string.strip() string.strip()
string += "\n" + SEP string += "\n" + _SEP
return string return string
@ -48,12 +48,12 @@ def format_help_list(hdict_cmds, hdict_db):
""" """
string = "" string = ""
if hdict_cmds and any(hdict_cmds.values()): if hdict_cmds and any(hdict_cmds.values()):
string += "\n" + SEP + "\n {CCommand help entries{n\n" + SEP string += "\n" + _SEP + "\n {CCommand help entries{n\n" + _SEP
for category in sorted(hdict_cmds.keys()): for category in sorted(hdict_cmds.keys()):
string += "\n {w%s{n:\n" % (str(category).title()) string += "\n {w%s{n:\n" % (str(category).title())
string += "{G" + fill(", ".join(sorted(hdict_cmds[category]))) + "{n" string += "{G" + fill(", ".join(sorted(hdict_cmds[category]))) + "{n"
if hdict_db and any(hdict_db.values()): if hdict_db and any(hdict_db.values()):
string += "\n\n" + SEP + "\n\r {COther help entries{n\n" + SEP string += "\n\n" + _SEP + "\n\r {COther help entries{n\n" + _SEP
for category in sorted(hdict_db.keys()): for category in sorted(hdict_db.keys()):
string += "\n\r {w%s{n:\n" % (str(category).title()) string += "\n\r {w%s{n:\n" % (str(category).title())
string += "{G" + fill(", ".join(sorted([str(topic) for topic in hdict_db[category]]))) + "{n" string += "{G" + fill(", ".join(sorted([str(topic) for topic in hdict_db[category]]))) + "{n"

View file

@ -24,6 +24,7 @@ module. To use it just import and add it to your default `cmdset`.
""" """
import re import re
from django.conf import settings
from evennia import Command, CmdSet, utils from evennia import Command, CmdSet, utils
from evennia import syscmdkeys from evennia import syscmdkeys
from evennia.contrib.menusystem import prompt_yesno from evennia.contrib.menusystem import prompt_yesno
@ -32,6 +33,7 @@ CMD_NOMATCH = syscmdkeys.CMD_NOMATCH
CMD_NOINPUT = syscmdkeys.CMD_NOINPUT CMD_NOINPUT = syscmdkeys.CMD_NOINPUT
RE_GROUP = re.compile(r"\".*?\"|\'.*?\'|\S*") RE_GROUP = re.compile(r"\".*?\"|\'.*?\'|\S*")
_DEFAULT_WIDTH = settings.CLIENT_DEFAULT_WIDTH
class CmdEditorBase(Command): class CmdEditorBase(Command):
@ -347,7 +349,7 @@ class CmdEditorGroup(CmdEditorBase):
editor.update_buffer(buf) editor.update_buffer(buf)
elif cmd == ":f": elif cmd == ":f":
# :f <l> flood-fill buffer or <l> lines of buffer. # :f <l> flood-fill buffer or <l> lines of buffer.
width = 78 width = _DEFAULT_WIDTH
if not self.linerange: if not self.linerange:
lstart = 0 lstart = 0
lend = self.cline + 1 lend = self.cline + 1
@ -567,7 +569,7 @@ class LineEditor(object):
nchars = len(buf) nchars = len(buf)
sep = self.sep sep = self.sep
header = "{n" + sep * 10 + "Line Editor [%s]" % self.key + sep * (78-25-len(self.key)) header = "{n" + sep * 10 + "Line Editor [%s]" % self.key + sep * (_DEFAULT_WIDTH-25-len(self.key))
footer = "{n" + sep * 10 + "[l:%02i w:%03i c:%04i]" % (nlines, nwords, nchars) + sep * 12 + "(:h for help)" + sep * 23 footer = "{n" + sep * 10 + "[l:%02i w:%03i c:%04i]" % (nlines, nwords, nchars) + sep * 12 + "(:h for help)" + sep * 23
if linenums: if linenums:
main = "\n".join("{b%02i|{n %s" % (iline + 1 + offset, line) for iline, line in enumerate(lines)) main = "\n".join("{b%02i|{n %s" % (iline + 1 + offset, line) for iline, line in enumerate(lines))
@ -580,7 +582,7 @@ class LineEditor(object):
""" """
Shows the help entry for the editor. Shows the help entry for the editor.
""" """
string = self.sep * 78 + """ string = self.sep * _DEFAULT_WIDTH + """
<txt> - any non-command is appended to the end of the buffer. <txt> - any non-command is appended to the end of the buffer.
: <l> - view buffer or only line <l> : <l> - view buffer or only line <l>
:: <l> - view buffer without line numbers or other parsing :: <l> - view buffer without line numbers or other parsing
@ -620,7 +622,7 @@ class LineEditor(object):
<l> - line numbers, or range lstart:lend, e.g. '3:7'. <l> - line numbers, or range lstart:lend, e.g. '3:7'.
<w> - one word or several enclosed in quotes. <w> - one word or several enclosed in quotes.
<txt> - longer string, usually not needed to be enclosed in quotes. <txt> - longer string, usually not needed to be enclosed in quotes.
""" + self.sep * 78 """ + self.sep * _DEFAULT_WIDTH
return string return string

View file

@ -115,11 +115,14 @@ table string.
""" """
#from textwrap import wrap #from textwrap import wrap
from django.conf import settings
from textwrap import TextWrapper from textwrap import TextWrapper
from copy import deepcopy, copy from copy import deepcopy, copy
from evennia.utils.utils import to_unicode, m_len from evennia.utils.utils import to_unicode, m_len
from evennia.utils.ansi import ANSIString from evennia.utils.ansi import ANSIString
_DEFAULT_WIDTH = settings.CLIENT_DEFAULT_WIDTH
def _to_ansi(obj): def _to_ansi(obj):
""" """
convert to ANSIString. convert to ANSIString.
@ -262,7 +265,7 @@ class ANSITextWrapper(TextWrapper):
# -- Convenience interface --------------------------------------------- # -- Convenience interface ---------------------------------------------
def wrap(text, width=70, **kwargs): def wrap(text, width=_DEFAULT_WIDTH, **kwargs):
""" """
Wrap a single paragraph of text, returning a list of wrapped lines. Wrap a single paragraph of text, returning a list of wrapped lines.
@ -283,7 +286,7 @@ def wrap(text, width=70, **kwargs):
w = ANSITextWrapper(width=width, **kwargs) w = ANSITextWrapper(width=width, **kwargs)
return w.wrap(text) return w.wrap(text)
def fill(text, width=70, **kwargs): def fill(text, width=_DEFAULT_WIDTH, **kwargs):
"""Fill a single paragraph of text, returning a new string. """Fill a single paragraph of text, returning a new string.
Reformat the single paragraph in 'text' to fit in lines of no more Reformat the single paragraph in 'text' to fit in lines of no more

View file

@ -47,12 +47,13 @@ import re
from django.conf import settings from django.conf import settings
from evennia.utils import utils from evennia.utils import utils
_DEFAULT_WIDTH = settings.CLIENT_DEFAULT_WIDTH
# inline functions # inline functions
def pad(text, *args, **kwargs): def pad(text, *args, **kwargs):
"Pad to width. pad(text, width=78, align='c', fillchar=' ')" "Pad to width. pad(text, width=78, align='c', fillchar=' ')"
width = 78 width = _DEFAULT_WIDTH
align = 'c' align = 'c'
fillchar = ' ' fillchar = ' '
for iarg, arg in enumerate(args): for iarg, arg in enumerate(args):
@ -68,7 +69,7 @@ def pad(text, *args, **kwargs):
def crop(text, *args, **kwargs): def crop(text, *args, **kwargs):
"Crop to width. crop(text, width=78, suffix='[...]')" "Crop to width. crop(text, width=78, suffix='[...]')"
width = 78 width = _DEFAULT_WIDTH
suffix = "[...]" suffix = "[...]"
for iarg, arg in enumerate(args): for iarg, arg in enumerate(args):
if iarg == 0: if iarg == 0:
@ -81,7 +82,7 @@ def crop(text, *args, **kwargs):
def wrap(text, *args, **kwargs): def wrap(text, *args, **kwargs):
"Wrap/Fill text to width. fill(text, width=78, indent=0)" "Wrap/Fill text to width. fill(text, width=78, indent=0)"
width = 78 width = _DEFAULT_WIDTH
indent = 0 indent = 0
for iarg, arg in enumerate(args): for iarg, arg in enumerate(args):
if iarg == 0: if iarg == 0:

View file

@ -32,6 +32,8 @@ _GA = object.__getattribute__
_SA = object.__setattr__ _SA = object.__setattr__
_DA = object.__delattr__ _DA = object.__delattr__
_DEFAULT_WIDTH = settings.CLIENT_DEFAULT_WIDTH
def is_iter(iterable): def is_iter(iterable):
""" """
@ -54,7 +56,7 @@ def make_iter(obj):
return not hasattr(obj, '__iter__') and [obj] or obj return not hasattr(obj, '__iter__') and [obj] or obj
def wrap(text, width=78, indent=0): def wrap(text, width=_DEFAULT_WIDTH, indent=0):
""" """
Safely wrap text to a certain number of characters. Safely wrap text to a certain number of characters.
@ -71,7 +73,7 @@ def wrap(text, width=78, indent=0):
# alias - fill # alias - fill
fill = wrap fill = wrap
def pad(text, width=78, align="c", fillchar=" "): def pad(text, width=_DEFAULT_WIDTH, align="c", fillchar=" "):
""" """
Pads to a given width, align is one of c,l,r Pads to a given width, align is one of c,l,r
and fillchar defaults to the space character. and fillchar defaults to the space character.
@ -85,7 +87,7 @@ def pad(text, width=78, align="c", fillchar=" "):
else: else:
return text.center(width, fillchar) return text.center(width, fillchar)
def crop(text, width=78, suffix="[...]"): def crop(text, width=_DEFAULT_WIDTH, suffix="[...]"):
""" """
Crop text to a certain width, adding `suffix` to show that the line Crop text to a certain width, adding `suffix` to show that the line
continues. Cropping will be done so that the suffix will also fit continues. Cropping will be done so that the suffix will also fit