Fix truncation of border titles.

- Ellipses weren't always standing in for truncations.
This commit is contained in:
Andrew Hamilton 2019-09-01 14:42:37 +10:00
parent a0892616bf
commit 71f8461bc3
2 changed files with 10 additions and 6 deletions

View file

@ -401,14 +401,14 @@ class Border:
if self.title is None: if self.title is None:
title_bar = self.top * content_width title_bar = self.top * content_width
else: else:
title = ("" + self.title[-(content_width-1):] padded_title = " " + ("" + self.title[-(content_width-3):]
if len(self.title) > content_width - 2 if len(self.title) > content_width - 2
else " " + self.title + " ") else self.title) + " "
try: try:
title_bar = title.center(content_width, self.top) title_bar = padded_title.center(content_width, self.top)
except TypeError: except TypeError:
title = termstr.TermStr(title) padded_title = termstr.TermStr(padded_title)
title_bar = title.center(content_width, self.top) title_bar = padded_title.center(content_width, self.top)
result = [self.top_left + title_bar + self.top_right] result = [self.top_left + title_bar + self.top_right]
result.extend(self.left + line + self.right for line in body_content) result.extend(self.left + line + self.right for line in body_content)
result.append(self.bottom_left + self.bottom * content_width + result.append(self.bottom_left + self.bottom * content_width +

View file

@ -64,6 +64,10 @@ class WidgetTests(unittest.TestCase):
"┌─ AB ─┐\n" "┌─ AB ─┐\n"
"│abcdef│\n" "│abcdef│\n"
"└──────┘") "└──────┘")
self.assert_string(fill3.Border(text, title="ABC").appearance((6, 3)),
"┌ …C ┐\n"
"│abcd│\n"
"└────┘")
def test_placeholder_widget(self): def test_placeholder_widget(self):
placeholder = fill3.Placeholder(self.TEXT_A) placeholder = fill3.Placeholder(self.TEXT_A)