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