From 4f4b7c80f36a44b5a3d430f8442b45df91dea7e4 Mon Sep 17 00:00:00 2001 From: Andrew Hamilton Date: Mon, 18 Apr 2022 00:23:23 +1000 Subject: [PATCH] termstr: Make center method match str's center. - Fixes wiggling titles in fill3 borders. --- eris/tests/golden-files/initial | 2 +- eris/tests/golden-files/log-original | 2 +- eris/tests/golden-files/window-orientation | 2 +- eris/tests/golden-files/window-orientation-original | 2 +- termstr/termstr.py | 4 +--- 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/eris/tests/golden-files/initial b/eris/tests/golden-files/initial index 6695766..925362a 100644 --- a/eris/tests/golden-files/initial +++ b/eris/tests/golden-files/initial @@ -42,7 +42,7 @@ ┃ ┃│ │ ┃ ┃│ │ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛│ │ -┌─────────────── Log ────────────────┐│ │ +┌──────────────── Log ───────────────┐│ │ │ ││ │ │ ││ │ │ ││ │ diff --git a/eris/tests/golden-files/log-original b/eris/tests/golden-files/log-original index 6695766..925362a 100644 --- a/eris/tests/golden-files/log-original +++ b/eris/tests/golden-files/log-original @@ -42,7 +42,7 @@ ┃ ┃│ │ ┃ ┃│ │ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛│ │ -┌─────────────── Log ────────────────┐│ │ +┌──────────────── Log ───────────────┐│ │ │ ││ │ │ ││ │ │ ││ │ diff --git a/eris/tests/golden-files/window-orientation b/eris/tests/golden-files/window-orientation index 4a1633b..72f3e41 100644 --- a/eris/tests/golden-files/window-orientation +++ b/eris/tests/golden-files/window-orientation @@ -1,4 +1,4 @@ -┏━━━━━━━━━━━━━━ Summary of project ━━━━━━━━━━━━━━┓┌───────────────────── Log ──────────────────────┐ +┏━━━━━━━━━━━━━━ Summary of project ━━━━━━━━━━━━━━┓┌────────────────────── Log ─────────────────────┐ ┃ ┃│ │ ┃ ┃│ │ ┃ ┃│ │ diff --git a/eris/tests/golden-files/window-orientation-original b/eris/tests/golden-files/window-orientation-original index 6695766..925362a 100644 --- a/eris/tests/golden-files/window-orientation-original +++ b/eris/tests/golden-files/window-orientation-original @@ -42,7 +42,7 @@ ┃ ┃│ │ ┃ ┃│ │ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛│ │ -┌─────────────── Log ────────────────┐│ │ +┌──────────────── Log ───────────────┐│ │ │ ││ │ │ ││ │ │ ││ │ diff --git a/termstr/termstr.py b/termstr/termstr.py index bc62f1f..5d45b66 100644 --- a/termstr/termstr.py +++ b/termstr/termstr.py @@ -349,9 +349,7 @@ class TermStr(collections.UserString): return self.__class__(fillchar * (width - len(self.data))) + self def center(self, width, fillchar=" "): - left_width = (width - len(self.data)) // 2 - if left_width < 1: - return self + left_width = round((width - len(self.data)) / 2) return (self.__class__(fillchar * left_width) + self + self.__class__(fillchar * (width - left_width - len(self.data))))