diff --git a/IPython/terminal/ptutils.py b/IPython/terminal/ptutils.py index f736752..bc22f8e 100644 --- a/IPython/terminal/ptutils.py +++ b/IPython/terminal/ptutils.py @@ -19,12 +19,16 @@ from prompt_toolkit.lexers import PygmentsLexer from prompt_toolkit.patch_stdout import patch_stdout import pygments.lexers as pygments_lexers +import os _completion_sentinel = object() def _elide(string, *, min_elide=30): """ - If a string is long enough, and has at least 2 dots, + If a string is long enough, and has at least 3 dots, + replace the middle part with ellipses. + + If a string naming a file is long enough, and has at least 3 slashes, replace the middle part with ellipses. If three consecutive dots, or two consecutive dots are encountered these are @@ -36,12 +40,16 @@ def _elide(string, *, min_elide=30): if len(string) < min_elide: return string - parts = string.split('.') + object_parts = string.split('.') + file_parts = string.split(os.sep) - if len(parts) <= 3: - return string + if len(object_parts) > 3: + return '{}.{}\N{HORIZONTAL ELLIPSIS}{}.{}'.format(object_parts[0], object_parts[1][0], object_parts[-2][-1], object_parts[-1]) + + elif len(file_parts) > 3: + return ('{}' + os.sep + '{}\N{HORIZONTAL ELLIPSIS}{}' + os.sep + '{}').format(file_parts[0], file_parts[1][0], file_parts[-2][-1], file_parts[-1]) - return '{}.{}\N{HORIZONTAL ELLIPSIS}{}.{}'.format(parts[0], parts[1][0], parts[-2][-1], parts[-1]) + return string def _adjust_completion_text_based_on_context(text, body, offset):