From 4d6a65b673a7056f11937315530e737e97bd26b4 Mon Sep 17 00:00:00 2001 From: Abraham Maxfield Date: Fri, 9 Aug 2019 09:08:12 -0500 Subject: [PATCH 1/3] Add support for ... in middle of line --- prompt_toolkit/layout/menus.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/prompt_toolkit/layout/menus.py b/prompt_toolkit/layout/menus.py index f0d8a0ab1d..47061b35da 100644 --- a/prompt_toolkit/layout/menus.py +++ b/prompt_toolkit/layout/menus.py @@ -223,17 +223,23 @@ def _trim_formatted_text( if width > max_width: result = [] # Text fragments. remaining_width = max_width - 3 + current_width = 0 for style_and_ch in explode_text_fragments(formatted_text): ch_width = get_cwidth(style_and_ch[1]) + # Add '...' somewhere in the middle of the text + if current_width == max_width - 6: + result.append(('', '...')) + if ch_width <= remaining_width: result.append(style_and_ch) remaining_width -= ch_width + current_width += ch_width else: break - result.append(('', '...')) + # result.append(('', '...')) return result, max_width - remaining_width else: From 9d043d38ade6a2f3f08434496c155639de6773c1 Mon Sep 17 00:00:00 2001 From: Abraham Maxfield Date: Mon, 12 Aug 2019 15:14:00 -0500 Subject: [PATCH 2/3] Add ellipsis at start of trimmed formated text --- prompt_toolkit/layout/menus.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/prompt_toolkit/layout/menus.py b/prompt_toolkit/layout/menus.py index 47061b35da..29cb907c89 100644 --- a/prompt_toolkit/layout/menus.py +++ b/prompt_toolkit/layout/menus.py @@ -218,20 +218,15 @@ def _trim_formatted_text( Returns (text, width) tuple. """ width = fragment_list_width(formatted_text) - # When the text is too wide, trim it. if width > max_width: result = [] # Text fragments. remaining_width = max_width - 3 current_width = 0 - for style_and_ch in explode_text_fragments(formatted_text): + for style_and_ch in explode_text_fragments(formatted_text)[::-1]: ch_width = get_cwidth(style_and_ch[1]) - # Add '...' somewhere in the middle of the text - if current_width == max_width - 6: - result.append(('', '...')) - if ch_width <= remaining_width: result.append(style_and_ch) remaining_width -= ch_width @@ -239,9 +234,9 @@ def _trim_formatted_text( else: break - # result.append(('', '...')) + result.append(('', '...')) - return result, max_width - remaining_width + return result[::-1], max_width - remaining_width else: return formatted_text, width From ebad043b6cf0422a047ea256821cac3389050ff7 Mon Sep 17 00:00:00 2001 From: Abraham Maxfield Date: Mon, 12 Aug 2019 15:18:04 -0500 Subject: [PATCH 3/3] Remove superfluous change --- prompt_toolkit/layout/menus.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/prompt_toolkit/layout/menus.py b/prompt_toolkit/layout/menus.py index 29cb907c89..164df530a5 100644 --- a/prompt_toolkit/layout/menus.py +++ b/prompt_toolkit/layout/menus.py @@ -218,11 +218,11 @@ def _trim_formatted_text( Returns (text, width) tuple. """ width = fragment_list_width(formatted_text) + # When the text is too wide, trim it. if width > max_width: result = [] # Text fragments. remaining_width = max_width - 3 - current_width = 0 for style_and_ch in explode_text_fragments(formatted_text)[::-1]: ch_width = get_cwidth(style_and_ch[1]) @@ -230,7 +230,6 @@ def _trim_formatted_text( if ch_width <= remaining_width: result.append(style_and_ch) remaining_width -= ch_width - current_width += ch_width else: break