diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 4660cbf..edf52e0 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -346,6 +346,10 @@ class InteractiveShell(SingletonConfigurable, Magic): _prompt_out_changed = _prompt_trait_changed _prompt_pad_left_changed = _prompt_trait_changed + show_rewritten_input = CBool(True, config=True, + help="Show rewritten input, e.g. for autocall." + ) + quiet = CBool(False, config=True) history_length = Integer(10000, config=True) @@ -2168,6 +2172,9 @@ class InteractiveShell(SingletonConfigurable, Magic): after the user's input prompt. This helps the user understand that the input line was transformed automatically by IPython. """ + if not self.show_rewritten_input: + return + rw = self.prompt_manager.render('rewrite') + cmd try: diff --git a/IPython/core/prompts.py b/IPython/core/prompts.py index df51e70..4413ddf 100644 --- a/IPython/core/prompts.py +++ b/IPython/core/prompts.py @@ -232,9 +232,6 @@ lazily_evaluate = {'time': LazyEvaluate(time.strftime, "%H:%M:%S"), [LazyEvaluate(cwd_filt, x) for x in range(1,6)], 'cwd_y': [LazyEvaluate(cwd_filt2, x) for x in range(6)] } - -misc_fields = {'rarrow': "-> " - } class PromptManager(Configurable): @@ -263,8 +260,6 @@ class PromptManager(Configurable): help="Continuation prompt.") out_template = Unicode('Out[\\#]: ', config=True, help="Output prompt. '\\#' will be transformed to the prompt number") - rewrite_template = Unicode("{rarrow:->{txtwidth}}", config=True, - help="Rewrite prompt. When inputs are transformed, the rewritten input will follow this.") justify = Bool(True, config=True, help=""" If True (default), each prompt will be right-aligned with the @@ -282,7 +277,7 @@ class PromptManager(Configurable): # The number of characters in each prompt which don't contribute to width invisible_chars = Dict() def _invisible_chars_default(self): - return {'in': 0, 'in2': 0, 'out': 0, 'rewrite': 0} + return {'in': 0, 'in2': 0, 'out': 0, 'rewrite':0} def __init__(self, shell, config=None): super(PromptManager, self).__init__(shell=shell, config=config) @@ -291,13 +286,13 @@ class PromptManager(Configurable): self.color_scheme_table = coloransi.ColorSchemeTable([PColNoColors, PColLinux, PColLightBG], self.color_scheme) - # Prepare templates + # Prepare templates & numbers of invisible characters self.update_prompt('in', self.in_template) self.update_prompt('in2', self.in2_template) self.update_prompt('out', self.out_template) - self.update_prompt('rewrite', self.rewrite_template) + self.update_prompt('rewrite') self.on_trait_change(self._update_prompt_trait, ['in_template', - 'in2_template', 'out_template', 'rewrite_template']) + 'in2_template', 'out_template']) def update_prompt(self, name, new_template=None): """This is called when a prompt template is updated. It processes @@ -321,18 +316,15 @@ class PromptManager(Configurable): def _render(self, name, color=True, **kwargs): """Render but don't justify, or update the width or txtwidth attributes. """ + if name == 'rewrite': + return self._render_rewrite(color=color) + if color: scheme = self.color_scheme_table.active_colors if name=='out': colors = color_lists['normal'] colors.number, colors.prompt, colors.normal = \ scheme.out_number, scheme.out_prompt, scheme.normal - elif name=='rewrite': - colors = color_lists['normal'] - # We need a non-input version of these escapes - colors.number = scheme.in_number.replace("\001","").replace("\002","") - colors.prompt = scheme.in_prompt.replace("\001","").replace("\002","") - colors.normal = scheme.normal else: colors = color_lists['inp'] colors.number, colors.prompt, colors.normal = \ @@ -350,7 +342,6 @@ class PromptManager(Configurable): dots="."*len(str(count)), width=self.width, txtwidth=self.txtwidth ) fmtargs.update(self.lazy_evaluate_fields) - fmtargs.update(misc_fields) fmtargs.update(kwargs) # Prepare the prompt @@ -359,6 +350,18 @@ class PromptManager(Configurable): # Fill in required fields return prompt.format(**fmtargs) + def _render_rewrite(self, color=True): + """Render the ---> rewrite prompt.""" + if color: + scheme = self.color_scheme_table.active_colors + # We need a non-input version of these escapes + color_prompt = scheme.in_prompt.replace("\001","").replace("\002","") + color_normal = scheme.normal + else: + color_prompt, color_normal = '', '' + + return color_prompt + "-> ".rjust(self.txtwidth, "-") + color_normal + def render(self, name, color=True, just=None, **kwargs): """ Render the selected prompt. @@ -391,4 +394,3 @@ class PromptManager(Configurable): res = res.rjust(self.width + invis_chars) self.width = len(res) - invis_chars return res -