diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a6cd9b600..8b9b27d2d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -98,6 +98,7 @@ Web/Django standard initiative (@strikaco) - Convert ServerConf model to store its values as a Picklefield (same as Attributes) instead of using a custom solution. - OOB: Add support for MSDP LIST, REPORT, UNREPORT commands (re-mapped to `msdp_list`, `msdp_report`, `msdp_unreport` inlinefuncs_) +- Added `evennia.ANSIString` to flat API. ### Utils diff --git a/evennia/__init__.py b/evennia/__init__.py index 5d221a7ebd..080114f7a0 100644 --- a/evennia/__init__.py +++ b/evennia/__init__.py @@ -101,6 +101,7 @@ EvTable = None EvForm = None EvEditor = None EvMore = None +ANSIString = None # Handlers SESSION_HANDLER = None @@ -153,6 +154,7 @@ def _init(): global settings, lockfuncs, logger, utils, gametime, ansi, spawn, managers global contrib, TICKER_HANDLER, MONITOR_HANDLER, SESSION_HANDLER, CHANNEL_HANDLER, TASK_HANDLER global EvMenu, EvTable, EvForm, EvMore, EvEditor + global ANSIString from .accounts.accounts import DefaultAccount from .accounts.accounts import DefaultGuest @@ -203,6 +205,7 @@ def _init(): from .utils.evtable import EvTable from .utils.evform import EvForm from .utils.eveditor import EvEditor + from .utils.ansi import ANSIString # handlers from .scripts.tickerhandler import TICKER_HANDLER diff --git a/evennia/utils/ansi.py b/evennia/utils/ansi.py index 6ba848dfb9..a10c6a4e2c 100644 --- a/evennia/utils/ansi.py +++ b/evennia/utils/ansi.py @@ -13,6 +13,7 @@ user. Depreciated example forms are available by extending the ansi mapping. """ +import functools from builtins import object, range import re @@ -534,8 +535,8 @@ def _spacing_preflight(func): functions used for padding ANSIStrings. """ - - def wrapped(self, width, fillchar=None): + @functools.wraps(func) + def wrapped(self, width=78, fillchar=None): if fillchar is None: fillchar = " " if (len(fillchar) != 1) or (not isinstance(fillchar, str)): @@ -555,7 +556,6 @@ def _query_super(func_name): of ANSIString. """ - def wrapped(self, *args, **kwargs): return getattr(self.clean(), func_name)(*args, **kwargs) return wrapped @@ -566,7 +566,6 @@ def _on_raw(func_name): Like query_super, but makes the operation run on the raw string. """ - def wrapped(self, *args, **kwargs): args = list(args) try: @@ -593,7 +592,6 @@ def _transform(func_name): with the resulting string. """ - def wrapped(self, *args, **kwargs): replacement_string = _query_super(func_name)(self, *args, **kwargs) to_string = [] @@ -1289,7 +1287,7 @@ class ANSIString(with_metaclass(ANSIMeta, str)): """ remainder = _difference % 2 - _difference /= 2 + _difference //= 2 spacing = self._filler(fillchar, _difference) result = spacing + self + spacing + self._filler(fillchar, remainder) return result