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.
|
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)
|
- Improve performance of `find` and `objects` commands on large data sets (strikaco)
|
||||||
- New `CHANNEL_HANDLER_CLASS` setting allows for replacing the ChannelHandler entirely.
|
- 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)
|
## Evennia 0.9 (2018-2019)
|
||||||
|
|
|
||||||
|
|
@ -285,8 +285,6 @@ class EvenniaPythonConsole(code.InteractiveConsole):
|
||||||
result = None
|
result = None
|
||||||
try:
|
try:
|
||||||
result = super().push(line)
|
result = super().push(line)
|
||||||
except SystemExit:
|
|
||||||
pass
|
|
||||||
finally:
|
finally:
|
||||||
sys.stdout = old_stdout
|
sys.stdout = old_stdout
|
||||||
sys.stderr = old_stderr
|
sys.stderr = old_stderr
|
||||||
|
|
@ -302,6 +300,7 @@ class CmdPy(COMMAND_DEFAULT_CLASS):
|
||||||
py/edit
|
py/edit
|
||||||
py/time <cmd>
|
py/time <cmd>
|
||||||
py/clientraw <cmd>
|
py/clientraw <cmd>
|
||||||
|
py/noecho
|
||||||
|
|
||||||
Switches:
|
Switches:
|
||||||
time - output an approximate execution time for <cmd>
|
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
|
clientraw - turn off all client-specific escaping. Note that this may
|
||||||
lead to different output depending on prototocol (such as angular brackets
|
lead to different output depending on prototocol (such as angular brackets
|
||||||
being parsed as HTML in the webclient but not in telnet clients)
|
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,
|
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
|
accepting multi-line Python code for testing and debugging. Type `exit()` to
|
||||||
|
|
@ -340,7 +341,7 @@ class CmdPy(COMMAND_DEFAULT_CLASS):
|
||||||
|
|
||||||
key = "py"
|
key = "py"
|
||||||
aliases = ["!"]
|
aliases = ["!"]
|
||||||
switch_options = ("time", "edit", "clientraw")
|
switch_options = ("time", "edit", "clientraw", "noecho")
|
||||||
locks = "cmd:perm(py) or perm(Developer)"
|
locks = "cmd:perm(py) or perm(Developer)"
|
||||||
help_category = "System"
|
help_category = "System"
|
||||||
|
|
||||||
|
|
@ -350,6 +351,8 @@ class CmdPy(COMMAND_DEFAULT_CLASS):
|
||||||
caller = self.caller
|
caller = self.caller
|
||||||
pycode = self.args
|
pycode = self.args
|
||||||
|
|
||||||
|
noecho = "noecho" in self.switches
|
||||||
|
|
||||||
if "edit" in self.switches:
|
if "edit" in self.switches:
|
||||||
caller.db._py_measure_time = "time" in self.switches
|
caller.db._py_measure_time = "time" in self.switches
|
||||||
caller.db._py_clientraw = "clientraw" in self.switches
|
caller.db._py_clientraw = "clientraw" in self.switches
|
||||||
|
|
@ -368,15 +371,26 @@ class CmdPy(COMMAND_DEFAULT_CLASS):
|
||||||
# Run in interactive mode
|
# Run in interactive mode
|
||||||
console = EvenniaPythonConsole(self.caller)
|
console = EvenniaPythonConsole(self.caller)
|
||||||
banner = (
|
banner = (
|
||||||
f"|gPython {sys.version} on {sys.platform}\n"
|
"|gEvennia Interactive Python mode{echomode}\n"
|
||||||
"Evennia interactive console mode - type 'exit()' to leave.|n"
|
"Python {version} on {platform}".format(
|
||||||
|
echomode=" (no echoing of prompts)" if noecho else "",
|
||||||
|
version=sys.version,
|
||||||
|
platform=sys.platform,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
self.msg(banner)
|
self.msg(banner)
|
||||||
line = ""
|
line = ""
|
||||||
prompt = ">>>"
|
main_prompt = "|x[py mode - quit() to exit]|n"
|
||||||
|
prompt = main_prompt
|
||||||
while line.lower() not in ("exit", "exit()"):
|
while line.lower() not in ("exit", "exit()"):
|
||||||
line = yield (prompt)
|
try:
|
||||||
prompt = "..." if console.push(line) else ">>>"
|
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")
|
self.msg("|gClosing the Python console.|n")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue