From 43d5950566e5275d3ae541621d6f27676df58c10 Mon Sep 17 00:00:00 2001 From: Tony Osibov Date: Thu, 21 Mar 2024 14:11:09 -0700 Subject: [PATCH] Fix signed width value _format_content bug There is the possibility that the width value evaluates to a negative value which will throw a ValueError: Sign not allowed in string format specifier. Adding a minimum 0 value ensures that only positive values are used during string formatting. Fix less than 1 calculated width bug Using a value less than 1 throws and error so make sure that isn't possible --- consolemenu/menu_component.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/consolemenu/menu_component.py b/consolemenu/menu_component.py index 8b77d8d..75ad2fe 100644 --- a/consolemenu/menu_component.py +++ b/consolemenu/menu_component.py @@ -116,7 +116,7 @@ def calculate_content_width(self): Returns: int: the inner content width in columns. """ - return self.calculate_border_width() - self.padding.left - self.padding.right - 2 + return max(self.calculate_border_width() - self.padding.left - self.padding.right - 2, 1) def generate(self): """ @@ -236,8 +236,8 @@ def _format_content(self, content='', align='left'): return '{lp}{text:{al}{width}}{rp}'.format(lp=' ' * self.padding.left, rp=' ' * self.padding.right, text=content, al=self._alignment_char(align), - width=(self.calculate_border_width() - self.padding.left - - self.padding.right - 2 + invisible_chars)) + width=max(self.calculate_border_width() - self.padding.left - + self.padding.right - 2 + invisible_chars, 0)) class MenuHeader(MenuComponent):