-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
48 lines (39 loc) · 1.49 KB
/
utils.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
41
42
43
44
45
46
47
48
"""
Utils
=====
Some useful functions.
"""
import os, re
from colors import Colors as C
def getSize():
"""
Returns the size of the terminal.
"""
size = os.get_terminal_size()
rows, columns = size.lines, size.columns
return int(rows), int(columns)
def get_space_to_fill():
"""Returns the number of spaces to fill the terminal."""
rows, columns = getSize()
return int(columns) - 1
def get_space_to_fill_text(text: str):
"""Returns the number of spaces to fill the terminal."""
rows, columns = getSize()
return int(columns) - len(text) - 1
def print_top_line():
"""prints the top line of the terminal."""
print(f"{C.GRAY}" + "┌"+"─"*get_space_to_fill_text("┌─")+"┐" + f"{C.END}")
def print_bottom_line():
"""prints the bottom line of the terminal."""
print(f"{C.GRAY}" + "└" + "─"*get_space_to_fill_text("└─") + "┘" + f"{C.END}")
def print_middle_line():
"""prints the middle line of the terminal."""
print(f"{C.GRAY}" + "├"+"─"*get_space_to_fill_text("├─")+"┤" + f"{C.END}")
def lprint(text: str, more_space: int=0):
"""Prints a line with the given text and fills the rest of the terminal with spaces."""
# Remove ANSI escape sequences
raw_text = re.sub(r"\x1b\[[0-9;]*m", "", text)
print(f"{C.GRAY}│{C.END} {text}" + " "*(get_space_to_fill_text(f"│ {raw_text}")+more_space)+f"{C.GRAY}│{C.END}")
if __name__ == "__main__":
print(get_space_to_fill())
print(get_space_to_fill_text("Hello"))