Initial commit
* basic CLI that will post text and images * reblogging is available * tags are available
This commit is contained in:
93
tcli/effects.py
Normal file
93
tcli/effects.py
Normal file
@@ -0,0 +1,93 @@
|
||||
ESC = "\x1b"
|
||||
RESET = f"{ESC}[0m"
|
||||
|
||||
BOLD = f"{ESC}[1m"
|
||||
BOLD_RESET = f"{ESC}[22m"
|
||||
|
||||
DIM = f"{ESC}[2m"
|
||||
DIM_RESET = f"{ESC}[22m"
|
||||
|
||||
ITALIC = f"{ESC}[3m"
|
||||
ITALIC_RESET = f"{ESC}[23m"
|
||||
|
||||
UNDERLINE = f"{ESC}[4m"
|
||||
UNDERLINE_RESET = f"{ESC}[24m"
|
||||
|
||||
|
||||
def bold(text: str) -> str:
|
||||
return f"{BOLD}{text}{BOLD_RESET}"
|
||||
|
||||
|
||||
def dim(text: str) -> str:
|
||||
return f"{DIM}{text}{DIM_RESET}"
|
||||
|
||||
|
||||
def italic(text: str) -> str:
|
||||
return f"{ITALIC}{text}{ITALIC_RESET}"
|
||||
|
||||
|
||||
def underline(text: str) -> str:
|
||||
return f"{UNDERLINE}{text}{UNDERLINE_RESET}"
|
||||
|
||||
|
||||
COLORS = {
|
||||
"black": (90, 100),
|
||||
"red": (91, 101),
|
||||
"green": (92, 102),
|
||||
"yellow": (93, 103),
|
||||
"blue": (94, 104),
|
||||
"magenta": (95, 105),
|
||||
"cyan": (96, 106),
|
||||
"white": (97, 107),
|
||||
"default": (99, 109),
|
||||
}
|
||||
|
||||
|
||||
def color(fg: str | None = None, bg: str | None = None, text: str = "") -> str:
|
||||
if fg is None and bg is None:
|
||||
return f"{RESET}{text}"
|
||||
if fg:
|
||||
fg = f"{ESC}[1;{COLORS[fg][0]}m"
|
||||
else:
|
||||
fg = ""
|
||||
if bg:
|
||||
bg = f"{ESC}[1;{COLORS[bg][1]}m"
|
||||
else:
|
||||
bg = ""
|
||||
return f"{fg}{bg}{text}{RESET}"
|
||||
|
||||
|
||||
def black(text: str) -> str:
|
||||
return color(fg="black", text=text)
|
||||
|
||||
|
||||
def red(text: str) -> str:
|
||||
return color(fg="red", text=text)
|
||||
|
||||
|
||||
def green(text: str) -> str:
|
||||
return color(fg="green", text=text)
|
||||
|
||||
|
||||
def yellow(text: str) -> str:
|
||||
return color(fg="yellow", text=text)
|
||||
|
||||
|
||||
def blue(text: str) -> str:
|
||||
return color(fg="blue", text=text)
|
||||
|
||||
|
||||
def magenta(text: str) -> str:
|
||||
return color(fg="magenta", text=text)
|
||||
|
||||
|
||||
def cyan(text: str) -> str:
|
||||
return color(fg="cyan", text=text)
|
||||
|
||||
|
||||
def white(text: str) -> str:
|
||||
return color(fg="white", text=text)
|
||||
|
||||
|
||||
def default(text: str) -> str:
|
||||
return color(fg="default", text=text)
|
||||
Reference in New Issue
Block a user