-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbannermagic.py
40 lines (29 loc) · 856 Bytes
/
bannermagic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
##### Author Konstantinos Pap
import os
from enum import Enum
class Location(Enum):
left=1
right=2
center=3
columns = os.get_terminal_size()[0]
# print the banner beauty
def printBannerPadding(char='='):
print(char*columns)
# print the message inside the banner on the center
def printMessage(message, location=Location.center):
# Calculate how many spaces we want for padding
if location == Location.left:
spaces = 0
elif location == Location.right:
spaces = columns - len(message)
else:
spaces = (columns - len(message)) //2
if spaces < 0:
spaces = 0
print(' '*spaces + message)
if __name__ == '__main__':
printBannerPadding('*')
printMessage('Hello i am centered!')
printMessage('Hello i am on the left!', location=Location.left)
printMessage('Hello i am on the right!', location=Location.right)
printBannerPadding('*')