##// END OF EJS Templates
Make rewrite prompt non-configurable.
Thomas Kluyver -
Show More
@@ -346,6 +346,10 class InteractiveShell(SingletonConfigurable, Magic):
346 346 _prompt_out_changed = _prompt_trait_changed
347 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 353 quiet = CBool(False, config=True)
350 354
351 355 history_length = Integer(10000, config=True)
@@ -2168,6 +2172,9 class InteractiveShell(SingletonConfigurable, Magic):
2168 2172 after the user's input prompt. This helps the user understand that the
2169 2173 input line was transformed automatically by IPython.
2170 2174 """
2175 if not self.show_rewritten_input:
2176 return
2177
2171 2178 rw = self.prompt_manager.render('rewrite') + cmd
2172 2179
2173 2180 try:
@@ -232,9 +232,6 lazily_evaluate = {'time': LazyEvaluate(time.strftime, "%H:%M:%S"),
232 232 [LazyEvaluate(cwd_filt, x) for x in range(1,6)],
233 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 237 class PromptManager(Configurable):
@@ -263,8 +260,6 class PromptManager(Configurable):
263 260 help="Continuation prompt.")
264 261 out_template = Unicode('Out[\\#]: ', config=True,
265 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 264 justify = Bool(True, config=True, help="""
270 265 If True (default), each prompt will be right-aligned with the
@@ -282,7 +277,7 class PromptManager(Configurable):
282 277 # The number of characters in each prompt which don't contribute to width
283 278 invisible_chars = Dict()
284 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 282 def __init__(self, shell, config=None):
288 283 super(PromptManager, self).__init__(shell=shell, config=config)
@@ -291,13 +286,13 class PromptManager(Configurable):
291 286 self.color_scheme_table = coloransi.ColorSchemeTable([PColNoColors,
292 287 PColLinux, PColLightBG], self.color_scheme)
293 288
294 # Prepare templates
289 # Prepare templates & numbers of invisible characters
295 290 self.update_prompt('in', self.in_template)
296 291 self.update_prompt('in2', self.in2_template)
297 292 self.update_prompt('out', self.out_template)
298 self.update_prompt('rewrite', self.rewrite_template)
293 self.update_prompt('rewrite')
299 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 297 def update_prompt(self, name, new_template=None):
303 298 """This is called when a prompt template is updated. It processes
@@ -321,18 +316,15 class PromptManager(Configurable):
321 316 def _render(self, name, color=True, **kwargs):
322 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 322 if color:
325 323 scheme = self.color_scheme_table.active_colors
326 324 if name=='out':
327 325 colors = color_lists['normal']
328 326 colors.number, colors.prompt, colors.normal = \
329 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 328 else:
337 329 colors = color_lists['inp']
338 330 colors.number, colors.prompt, colors.normal = \
@@ -350,7 +342,6 class PromptManager(Configurable):
350 342 dots="."*len(str(count)),
351 343 width=self.width, txtwidth=self.txtwidth )
352 344 fmtargs.update(self.lazy_evaluate_fields)
353 fmtargs.update(misc_fields)
354 345 fmtargs.update(kwargs)
355 346
356 347 # Prepare the prompt
@@ -359,6 +350,18 class PromptManager(Configurable):
359 350 # Fill in required fields
360 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 365 def render(self, name, color=True, just=None, **kwargs):
363 366 """
364 367 Render the selected prompt.
@@ -391,4 +394,3 class PromptManager(Configurable):
391 394 res = res.rjust(self.width + invis_chars)
392 395 self.width = len(res) - invis_chars
393 396 return res
394
General Comments 0
You need to be logged in to leave comments. Login now