##// END OF EJS Templates
Fixes tests by using in_normal colors for input.
Tayfun Sen -
Show More
@@ -55,17 +55,17 b' class LazyEvaluate(object):'
55 self.func = func
55 self.func = func
56 self.args = args
56 self.args = args
57 self.kwargs = kwargs
57 self.kwargs = kwargs
58
58
59 def __call__(self, **kwargs):
59 def __call__(self, **kwargs):
60 self.kwargs.update(kwargs)
60 self.kwargs.update(kwargs)
61 return self.func(*self.args, **self.kwargs)
61 return self.func(*self.args, **self.kwargs)
62
62
63 def __str__(self):
63 def __str__(self):
64 return str(self())
64 return str(self())
65
65
66 def __unicode__(self):
66 def __unicode__(self):
67 return py3compat.unicode_type(self())
67 return py3compat.unicode_type(self())
68
68
69 def __format__(self, format_spec):
69 def __format__(self, format_spec):
70 return format(self(), format_spec)
70 return format(self(), format_spec)
71
71
@@ -114,7 +114,7 b' USER = py3compat.str_to_unicode(os.environ.get("USER",\'\'))'
114 HOSTNAME = py3compat.str_to_unicode(socket.gethostname())
114 HOSTNAME = py3compat.str_to_unicode(socket.gethostname())
115 HOSTNAME_SHORT = HOSTNAME.split(".")[0]
115 HOSTNAME_SHORT = HOSTNAME.split(".")[0]
116
116
117 # IronPython doesn't currently have os.getuid() even if
117 # IronPython doesn't currently have os.getuid() even if
118 # os.name == 'posix'; 2/8/2014
118 # os.name == 'posix'; 2/8/2014
119 ROOT_SYMBOL = "#" if (os.name=='nt' or sys.platform=='cli' or os.getuid()==0) else "$"
119 ROOT_SYMBOL = "#" if (os.name=='nt' or sys.platform=='cli' or os.getuid()==0) else "$"
120
120
@@ -254,7 +254,7 b' class UserNSFormatter(Formatter):'
254 class PromptManager(Configurable):
254 class PromptManager(Configurable):
255 """This is the primary interface for producing IPython's prompts."""
255 """This is the primary interface for producing IPython's prompts."""
256 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', allow_none=True)
256 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', allow_none=True)
257
257
258 color_scheme_table = Instance(coloransi.ColorSchemeTable, allow_none=True)
258 color_scheme_table = Instance(coloransi.ColorSchemeTable, allow_none=True)
259 color_scheme = Unicode('Linux', config=True)
259 color_scheme = Unicode('Linux', config=True)
260 def _color_scheme_changed(self, name, new_value):
260 def _color_scheme_changed(self, name, new_value):
@@ -262,7 +262,7 b' class PromptManager(Configurable):'
262 for pname in ['in', 'in2', 'out', 'rewrite']:
262 for pname in ['in', 'in2', 'out', 'rewrite']:
263 # We need to recalculate the number of invisible characters
263 # We need to recalculate the number of invisible characters
264 self.update_prompt(pname)
264 self.update_prompt(pname)
265
265
266 lazy_evaluate_fields = Dict(help="""
266 lazy_evaluate_fields = Dict(help="""
267 This maps field names used in the prompt templates to functions which
267 This maps field names used in the prompt templates to functions which
268 will be called when the prompt is rendered. This allows us to include
268 will be called when the prompt is rendered. This allows us to include
@@ -270,39 +270,39 b' class PromptManager(Configurable):'
270 if they are used in the prompt.
270 if they are used in the prompt.
271 """)
271 """)
272 def _lazy_evaluate_fields_default(self): return lazily_evaluate.copy()
272 def _lazy_evaluate_fields_default(self): return lazily_evaluate.copy()
273
273
274 in_template = Unicode('In [\\#]: ', config=True,
274 in_template = Unicode('In [\\#]: ', config=True,
275 help="Input prompt. '\\#' will be transformed to the prompt number")
275 help="Input prompt. '\\#' will be transformed to the prompt number")
276 in2_template = Unicode(' .\\D.: ', config=True,
276 in2_template = Unicode(' .\\D.: ', config=True,
277 help="Continuation prompt.")
277 help="Continuation prompt.")
278 out_template = Unicode('Out[\\#]: ', config=True,
278 out_template = Unicode('Out[\\#]: ', config=True,
279 help="Output prompt. '\\#' will be transformed to the prompt number")
279 help="Output prompt. '\\#' will be transformed to the prompt number")
280
280
281 justify = Bool(True, config=True, help="""
281 justify = Bool(True, config=True, help="""
282 If True (default), each prompt will be right-aligned with the
282 If True (default), each prompt will be right-aligned with the
283 preceding one.
283 preceding one.
284 """)
284 """)
285
285
286 # We actually store the expanded templates here:
286 # We actually store the expanded templates here:
287 templates = Dict()
287 templates = Dict()
288
288
289 # The number of characters in the last prompt rendered, not including
289 # The number of characters in the last prompt rendered, not including
290 # colour characters.
290 # colour characters.
291 width = Int()
291 width = Int()
292 txtwidth = Int() # Not including right-justification
292 txtwidth = Int() # Not including right-justification
293
293
294 # The number of characters in each prompt which don't contribute to width
294 # The number of characters in each prompt which don't contribute to width
295 invisible_chars = Dict()
295 invisible_chars = Dict()
296 def _invisible_chars_default(self):
296 def _invisible_chars_default(self):
297 return {'in': 0, 'in2': 0, 'out': 0, 'rewrite':0}
297 return {'in': 0, 'in2': 0, 'out': 0, 'rewrite':0}
298
298
299 def __init__(self, shell, **kwargs):
299 def __init__(self, shell, **kwargs):
300 super(PromptManager, self).__init__(shell=shell, **kwargs)
300 super(PromptManager, self).__init__(shell=shell, **kwargs)
301
301
302 # Prepare colour scheme table
302 # Prepare colour scheme table
303 self.color_scheme_table = coloransi.ColorSchemeTable([NoColor,
303 self.color_scheme_table = coloransi.ColorSchemeTable([NoColor,
304 LinuxColors, LightBGColors], self.color_scheme)
304 LinuxColors, LightBGColors], self.color_scheme)
305
305
306 self._formatter = UserNSFormatter(shell)
306 self._formatter = UserNSFormatter(shell)
307 # Prepare templates & numbers of invisible characters
307 # Prepare templates & numbers of invisible characters
308 self.update_prompt('in', self.in_template)
308 self.update_prompt('in', self.in_template)
@@ -311,13 +311,13 b' class PromptManager(Configurable):'
311 self.update_prompt('rewrite')
311 self.update_prompt('rewrite')
312 self.on_trait_change(self._update_prompt_trait, ['in_template',
312 self.on_trait_change(self._update_prompt_trait, ['in_template',
313 'in2_template', 'out_template'])
313 'in2_template', 'out_template'])
314
314
315 def update_prompt(self, name, new_template=None):
315 def update_prompt(self, name, new_template=None):
316 """This is called when a prompt template is updated. It processes
316 """This is called when a prompt template is updated. It processes
317 abbreviations used in the prompt template (like \#) and calculates how
317 abbreviations used in the prompt template (like \#) and calculates how
318 many invisible characters (ANSI colour escapes) the resulting prompt
318 many invisible characters (ANSI colour escapes) the resulting prompt
319 contains.
319 contains.
320
320
321 It is also called for each prompt on changing the colour scheme. In both
321 It is also called for each prompt on changing the colour scheme. In both
322 cases, traitlets should take care of calling this automatically.
322 cases, traitlets should take care of calling this automatically.
323 """
323 """
@@ -327,17 +327,17 b' class PromptManager(Configurable):'
327 # prompt, to calculate the width for lining up subsequent prompts.
327 # prompt, to calculate the width for lining up subsequent prompts.
328 invis_chars = _invisible_characters(self._render(name, color=True))
328 invis_chars = _invisible_characters(self._render(name, color=True))
329 self.invisible_chars[name] = invis_chars
329 self.invisible_chars[name] = invis_chars
330
330
331 def _update_prompt_trait(self, traitname, new_template):
331 def _update_prompt_trait(self, traitname, new_template):
332 name = traitname[:-9] # Cut off '_template'
332 name = traitname[:-9] # Cut off '_template'
333 self.update_prompt(name, new_template)
333 self.update_prompt(name, new_template)
334
334
335 def _render(self, name, color=True, **kwargs):
335 def _render(self, name, color=True, **kwargs):
336 """Render but don't justify, or update the width or txtwidth attributes.
336 """Render but don't justify, or update the width or txtwidth attributes.
337 """
337 """
338 if name == 'rewrite':
338 if name == 'rewrite':
339 return self._render_rewrite(color=color)
339 return self._render_rewrite(color=color)
340
340
341 if color:
341 if color:
342 scheme = self.color_scheme_table.active_colors
342 scheme = self.color_scheme_table.active_colors
343 if name=='out':
343 if name=='out':
@@ -347,14 +347,14 b' class PromptManager(Configurable):'
347 else:
347 else:
348 colors = color_lists['inp']
348 colors = color_lists['inp']
349 colors.number, colors.prompt, colors.normal = \
349 colors.number, colors.prompt, colors.normal = \
350 scheme.in_number, scheme.in_prompt, scheme.normal
350 scheme.in_number, scheme.in_prompt, scheme.in_normal
351 if name=='in2':
351 if name=='in2':
352 colors.prompt = scheme.in_prompt2
352 colors.prompt = scheme.in_prompt2
353 else:
353 else:
354 # No color
354 # No color
355 colors = color_lists['nocolor']
355 colors = color_lists['nocolor']
356 colors.number, colors.prompt, colors.normal = '', '', ''
356 colors.number, colors.prompt, colors.normal = '', '', ''
357
357
358 count = self.shell.execution_count # Shorthand
358 count = self.shell.execution_count # Shorthand
359 # Build the dictionary to be passed to string formatting
359 # Build the dictionary to be passed to string formatting
360 fmtargs = dict(color=colors, count=count,
360 fmtargs = dict(color=colors, count=count,
@@ -362,13 +362,13 b' class PromptManager(Configurable):'
362 width=self.width, txtwidth=self.txtwidth)
362 width=self.width, txtwidth=self.txtwidth)
363 fmtargs.update(self.lazy_evaluate_fields)
363 fmtargs.update(self.lazy_evaluate_fields)
364 fmtargs.update(kwargs)
364 fmtargs.update(kwargs)
365
365
366 # Prepare the prompt
366 # Prepare the prompt
367 prompt = colors.prompt + self.templates[name] + colors.normal
367 prompt = colors.prompt + self.templates[name] + colors.normal
368
368
369 # Fill in required fields
369 # Fill in required fields
370 return self._formatter.format(prompt, **fmtargs)
370 return self._formatter.format(prompt, **fmtargs)
371
371
372 def _render_rewrite(self, color=True):
372 def _render_rewrite(self, color=True):
373 """Render the ---> rewrite prompt."""
373 """Render the ---> rewrite prompt."""
374 if color:
374 if color:
@@ -380,11 +380,11 b' class PromptManager(Configurable):'
380 color_prompt, color_normal = '', ''
380 color_prompt, color_normal = '', ''
381
381
382 return color_prompt + "-> ".rjust(self.txtwidth, "-") + color_normal
382 return color_prompt + "-> ".rjust(self.txtwidth, "-") + color_normal
383
383
384 def render(self, name, color=True, just=None, **kwargs):
384 def render(self, name, color=True, just=None, **kwargs):
385 """
385 """
386 Render the selected prompt.
386 Render the selected prompt.
387
387
388 Parameters
388 Parameters
389 ----------
389 ----------
390 name : str
390 name : str
@@ -398,13 +398,13 b' class PromptManager(Configurable):'
398 Additional arguments will be passed to the string formatting operation,
398 Additional arguments will be passed to the string formatting operation,
399 so they can override the values that would otherwise fill in the
399 so they can override the values that would otherwise fill in the
400 template.
400 template.
401
401
402 Returns
402 Returns
403 -------
403 -------
404 A string containing the rendered prompt.
404 A string containing the rendered prompt.
405 """
405 """
406 res = self._render(name, color=color, **kwargs)
406 res = self._render(name, color=color, **kwargs)
407
407
408 # Handle justification of prompt
408 # Handle justification of prompt
409 invis_chars = self.invisible_chars[name] if color else 0
409 invis_chars = self.invisible_chars[name] if color else 0
410 self.txtwidth = _lenlastline(res) - invis_chars
410 self.txtwidth = _lenlastline(res) - invis_chars
General Comments 0
You need to be logged in to leave comments. Login now