Skip to content

Commit

Permalink
Renamed from Banner to Proem
Browse files Browse the repository at this point in the history
  • Loading branch information
engmtcdrm committed Apr 14, 2024
1 parent f2df661 commit 22faebe
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions src/banner.py → src/proem.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

just_fix_windows_console()

class Banner:
class Proem:
"""
A class to create a banner for a command line application.
:app_nm: The name of the application.
:flavor_text: (optional) A short description of the application.
:version: (optional) The version of the application.
:repo_url: (optional) The URL to the repository for the application.
:width: (optional) The width of the banner.
:border_char: (optional) The character used to create the border.
:border_color: (optional) The color of the border.
:description: (optional) A long description of the application.
:width: (optional) The width of the banner. (default is ``80``)
:border_char: (optional) The character used to create the border. (default is ``#``)
:border_color: (optional) The color of the border. (default is ``magenta``)
:description: (optional) A long description of the application. (default is ``None``)
"""

def __init__(
Expand All @@ -38,8 +38,6 @@ def __init__(
self.border_color = border_color
self.description = description

self.empty_width = width - 2

def _str_to_color(self) -> str:
color_name = self.border_color.lower()

Expand All @@ -63,7 +61,7 @@ def _border_line(self):
return self._str_to_color() + self.border_char * self.width + Fore.RESET + '\n'

def _empty_line(self):
return self._border_char() + ' ' * self.empty_width + self.border_char + Fore.RESET + '\n'
return self._border_char() + ' ' * self._empty_width + self._border_char() + Fore.RESET + '\n'

def _side_widths(self, text: str):
text_len = len(text)
Expand Down Expand Up @@ -124,6 +122,23 @@ def _text_line(self, text: str, align: str = 'center'):

return text_line

def _find_max_width(self) -> int:
"""
Find the maximum width of the banner.
"""
max_width = len(self.app_nm)

if self.flavor_text:
max_width = max(max_width, len(self.flavor_text))

if self.repo_url:
max_width = max(max_width, len(self.repo_url))

if self.version:
max_width = max(max_width, len('version ' + self.version))

return max_width

@property
def width(self) -> int:
"""
Expand All @@ -134,7 +149,7 @@ def width(self) -> int:
@width.setter
def width(self, width: int):
self._width = width
self.empty_width = width - 2
self._empty_width = width - 2

def build(self) -> str:
"""
Expand Down

0 comments on commit 22faebe

Please sign in to comment.