From 49c798c18d45baf197a3db36f85528448d2148f8 2016-05-31 20:33:44 From: Matthias Bussonnier Date: 2016-05-31 20:33:44 Subject: [PATCH] Add flag for simple_prompt. As this mode seem to be useful beyond testing, expose it via a flag and make it official. --- diff --git a/IPython/terminal/ipapp.py b/IPython/terminal/ipapp.py index 02edabe..b39eb52 100755 --- a/IPython/terminal/ipapp.py +++ b/IPython/terminal/ipapp.py @@ -102,6 +102,11 @@ addflag('autoedit-syntax', 'TerminalInteractiveShell.autoedit_syntax', 'Turn on auto editing of files with syntax errors.', 'Turn off auto editing of files with syntax errors.' ) +addflag('simple-prompt', 'TerminalInteractiveShell.simple_prompt', + "Force simple minimal prompt using `raw_input`", + "Use a rich interactive prompt with prompt_toolkit", +) + addflag('banner', 'TerminalIPythonApp.display_banner', "Display a banner upon starting IPython.", "Don't display a banner upon starting IPython." diff --git a/IPython/terminal/ptshell.py b/IPython/terminal/ptshell.py index b229284..d7597c8 100644 --- a/IPython/terminal/ptshell.py +++ b/IPython/terminal/ptshell.py @@ -31,6 +31,7 @@ from .pt_inputhooks import get_inputhook_func from .interactiveshell import get_default_editor, TerminalMagics from .ptutils import IPythonPTCompleter, IPythonPTLexer +_use_simple_prompt = 'IPY_TEST_SIMPLE_PROMPT' in os.environ or not sys.stdin.isatty() class TerminalInteractiveShell(InteractiveShell): colors_force = True @@ -46,6 +47,18 @@ class TerminalInteractiveShell(InteractiveShell): debugger_history = None debugger_cls = TerminalPdb + simple_prompt = Bool(_use_simple_prompt, + help="""Use `raw_input` for the REPL, without completion, multiline input, and prompt colors. + + Useful when controlling IPython as a subprocess, and piping STDIN/OUT/ERR. Known usage are: + IPython own testing machinery, and emacs inferior-shell integration through elpy. + + This mode default to `True` if the `IPY_TEST_SIMPLE_PROMPT` + environment variable is set, or the current terminal is not a tty. + + """ + ).tag(config=True) + autoedit_syntax = Bool(False, help="auto editing of files with syntax errors.", ).tag(config=True) @@ -117,7 +130,7 @@ class TerminalInteractiveShell(InteractiveShell): ] def init_prompt_toolkit_cli(self): - if ('IPY_TEST_SIMPLE_PROMPT' in os.environ) or not sys.stdin.isatty(): + if self.simple_prompt: # Fall back to plain non-interactive output for tests. # This is very limited, and only accepts a single line. def prompt(): diff --git a/docs/source/whatsnew/pr/simple_prompt.rst b/docs/source/whatsnew/pr/simple_prompt.rst new file mode 100644 index 0000000..c9d3ec5 --- /dev/null +++ b/docs/source/whatsnew/pr/simple_prompt.rst @@ -0,0 +1,4 @@ +when using IPython as a subprocess, like for emacs inferior-shell, IPython can +be started with --simple-prompt flag, which will bypass the prompt_toolkit +input layer. In this mode completion, prompt color and many other features are +disabled.