mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
Make exit() work in py Cmd, make it more instructive
This commit is contained in:
parent
db17ece61b
commit
bdd5d7f6ca
2 changed files with 23 additions and 8 deletions
|
|
@ -41,6 +41,7 @@ without arguments starts a full interactive Python console.
|
|||
but is now only used to pass extra kwargs into the justify function.
|
||||
- Improve performance of `find` and `objects` commands on large data sets (strikaco)
|
||||
- New `CHANNEL_HANDLER_CLASS` setting allows for replacing the ChannelHandler entirely.
|
||||
- Made `py` interactive mode support regular quit() and more verbose.
|
||||
|
||||
|
||||
## Evennia 0.9 (2018-2019)
|
||||
|
|
|
|||
|
|
@ -285,8 +285,6 @@ class EvenniaPythonConsole(code.InteractiveConsole):
|
|||
result = None
|
||||
try:
|
||||
result = super().push(line)
|
||||
except SystemExit:
|
||||
pass
|
||||
finally:
|
||||
sys.stdout = old_stdout
|
||||
sys.stderr = old_stderr
|
||||
|
|
@ -302,6 +300,7 @@ class CmdPy(COMMAND_DEFAULT_CLASS):
|
|||
py/edit
|
||||
py/time <cmd>
|
||||
py/clientraw <cmd>
|
||||
py/noecho
|
||||
|
||||
Switches:
|
||||
time - output an approximate execution time for <cmd>
|
||||
|
|
@ -309,6 +308,8 @@ class CmdPy(COMMAND_DEFAULT_CLASS):
|
|||
clientraw - turn off all client-specific escaping. Note that this may
|
||||
lead to different output depending on prototocol (such as angular brackets
|
||||
being parsed as HTML in the webclient but not in telnet clients)
|
||||
noecho - in Python console mode, turn off the input echo (e.g. if your client
|
||||
does this for you already)
|
||||
|
||||
Without argument, open a Python console in-game. This is a full console,
|
||||
accepting multi-line Python code for testing and debugging. Type `exit()` to
|
||||
|
|
@ -340,7 +341,7 @@ class CmdPy(COMMAND_DEFAULT_CLASS):
|
|||
|
||||
key = "py"
|
||||
aliases = ["!"]
|
||||
switch_options = ("time", "edit", "clientraw")
|
||||
switch_options = ("time", "edit", "clientraw", "noecho")
|
||||
locks = "cmd:perm(py) or perm(Developer)"
|
||||
help_category = "System"
|
||||
|
||||
|
|
@ -350,6 +351,8 @@ class CmdPy(COMMAND_DEFAULT_CLASS):
|
|||
caller = self.caller
|
||||
pycode = self.args
|
||||
|
||||
noecho = "noecho" in self.switches
|
||||
|
||||
if "edit" in self.switches:
|
||||
caller.db._py_measure_time = "time" in self.switches
|
||||
caller.db._py_clientraw = "clientraw" in self.switches
|
||||
|
|
@ -368,15 +371,26 @@ class CmdPy(COMMAND_DEFAULT_CLASS):
|
|||
# Run in interactive mode
|
||||
console = EvenniaPythonConsole(self.caller)
|
||||
banner = (
|
||||
f"|gPython {sys.version} on {sys.platform}\n"
|
||||
"Evennia interactive console mode - type 'exit()' to leave.|n"
|
||||
"|gEvennia Interactive Python mode{echomode}\n"
|
||||
"Python {version} on {platform}".format(
|
||||
echomode=" (no echoing of prompts)" if noecho else "",
|
||||
version=sys.version,
|
||||
platform=sys.platform,
|
||||
)
|
||||
)
|
||||
self.msg(banner)
|
||||
line = ""
|
||||
prompt = ">>>"
|
||||
main_prompt = "|x[py mode - quit() to exit]|n"
|
||||
prompt = main_prompt
|
||||
while line.lower() not in ("exit", "exit()"):
|
||||
line = yield (prompt)
|
||||
prompt = "..." if console.push(line) else ">>>"
|
||||
try:
|
||||
line = yield (prompt)
|
||||
if noecho:
|
||||
prompt = "..." if console.push(line) else main_prompt
|
||||
else:
|
||||
prompt = line if console.push(line) else f"{line}\n{main_prompt}"
|
||||
except SystemExit:
|
||||
break
|
||||
self.msg("|gClosing the Python console.|n")
|
||||
return
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue