##// END OF EJS Templates
Fix for prompts containing newlines....
Thomas Kluyver -
Show More
@@ -232,7 +232,14 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
235
236 def _lenlastline(s):
237 """Get the length of the last line. More intelligent than
238 len(s.splitlines()[-1]).
239 """
240 if not s or s.endswith(('\n', '\r')):
241 return 0
242 return len(s.splitlines()[-1])
236
243
237 class PromptManager(Configurable):
244 class PromptManager(Configurable):
238 """This is the primary interface for producing IPython's prompts."""
245 """This is the primary interface for producing IPython's prompts."""
@@ -305,8 +312,10 b' class PromptManager(Configurable):'
305 """
312 """
306 if new_template is not None:
313 if new_template is not None:
307 self.templates[name] = multiple_replace(prompt_abbreviations, new_template)
314 self.templates[name] = multiple_replace(prompt_abbreviations, new_template)
308 invis_chars = len(self._render(name, color=True)) - \
315 # We count invisible characters (colour escapes) on the last line of the
309 len(self._render(name, color=False))
316 # prompt, to calculate the width for lining up subsequent prompts.
317 invis_chars = _lenlastline(self._render(name, color=True)) - \
318 _lenlastline(self._render(name, color=False))
310 self.invisible_chars[name] = invis_chars
319 self.invisible_chars[name] = invis_chars
311
320
312 def _update_prompt_trait(self, traitname, new_template):
321 def _update_prompt_trait(self, traitname, new_template):
@@ -388,9 +397,10 b' class PromptManager(Configurable):'
388
397
389 # Handle justification of prompt
398 # Handle justification of prompt
390 invis_chars = self.invisible_chars[name] if color else 0
399 invis_chars = self.invisible_chars[name] if color else 0
391 self.txtwidth = len(res) - invis_chars
400 self.txtwidth = _lenlastline(res) - invis_chars
392 just = self.justify if (just is None) else just
401 just = self.justify if (just is None) else just
393 if just:
402 # If the prompt spans more than one line, don't try to justify it:
403 if just and ('\n' not in res) and ('\r' not in res):
394 res = res.rjust(self.width + invis_chars)
404 res = res.rjust(self.width + invis_chars)
395 self.width = len(res) - invis_chars
405 self.width = _lenlastline(res) - invis_chars
396 return res
406 return res
General Comments 0
You need to be logged in to leave comments. Login now