Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make rewrite prompt non-configurable.

  • Loading branch information...
commit ff4cb8496a575971f4a0b4a3ea71f18c061f1aa9 1 parent 7a27b8c
Thomas Kluyver authored
Showing with 26 additions and 17 deletions.
  1. +7 −0 IPython/core/interactiveshell.py
  2. +19 −17 IPython/core/prompts.py
7 IPython/core/interactiveshell.py
View
@@ -346,6 +346,10 @@ def _prompt_trait_changed(self, name, old, new):
_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 @@ def auto_rewrite_input(self, cmd):
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:
36 IPython/core/prompts.py
View
@@ -232,9 +232,6 @@ def cwd_filt2(depth):
[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 @@ def _lazy_evaluate_fields_default(self): return lazily_evaluate.copy()
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 @@ def _lazy_evaluate_fields_default(self): return lazily_evaluate.copy()
# 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 @@ def __init__(self, shell, config=None):
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 @@ def _update_prompt_trait(self, traitname, new_template):
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 @@ def _render(self, name, color=True, **kwargs):
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 @@ def _render(self, name, color=True, **kwargs):
# 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 @@ def render(self, name, color=True, just=None, **kwargs):
res = res.rjust(self.width + invis_chars)
self.width = len(res) - invis_chars
return res
-
Please sign in to comment.
Something went wrong with that request. Please try again.