forked from orbit-oss/flask
shell calls sys.__interativehook__
This will set up readline tab and history completion by default.
This commit is contained in:
parent
64213fc021
commit
32272da9ac
2 changed files with 20 additions and 0 deletions
|
|
@ -70,6 +70,8 @@ Unreleased
|
|||
- Support async views, error handlers, before and after request, and
|
||||
teardown functions. :pr:`3412`
|
||||
- Support nesting blueprints. :issue:`593, 1548`, :pr:`3923`
|
||||
- ``flask shell`` sets up tab and history completion like the default
|
||||
``python`` shell if ``readline`` is installed. :issue:`3941`
|
||||
|
||||
|
||||
Version 1.1.2
|
||||
|
|
|
|||
|
|
@ -887,6 +887,24 @@ def shell_command():
|
|||
|
||||
ctx.update(app.make_shell_context())
|
||||
|
||||
# Site, customize, or startup script can set a hook to call when
|
||||
# entering interactive mode. The default one sets up readline with
|
||||
# tab and history completion.
|
||||
interactive_hook = getattr(sys, "__interactivehook__", None)
|
||||
|
||||
if interactive_hook is not None:
|
||||
try:
|
||||
import readline
|
||||
from rlcompleter import Completer
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
# rlcompleter uses __main__.__dict__ by default, which is
|
||||
# flask.__main__. Use the shell context instead.
|
||||
readline.set_completer(Completer(ctx).complete)
|
||||
|
||||
interactive_hook()
|
||||
|
||||
code.interact(banner=banner, local=ctx)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue