diff --git a/evennia/commands/default/building.py b/evennia/commands/default/building.py index ff9b9e575..93a5e4d83 100644 --- a/evennia/commands/default/building.py +++ b/evennia/commands/default/building.py @@ -35,6 +35,7 @@ except ImportError: CHAR_TYPECLASS = settings.BASE_CHARACTER_TYPECLASS ROOM_TYPECLASS = settings.BASE_ROOM_TYPECLASS EXIT_TYPECLASS = settings.BASE_EXIT_TYPECLASS +_DEFAULT_WIDTH = settings.CLIENT_DEFAULT_WIDTH _PROTOTYPE_PARENTS = None @@ -1874,7 +1875,7 @@ class CmdExamine(ObjManipCommand): if things: 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]) - separator = "-" * 78 + separator = "-" * _DEFAULT_WIDTH #output info return '%s\n%s\n%s' % (separator, string.strip(), separator) diff --git a/evennia/commands/default/comms.py b/evennia/commands/default/comms.py index 5d7e3afef..ab66000f4 100644 --- a/evennia/commands/default/comms.py +++ b/evennia/commands/default/comms.py @@ -23,6 +23,7 @@ __all__ = ("CmdAddCom", "CmdDelCom", "CmdAllCom", "CmdCWho", "CmdChannelCreate", "CmdClock", "CmdCdesc", "CmdPage", "CmdIRC2Chan", "CmdRSS2Chan")#, "CmdIMC2Chan", "CmdIMCInfo", #"CmdIMCTell") +_DEFAULT_WIDTH = settings.CLIENT_DEFAULT_WIDTH def find_channel(caller, channelname, silent=False, noaliases=False): @@ -276,7 +277,7 @@ class CmdChannels(MuxPlayerCommand): if self.cmdstring == "comlist": # 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"]) for chan in subs: 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) else: # 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"]) for chan in channels: 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-")] if ircbots: 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: 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) @@ -905,7 +906,8 @@ class CmdRSS2Chan(MuxCommand): rssbots = [bot for bot in PlayerDB.objects.filter(db_is_bot=True, username__startswith="rssbot-")] if rssbots: 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: table.add_row(rssbot.id, rssbot.db.rss_rate, rssbot.db.ev_channel, rssbot.db.rss_url) self.caller.msg(table) diff --git a/evennia/commands/default/help.py b/evennia/commands/default/help.py index 54e5fb117..44b6daf8c 100644 --- a/evennia/commands/default/help.py +++ b/evennia/commands/default/help.py @@ -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. """ +from django.conf import settings from collections import defaultdict from evennia.utils.utils import fill, dedent from evennia.commands.command import Command @@ -16,16 +17,15 @@ from evennia.commands.default.muxcommand import MuxCommand # limit symbol import for API __all__ = ("CmdHelp", "CmdSetHelp") - - -SEP = "{C" + "-" * 78 + "{n" +_DEFAULT_WIDTH = settings.CLIENT_DEFAULT_WIDTH +_SEP = "{C" + "-" * _DEFAULT_WIDTH + "{n" def format_help_entry(title, help_text, aliases=None, suggested=None): """ This visually formats the help entry. """ - string = SEP + "\n" + string = _SEP + "\n" if title: string += "{CHelp topic for {w%s{n" % title if aliases: @@ -36,7 +36,7 @@ def format_help_entry(title, help_text, aliases=None, suggested=None): string += "\n\n{CSuggested:{n " string += "{w%s{n" % fill(", ".join(suggested)) string.strip() - string += "\n" + SEP + string += "\n" + _SEP return string @@ -48,12 +48,12 @@ def format_help_list(hdict_cmds, hdict_db): """ string = "" 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()): string += "\n {w%s{n:\n" % (str(category).title()) string += "{G" + fill(", ".join(sorted(hdict_cmds[category]))) + "{n" 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()): string += "\n\r {w%s{n:\n" % (str(category).title()) string += "{G" + fill(", ".join(sorted([str(topic) for topic in hdict_db[category]]))) + "{n" diff --git a/evennia/contrib/lineeditor.py b/evennia/contrib/lineeditor.py index 6a4884c97..10a8058ea 100644 --- a/evennia/contrib/lineeditor.py +++ b/evennia/contrib/lineeditor.py @@ -24,6 +24,7 @@ module. To use it just import and add it to your default `cmdset`. """ import re +from django.conf import settings from evennia import Command, CmdSet, utils from evennia import syscmdkeys from evennia.contrib.menusystem import prompt_yesno @@ -32,6 +33,7 @@ CMD_NOMATCH = syscmdkeys.CMD_NOMATCH CMD_NOINPUT = syscmdkeys.CMD_NOINPUT RE_GROUP = re.compile(r"\".*?\"|\'.*?\'|\S*") +_DEFAULT_WIDTH = settings.CLIENT_DEFAULT_WIDTH class CmdEditorBase(Command): @@ -347,7 +349,7 @@ class CmdEditorGroup(CmdEditorBase): editor.update_buffer(buf) elif cmd == ":f": # :f flood-fill buffer or lines of buffer. - width = 78 + width = _DEFAULT_WIDTH if not self.linerange: lstart = 0 lend = self.cline + 1 @@ -567,7 +569,7 @@ class LineEditor(object): nchars = len(buf) 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 if linenums: 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. """ - string = self.sep * 78 + """ + string = self.sep * _DEFAULT_WIDTH + """ - any non-command is appended to the end of the buffer. : - view buffer or only line :: - view buffer without line numbers or other parsing @@ -620,7 +622,7 @@ class LineEditor(object): - line numbers, or range lstart:lend, e.g. '3:7'. - one word or several enclosed in quotes. - longer string, usually not needed to be enclosed in quotes. -""" + self.sep * 78 +""" + self.sep * _DEFAULT_WIDTH return string diff --git a/evennia/utils/evtable.py b/evennia/utils/evtable.py index 4ed833033..9dfc0f4d3 100644 --- a/evennia/utils/evtable.py +++ b/evennia/utils/evtable.py @@ -115,11 +115,14 @@ table string. """ #from textwrap import wrap +from django.conf import settings from textwrap import TextWrapper from copy import deepcopy, copy from evennia.utils.utils import to_unicode, m_len from evennia.utils.ansi import ANSIString +_DEFAULT_WIDTH = settings.CLIENT_DEFAULT_WIDTH + def _to_ansi(obj): """ convert to ANSIString. @@ -262,7 +265,7 @@ class ANSITextWrapper(TextWrapper): # -- 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. @@ -283,7 +286,7 @@ def wrap(text, width=70, **kwargs): w = ANSITextWrapper(width=width, **kwargs) 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. Reformat the single paragraph in 'text' to fit in lines of no more diff --git a/evennia/utils/inlinefunc.py b/evennia/utils/inlinefunc.py index ed929aeb7..78abfbbed 100644 --- a/evennia/utils/inlinefunc.py +++ b/evennia/utils/inlinefunc.py @@ -47,12 +47,13 @@ import re from django.conf import settings from evennia.utils import utils +_DEFAULT_WIDTH = settings.CLIENT_DEFAULT_WIDTH # inline functions def pad(text, *args, **kwargs): "Pad to width. pad(text, width=78, align='c', fillchar=' ')" - width = 78 + width = _DEFAULT_WIDTH align = 'c' fillchar = ' ' for iarg, arg in enumerate(args): @@ -68,7 +69,7 @@ def pad(text, *args, **kwargs): def crop(text, *args, **kwargs): "Crop to width. crop(text, width=78, suffix='[...]')" - width = 78 + width = _DEFAULT_WIDTH suffix = "[...]" for iarg, arg in enumerate(args): if iarg == 0: @@ -81,7 +82,7 @@ def crop(text, *args, **kwargs): def wrap(text, *args, **kwargs): "Wrap/Fill text to width. fill(text, width=78, indent=0)" - width = 78 + width = _DEFAULT_WIDTH indent = 0 for iarg, arg in enumerate(args): if iarg == 0: diff --git a/evennia/utils/utils.py b/evennia/utils/utils.py index 013447d97..1e31cb6fa 100644 --- a/evennia/utils/utils.py +++ b/evennia/utils/utils.py @@ -32,6 +32,8 @@ _GA = object.__getattribute__ _SA = object.__setattr__ _DA = object.__delattr__ +_DEFAULT_WIDTH = settings.CLIENT_DEFAULT_WIDTH + def is_iter(iterable): """ @@ -54,7 +56,7 @@ def make_iter(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. @@ -71,7 +73,7 @@ def wrap(text, width=78, indent=0): # alias - fill 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 and fillchar defaults to the space character. @@ -85,7 +87,7 @@ def pad(text, width=78, align="c", fillchar=" "): else: 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 continues. Cropping will be done so that the suffix will also fit