Skip to content

Instantly share code, notes, and snippets.

@code-rgb
Last active June 15, 2021 08:51
Show Gist options
  • Save code-rgb/6c1600643b29139f41a79783cc840a25 to your computer and use it in GitHub Desktop.
Save code-rgb/6c1600643b29139f41a79783cc840a25 to your computer and use it in GitHub Desktop.
# Draw Lines
def draw_line(
text: str,
line_char: str = "-",
line_out: str = "#",
line_in: str = "",
max_length: int = 38,
reverse: bool = True,
) -> str:
def mirror(input_str: str) -> str:
text_chars = list(input_str)[::-1] if reverse else list(input_str)
for i, char in enumerate(text_chars):
for br in ["<>", "()", r"{}", "[]", "/\\"]:
if char in br:
text_chars[i] = br[1 if char == br[0] else 0]
return "".join(text_chars)
line_length = max_length - len(text)
line_left = round(line_length / 2)
line_right = line_length - line_left
line = (
line_out,
line_char * line_left,
line_in,
text,
mirror(line_in),
line_char * line_right,
mirror(line_out),
)
return " ".join(line)
"""
e.g:
foo = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.'
for i in foo.strip().split():
print(draw_line(text=i, line_out="# )>", reverse=True, line_in="|"))
>>
# )> ---------------- | Lorem | ----------------- <( #
# )> ---------------- | Ipsum | ----------------- <( #
# )> ------------------ | is | ------------------ <( #
# )> ---------------- | simply | ---------------- <( #
# )> ---------------- | dummy | ----------------- <( #
# )> ----------------- | text | ----------------- <( #
# )> ------------------ | of | ------------------ <( #
# )> ------------------ | the | ----------------- <( #
# )> --------------- | printing | --------------- <( #
# )> ------------------ | and | ----------------- <( #
# )> -------------- | typesetting | ------------- <( #
# )> -------------- | industry. | --------------- <( #
# )> ---------------- | Lorem | ----------------- <( #
# )> ---------------- | Ipsum | ----------------- <( #
# )> ------------------ | has | ----------------- <( #
# )> ----------------- | been | ----------------- <( #
# )> ------------------ | the | ----------------- <( #
# )> -------------- | industry's | -------------- <( #
# )> --------------- | standard | --------------- <( #
# )> ---------------- | dummy | ----------------- <( #
# )> ----------------- | text | ----------------- <( #
# )> ----------------- | ever | ----------------- <( #
# )> ---------------- | since | ----------------- <( #
# )> ------------------ | the | ----------------- <( #
# )> ---------------- | 1500s, | ---------------- <( #
# )> ----------------- | when | ----------------- <( #
# )> ------------------ | an | ------------------ <( #
# )> ---------------- | unknown | --------------- <( #
# )> ---------------- | printer | --------------- <( #
# )> ----------------- | took | ----------------- <( #
# )> ------------------ | a | ------------------- <( #
# )> ---------------- | galley | ---------------- <( #
# )> ------------------ | of | ------------------ <( #
# )> ----------------- | type | ----------------- <( #
# )> ------------------ | and | ----------------- <( #
# )> -------------- | scrambled | --------------- <( #
# )> ------------------ | it | ------------------ <( #
# )> ------------------ | to | ------------------ <( #
# )> ----------------- | make | ----------------- <( #
# )> ------------------ | a | ------------------- <( #
# )> ----------------- | type | ----------------- <( #
# )> --------------- | specimen | --------------- <( #
# )> ---------------- | book. | ----------------- <( #
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment