##// END OF EJS Templates
Make rewrite prompt non-configurable.
Thomas Kluyver -
Show More
@@ -346,6 +346,10 b' class InteractiveShell(SingletonConfigurable, Magic):'
346 _prompt_out_changed = _prompt_trait_changed
346 _prompt_out_changed = _prompt_trait_changed
347 _prompt_pad_left_changed = _prompt_trait_changed
347 _prompt_pad_left_changed = _prompt_trait_changed
348
348
349 show_rewritten_input = CBool(True, config=True,
350 help="Show rewritten input, e.g. for autocall."
351 )
352
349 quiet = CBool(False, config=True)
353 quiet = CBool(False, config=True)
350
354
351 history_length = Integer(10000, config=True)
355 history_length = Integer(10000, config=True)
@@ -2168,6 +2172,9 b' class InteractiveShell(SingletonConfigurable, Magic):'
2168 after the user's input prompt. This helps the user understand that the
2172 after the user's input prompt. This helps the user understand that the
2169 input line was transformed automatically by IPython.
2173 input line was transformed automatically by IPython.
2170 """
2174 """
2175 if not self.show_rewritten_input:
2176 return
2177
2171 rw = self.prompt_manager.render('rewrite') + cmd
2178 rw = self.prompt_manager.render('rewrite') + cmd
2172
2179
2173 try:
2180 try:
@@ -232,9 +232,6 b' lazily_evaluate = {\'time\': LazyEvaluate(time.strftime, "%H:%M:%S"),'
232 [LazyEvaluate(cwd_filt, x) for x in range(1,6)],
232 [LazyEvaluate(cwd_filt, x) for x in range(1,6)],
233 'cwd_y': [LazyEvaluate(cwd_filt2, x) for x in range(6)]
233 'cwd_y': [LazyEvaluate(cwd_filt2, x) for x in range(6)]
234 }
234 }
235
236 misc_fields = {'rarrow': "-> "
237 }
238
235
239
236
240 class PromptManager(Configurable):
237 class PromptManager(Configurable):
@@ -263,8 +260,6 b' class PromptManager(Configurable):'
263 help="Continuation prompt.")
260 help="Continuation prompt.")
264 out_template = Unicode('Out[\\#]: ', config=True,
261 out_template = Unicode('Out[\\#]: ', config=True,
265 help="Output prompt. '\\#' will be transformed to the prompt number")
262 help="Output prompt. '\\#' will be transformed to the prompt number")
266 rewrite_template = Unicode("{rarrow:->{txtwidth}}", config=True,
267 help="Rewrite prompt. When inputs are transformed, the rewritten input will follow this.")
268
263
269 justify = Bool(True, config=True, help="""
264 justify = Bool(True, config=True, help="""
270 If True (default), each prompt will be right-aligned with the
265 If True (default), each prompt will be right-aligned with the
@@ -282,7 +277,7 b' class PromptManager(Configurable):'
282 # The number of characters in each prompt which don't contribute to width
277 # The number of characters in each prompt which don't contribute to width
283 invisible_chars = Dict()
278 invisible_chars = Dict()
284 def _invisible_chars_default(self):
279 def _invisible_chars_default(self):
285 return {'in': 0, 'in2': 0, 'out': 0, 'rewrite': 0}
280 return {'in': 0, 'in2': 0, 'out': 0, 'rewrite':0}
286
281
287 def __init__(self, shell, config=None):
282 def __init__(self, shell, config=None):
288 super(PromptManager, self).__init__(shell=shell, config=config)
283 super(PromptManager, self).__init__(shell=shell, config=config)
@@ -291,13 +286,13 b' class PromptManager(Configurable):'
291 self.color_scheme_table = coloransi.ColorSchemeTable([PColNoColors,
286 self.color_scheme_table = coloransi.ColorSchemeTable([PColNoColors,
292 PColLinux, PColLightBG], self.color_scheme)
287 PColLinux, PColLightBG], self.color_scheme)
293
288
294 # Prepare templates
289 # Prepare templates & numbers of invisible characters
295 self.update_prompt('in', self.in_template)
290 self.update_prompt('in', self.in_template)
296 self.update_prompt('in2', self.in2_template)
291 self.update_prompt('in2', self.in2_template)
297 self.update_prompt('out', self.out_template)
292 self.update_prompt('out', self.out_template)
298 self.update_prompt('rewrite', self.rewrite_template)
293 self.update_prompt('rewrite')
299 self.on_trait_change(self._update_prompt_trait, ['in_template',
294 self.on_trait_change(self._update_prompt_trait, ['in_template',
300 'in2_template', 'out_template', 'rewrite_template'])
295 'in2_template', 'out_template'])
301
296
302 def update_prompt(self, name, new_template=None):
297 def update_prompt(self, name, new_template=None):
303 """This is called when a prompt template is updated. It processes
298 """This is called when a prompt template is updated. It processes
@@ -321,18 +316,15 b' class PromptManager(Configurable):'
321 def _render(self, name, color=True, **kwargs):
316 def _render(self, name, color=True, **kwargs):
322 """Render but don't justify, or update the width or txtwidth attributes.
317 """Render but don't justify, or update the width or txtwidth attributes.
323 """
318 """
319 if name == 'rewrite':
320 return self._render_rewrite(color=color)
321
324 if color:
322 if color:
325 scheme = self.color_scheme_table.active_colors
323 scheme = self.color_scheme_table.active_colors
326 if name=='out':
324 if name=='out':
327 colors = color_lists['normal']
325 colors = color_lists['normal']
328 colors.number, colors.prompt, colors.normal = \
326 colors.number, colors.prompt, colors.normal = \
329 scheme.out_number, scheme.out_prompt, scheme.normal
327 scheme.out_number, scheme.out_prompt, scheme.normal
330 elif name=='rewrite':
331 colors = color_lists['normal']
332 # We need a non-input version of these escapes
333 colors.number = scheme.in_number.replace("\001","").replace("\002","")
334 colors.prompt = scheme.in_prompt.replace("\001","").replace("\002","")
335 colors.normal = scheme.normal
336 else:
328 else:
337 colors = color_lists['inp']
329 colors = color_lists['inp']
338 colors.number, colors.prompt, colors.normal = \
330 colors.number, colors.prompt, colors.normal = \
@@ -350,7 +342,6 b' class PromptManager(Configurable):'
350 dots="."*len(str(count)),
342 dots="."*len(str(count)),
351 width=self.width, txtwidth=self.txtwidth )
343 width=self.width, txtwidth=self.txtwidth )
352 fmtargs.update(self.lazy_evaluate_fields)
344 fmtargs.update(self.lazy_evaluate_fields)
353 fmtargs.update(misc_fields)
354 fmtargs.update(kwargs)
345 fmtargs.update(kwargs)
355
346
356 # Prepare the prompt
347 # Prepare the prompt
@@ -359,6 +350,18 b' class PromptManager(Configurable):'
359 # Fill in required fields
350 # Fill in required fields
360 return prompt.format(**fmtargs)
351 return prompt.format(**fmtargs)
361
352
353 def _render_rewrite(self, color=True):
354 """Render the ---> rewrite prompt."""
355 if color:
356 scheme = self.color_scheme_table.active_colors
357 # We need a non-input version of these escapes
358 color_prompt = scheme.in_prompt.replace("\001","").replace("\002","")
359 color_normal = scheme.normal
360 else:
361 color_prompt, color_normal = '', ''
362
363 return color_prompt + "-> ".rjust(self.txtwidth, "-") + color_normal
364
362 def render(self, name, color=True, just=None, **kwargs):
365 def render(self, name, color=True, just=None, **kwargs):
363 """
366 """
364 Render the selected prompt.
367 Render the selected prompt.
@@ -391,4 +394,3 b' class PromptManager(Configurable):'
391 res = res.rjust(self.width + invis_chars)
394 res = res.rjust(self.width + invis_chars)
392 self.width = len(res) - invis_chars
395 self.width = len(res) - invis_chars
393 return res
396 return res
394
General Comments 0
You need to be logged in to leave comments. Login now