simple-terminal-banner 0.0.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ from .banner import Banner, BannerThemes
@@ -0,0 +1,209 @@
1
+ from enum import Enum
2
+ import logging
3
+ import textwrap
4
+
5
+
6
+ class BannerThemes(Enum):
7
+ DEFAULT = 'default'
8
+ SIMPLE = 'simple'
9
+ HASH = 'hash'
10
+ STAR = 'star'
11
+ SPACE = 'space'
12
+ NONE = 'none'
13
+
14
+
15
+ # create a simple class to create a banner
16
+ class Banner:
17
+ def __init__(self, message=None):
18
+
19
+ self.title = None
20
+ self.title_padding = 1
21
+ self.title_margin = 1
22
+ self.width = 40
23
+ self.wrap = True
24
+ self.padding_top = 1
25
+ self.padding_bottom = 1
26
+ self.padding_left = 1
27
+ self.padding_right = 1
28
+ self.margin_top = 0
29
+ self.margin_bottom = 1
30
+ self.margin_left = 0
31
+ self.margin_right = 0
32
+ self.border_symbol = "*"
33
+ self.background_symbol = " "
34
+ self.padding_symbol = " "
35
+
36
+ self._rows = []
37
+ self._border_width = 1
38
+
39
+ if message:
40
+ self.add_row(message)
41
+ self.message = message
42
+
43
+ def display(self):
44
+ if self.margin_top > 0: print(self._create_margin_top())
45
+ print(self._title())
46
+ print(self._create_padding_top())
47
+ if self._rows:
48
+ for row in self._rows:
49
+ print(row)
50
+ else:
51
+ print(self._line(self.message))
52
+ print(self._create_padding_bottom())
53
+ print(self._separator())
54
+ if self.margin_bottom > 0: print(self._create_margin_bottom())
55
+
56
+ def add_row(self, content=None, type=None):
57
+ if type in ['blank', 'empty', 'line']:
58
+ self._rows.append(self._blank_line())
59
+ elif type in ['separator', 'divider']:
60
+ self._rows.append(self._create_padding_top())
61
+ self._rows.append(self._separator())
62
+ self._rows.append(self._create_padding_bottom())
63
+ else:
64
+ # content = self._check_content_length(content)
65
+ self._line(content)
66
+
67
+ return
68
+
69
+ def set_message(self, message):
70
+ self._rows = []
71
+ self.add_row(message)
72
+
73
+ def set_wrap(self, wrap):
74
+ # if wrap is changed, we need to reprocess any existing rows
75
+ # to calculate the correct wrapping
76
+ self.wrap = wrap
77
+
78
+ def theme(self, theme_name):
79
+ if theme_name == "default":
80
+ self.border_symbol = "*"
81
+ self.background_symbol = " "
82
+ self.padding_symbol = " "
83
+ elif theme_name == "simple":
84
+ self.border_symbol = "-"
85
+ self.background_symbol = " "
86
+ self.padding_symbol = " "
87
+ elif theme_name == "hash":
88
+ self.border_symbol = "#"
89
+ self.background_symbol = " "
90
+ self.padding_symbol = " "
91
+ elif theme_name == "star":
92
+ self.border_symbol = "*"
93
+ self.background_symbol = " "
94
+ self.padding_symbol = " "
95
+ elif theme_name == "space":
96
+ self.border_symbol = " "
97
+ self.background_symbol = " "
98
+ self.padding_symbol = " "
99
+ elif theme_name == "none":
100
+ self.border_symbol = ""
101
+ self.background_symbol = ""
102
+ self.padding_symbol = ""
103
+ self.title_padding = 0
104
+ self.title_margin = 0
105
+ else:
106
+ self.border_symbol = "*"
107
+ self.background_symbol = " "
108
+ self.padding_symbol = " "
109
+
110
+ def _line(self, content):
111
+ checked_content_list = self._check_content_length(content)
112
+
113
+ for checked_content in checked_content_list:
114
+ self._rows.append(
115
+ self._create_row(checked_content)
116
+ )
117
+
118
+ def _create_row(self, content):
119
+ return (
120
+ f"{self.border_symbol}"
121
+ f"{self.padding_symbol * self.padding_left}"
122
+ f"{content}"
123
+ f"{self.background_symbol * int(self.width-len(content)-self.padding_left-self.padding_right-2)}"
124
+ f"{self.padding_symbol * self.padding_right}"
125
+ f"{self.border_symbol}"
126
+ )
127
+
128
+ def _check_content_length(self, content):
129
+ checked_content_list = []
130
+ if len(content) > self.width - \
131
+ (self.padding_left + self.padding_right) - \
132
+ (self._border_width * 2):
133
+ if self.wrap:
134
+ checked_content_list = textwrap.wrap(
135
+ content,
136
+ width=self.width-(self.padding_left+self.padding_right+(self._border_width*2)))
137
+ # for line in wrapped_content:
138
+ # self.add_row(line)
139
+ else:
140
+ checked_content_list.append(content[:self.width-(self.padding_left+self.padding_right+(self._border_width*2))])
141
+ else:
142
+ checked_content_list.append(content)
143
+ return checked_content_list
144
+
145
+ def _title(self):
146
+ if self.title is None or self.title == "":
147
+ return self._separator()
148
+
149
+ if len(self.title) > self.width - (self._border_width * 2) - (self.title_margin * 2) - (self.title_padding * 2):
150
+ logging.warning(f"Title is too long ({len(self.title)} chars) and has been truncated to fit banner: Total width:{self.width}, Title margin {self.title_margin * 2}, Title padding {self.title_padding * 2}, Allowed Title Length:{self.width-(self.title_margin*2)-(self.title_padding*2)}.")
151
+ self.title = self.title[:self.width-(self._border_width*2)-(self.title_margin*2)-(self.title_padding*2)]
152
+
153
+ return (
154
+ f"{self.border_symbol}"
155
+ f"{self.border_symbol * self.title_margin}"
156
+ f"{' ' * self.title_padding}"
157
+ f"{self.title}"
158
+ f"{' ' * self.title_padding}"
159
+ f"{self.border_symbol * self.title_margin}"
160
+ f"{self.border_symbol * int(self.width-len(self.title)-(self._border_width*2)-(self.title_padding*2)-(self.title_margin*2))}"
161
+ f"{self.border_symbol}"
162
+ )
163
+
164
+ def _separator(self):
165
+ return self.border_symbol * self.width
166
+
167
+ def _create_padding_top(self):
168
+ padding_lines = ""
169
+ for i in range(self.padding_top):
170
+ padding_lines += self._padding_line() + "\n"
171
+
172
+ # remove the last newline character
173
+ return padding_lines[:-1]
174
+
175
+ def _create_padding_bottom(self):
176
+ padding_lines = ""
177
+ for i in range(self.padding_bottom):
178
+ padding_lines += self._padding_line() + "\n"
179
+
180
+ # remove the last newline character
181
+ return padding_lines[:-1]
182
+
183
+ def _create_margin_top(self):
184
+ margin_lines = ""
185
+ for i in range(self.margin_top):
186
+ margin_lines += "\n"
187
+
188
+ return margin_lines
189
+
190
+ def _create_margin_bottom(self):
191
+ margin_lines = ""
192
+ for i in range(self.margin_bottom):
193
+ margin_lines += "\n"
194
+
195
+ return margin_lines
196
+
197
+ def _padding_line(self):
198
+ return self.border_symbol \
199
+ + self.padding_symbol * self.padding_left \
200
+ + self.padding_symbol * (self.width - 2 - self.padding_left - self.padding_right) \
201
+ + self.padding_symbol * self.padding_right \
202
+ + self.border_symbol
203
+
204
+ def _blank_line(self):
205
+ return self.border_symbol \
206
+ + self.padding_symbol * self.padding_left \
207
+ + self.background_symbol * (self.width - 2 - self.padding_left - self.padding_right) \
208
+ + self.padding_symbol * self.padding_right \
209
+ + self.border_symbol
@@ -0,0 +1,77 @@
1
+ from simple_terminal_banner import Banner, BannerThemes
2
+
3
+ # create a simple banner showing the easiest possible
4
+ # way to have a quick and easy banner message displayed
5
+ banner = Banner("Hello, World!")
6
+ banner.display()
7
+
8
+ # create a banner that also has a title
9
+ titled_banner = Banner("This banner message has a title.")
10
+ titled_banner.title = "Banner with a title"
11
+ titled_banner.display()
12
+
13
+ # There are some pre-defined themes that can be used
14
+ # to change the look of the banner. Here are examples
15
+ # of all the available themes.
16
+ for index, theme in enumerate(BannerThemes):
17
+ banner.theme(theme.value)
18
+ banner.title = f"{index+1}. Theme: {theme.value.capitalize()}"
19
+ banner.set_message(f"Theme name: {theme.value}")
20
+ banner.display()
21
+
22
+ quit()
23
+
24
+ print(list(BannerThemes))
25
+ for theme in BannerThemes:
26
+ print(theme.name)
27
+
28
+ basic_banner = Banner("Hello, World!")
29
+ basic_banner.title = "12345678901234567890123456789012345678901234567890"
30
+ basic_banner.title_padding = 0
31
+ basic_banner.title_margin = 0
32
+ basic_banner.display()
33
+ # quit()
34
+ banner = Banner("1234567890")
35
+ print()
36
+ banner.title = "Simple Terminal Banner"
37
+ banner.width = 40
38
+ banner.padding_left = 4
39
+ banner.padding_right = 4
40
+ banner.set_message("Hello, World!")
41
+ banner.display()
42
+ print()
43
+
44
+
45
+
46
+ multiline_banner = Banner()
47
+ multiline_banner.title = "Multiline Banner"
48
+ multiline_banner.width = 40
49
+ multiline_banner.padding_left = 4
50
+ multiline_banner.padding_right = 4
51
+ multiline_banner.margin_bottom = 1
52
+ multiline_banner.add_row("Hello, World!")
53
+ multiline_banner.add_row(type="blank")
54
+ multiline_banner.add_row("This is a multiline banner.")
55
+ multiline_banner.add_row("It can display multiple lines.")
56
+ multiline_banner.add_row(type="separator")
57
+ multiline_banner.add_row("This is the last line.")
58
+ multiline_banner.display()
59
+
60
+ no_border_banner = Banner()
61
+ no_border_banner.theme("none")
62
+ no_border_banner.title = "No Border, Margin or Padding, wrapped"
63
+ no_border_banner.width = 40
64
+ no_border_banner.add_row("Hello, World! This is the way you introduce most code examples in tutorials. It came from a book about C in the 1980s, but it's become a meme.")
65
+ no_border_banner.display()
66
+
67
+ no_border_banner.set_wrap(False)
68
+ no_border_banner.display()
69
+
70
+ no_padding_banner = Banner()
71
+ no_padding_banner.title = "No Margin or Padding, wrapped text"
72
+ no_padding_banner.width = 40
73
+ no_padding_banner.padding_left = 2
74
+ no_padding_banner.padding_right = 2
75
+ no_padding_banner.margin_bottom = 1
76
+ no_padding_banner.add_row("Hello, World! This is the way you introduce most code examples in tutorials. It came from a book about C in the 1980s, but it's become a meme.")
77
+ no_padding_banner.display()
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Stephen Graham
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,54 @@
1
+ Metadata-Version: 2.2
2
+ Name: simple_terminal_banner
3
+ Version: 0.0.6
4
+ Summary: A simple Python utility to display banners in the terminal
5
+ Author-email: "Stephen J. Graham" <stephen@seesawweb.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/charlbury/simple_terminal_banner
8
+ Project-URL: Repository, https://github.com/charlbury/simple_terminal_banner
9
+ Project-URL: Issues, https://github.com/charlbury/simple_terminal_banner/issues
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3.7
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+
17
+ # Simple Terminal Banner
18
+
19
+ ```
20
+ ** Simple Terminal Banner **************
21
+ * *
22
+ * Hello, World! *
23
+ * *
24
+ ****************************************
25
+ ```
26
+
27
+ Display a simple terminal banner.
28
+
29
+ ## Features
30
+
31
+ * Banner Title
32
+ * Themes
33
+ * Padding
34
+ * Configurable border symbols
35
+ * Configurable background symbols
36
+
37
+ ## Example
38
+
39
+ ```python
40
+ from banner import Banner
41
+
42
+ banner = Banner("Hello, World!")
43
+ banner.display()
44
+ ```
45
+
46
+ Produces:
47
+
48
+ ```
49
+ ****************************************
50
+ * *
51
+ * Hello, World! *
52
+ * *
53
+ ****************************************
54
+ ```
@@ -0,0 +1,8 @@
1
+ simple_terminal_banner/__init__.py,sha256=0cfNpfswT8T3vW4vLg8xTX3VaYMLUshLevSRd3ogUFQ,40
2
+ simple_terminal_banner/banner.py,sha256=vmjpqRe66wANTNlOyb4gm9JIei52MvYwGMacjycyul0,7271
3
+ simple_terminal_banner/examples.py,sha256=EmLE5DVBc0poF8hdNMSuefw-aWtNKdQ8v8w9QTbCGAA,2602
4
+ simple_terminal_banner-0.0.6.dist-info/LICENSE,sha256=zK9pX0Av9b6gWXqXxUlfXuHZv8EyFyZJJwRh-lwlJIM,1071
5
+ simple_terminal_banner-0.0.6.dist-info/METADATA,sha256=ag8bbg-Y0xy_9nOeioIHcppKgUgNx42nRYhAiagnB_s,1384
6
+ simple_terminal_banner-0.0.6.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
7
+ simple_terminal_banner-0.0.6.dist-info/top_level.txt,sha256=AUlEwZU8ureUzl5SFLPaAYNd4wbOwYgAl4nErx2rjKs,23
8
+ simple_terminal_banner-0.0.6.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (75.8.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ simple_terminal_banner