Complete overhaul from start to finish.

This commit is contained in:
Andrew Bastien 2023-05-11 14:58:49 -04:00
parent 3d3bd5e9d7
commit ff6f0bebb8
3 changed files with 10 additions and 12 deletions

View file

@ -158,7 +158,7 @@ Damage roll: 1d6
Here's the start of how the function could look:
```python
# in mygame/evadventure/utils.py
# in mygame/evadventure/time.py
_OBJ_STATS = """
|c{key}|n

View file

@ -187,10 +187,11 @@ def _run_code_snippet(
if show_input:
for session in sessions:
data = {"text": (f">>> {pycode}", {"type": "py_input"}), "options": {"raw": True}}
try:
caller.msg(">>> %s" % pycode, session=session, options={"raw": True})
caller.msg(session=session, **data)
except TypeError:
caller.msg(">>> %s" % pycode, options={"raw": True})
caller.msg(**data)
try:
# reroute standard output to game client console
@ -202,10 +203,7 @@ def _run_code_snippet(
self.caller = caller
def write(self, string):
if string.endswith("\n"):
self.caller.msg(string[:-1])
else:
self.caller.msg(string)
self.caller.msg(text=(string.rstrip("\n"), {"type": "py_output"}))
fake_std = FakeStd(caller)
sys.stdout = fake_std
@ -222,7 +220,7 @@ def _run_code_snippet(
t0 = time.time()
ret = eval(pycode_compiled, {}, available_vars)
t1 = time.time()
duration = " (runtime ~ %.4f ms)" % ((t1 - t0) * 1000)
duration = f" (runtime ~ {(t1 - t0) * 1000:.4f} ms)"
caller.msg(duration)
else:
ret = eval(pycode_compiled, {}, available_vars)
@ -246,9 +244,9 @@ def _run_code_snippet(
for session in sessions:
try:
caller.msg(ret, session=session, options={"raw": True, "client_raw": client_raw})
caller.msg((ret, {"type": "py_output"}), session=session, options={"raw": True, "client_raw": client_raw})
except TypeError:
caller.msg(ret, options={"raw": True, "client_raw": client_raw})
caller.msg((ret, {"type": "py_output"}), options={"raw": True, "client_raw": client_raw})
def evennia_local_vars(caller):

View file

@ -56,7 +56,7 @@ class TestDedent(TestCase):
class TestListToString(TestCase):
"""
Default function header from utils.py:
Default function header from time.py:
list_to_string(inlist, sep=",", endsep=", and", addquote=False)
Examples:
@ -175,7 +175,7 @@ class TestANSIString(TestCase):
class TestTimeformat(TestCase):
"""
Default function header from utils.py:
Default function header from time.py:
time_format(seconds, style=0)
"""