-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path14-text-framing.py
30 lines (20 loc) · 948 Bytes
/
14-text-framing.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
from dataclasses import dataclass, replace
@dataclass
class Frame:
top: str = "-"
left: str = "|"
bottom: str = "-"
right: str = "|"
top_left: str = "+"
top_right: str = "+"
bottom_left: str = "+"
bottom_right: str = "+"
fancy_frame = Frame("─", "│", "─", "│", "╭", "╮", "╰", "╯")
invisible_frame = Frame(" ", " ", " ", " ", " ", " ", " ", " ")
def frame_text(text: str, frame: Frame) -> str:
length = max([len(line) for line in text.split("\n")])
framed_text = frame.top_left + ''.join([frame.top for index in range(length)]) + frame.top_right + '\n'
for line in text.split("\n"):
framed_text = framed_text + frame.left + line + ''.join([' ' for item in range(length - len(line))]) + frame.right + '\n'
framed_text = framed_text + frame.bottom_left + ''.join([frame.bottom for index in range(length)]) + frame.bottom_right
return framed_text