Skip to content

Commit 8ab1fdd

Browse files
committed
make fully typed + closes #1
1 parent 272d540 commit 8ab1fdd

File tree

5 files changed

+243
-174
lines changed

5 files changed

+243
-174
lines changed

generate_styles.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
from pathlib import Path
2+
from typing import Union
3+
4+
STYLE_MAP: dict[str, str] = {
5+
"Bold": "\033[1m",
6+
"Dim": "\033[2m",
7+
"Italicized": "\033[3m",
8+
"Underlined": "\033[4m",
9+
"Blinking": "\033[5m",
10+
"SlowlyBlinking": "\033[6m",
11+
"Inverted": "\033[7m",
12+
"Hidden": "\033[8m",
13+
"Striked": "\033[9m",
14+
"Black": "\033[30m",
15+
"Red": "\033[31m",
16+
"Green": "\033[32m",
17+
"Yellow": "\033[33m",
18+
"Blue": "\033[34m",
19+
"Magenta": "\033[35m",
20+
"Cyan": "\033[36m",
21+
"White": "\033[37m",
22+
"Gray": "\033[90m",
23+
"BrightRed": "\033[91m",
24+
"BrightGreen": "\033[92m",
25+
"BrightYellow": "\033[93m",
26+
"BrightBlue": "\033[94m",
27+
"BrightMagenta": "\033[95m",
28+
"BrightCyan": "\033[96m",
29+
"BrightWhite": "\033[97m",
30+
"BGBlack": "\033[40m",
31+
"BGRed": "\033[41m",
32+
"BGGreen": "\033[42m",
33+
"BGYellow": "\033[43m",
34+
"BGBlue": "\033[44m",
35+
"BGMagenta": "\033[45m",
36+
"BGCyan": "\033[46m",
37+
"BGWhite": "\033[47m",
38+
"BGGray": "\033[100m",
39+
"BGBrightRed": "\033[101m",
40+
"BGBrightGreen": "\033[102m",
41+
"BGBrightYellow": "\033[103m",
42+
"BGBrightBlue": "\033[104m",
43+
"BGBrightMagenta": "\033[105m",
44+
"BGBrightCyan": "\033[106m",
45+
"BGBrightWhite": "\033[107m",
46+
}
47+
48+
DOCS: dict[str, str] = {
49+
"Italicized": "Some legacy terminals don't support italicized text.",
50+
"SlowlyBlinking": "Support for slow blinking is highly limited. Most modern terminals will treat this the same as normal blink.",
51+
"Hidden": "This has absolutely no use. I don't know why this is in ANSI at all.",
52+
}
53+
54+
def generate_class(name: str, code: str, doc: Union[str, None] = None) -> str:
55+
docstring = f' """{doc}"""\n' if doc else ''
56+
return f'''
57+
class {name}(BaseText):
58+
{docstring} def __new__(cls, text: Union[str, BaseText, None] = None) -> "{name}": # NOQA
59+
code = {code!r}
60+
return cast("{name}", super().__new__(cls, code, text))
61+
'''.rstrip()
62+
63+
def main() -> None:
64+
lines = []
65+
for name, code in STYLE_MAP.items():
66+
doc = DOCS.get(name)
67+
lines.append(generate_class(name, code, doc))
68+
out = "\n\n".join(lines) + "\n"
69+
70+
Path("tranci/styles.py").write_text(out)
71+
72+
if __name__ == "__main__":
73+
main()

screenshot.png

-31.1 KB
Binary file not shown.

setup.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,8 @@
5959
"Source": "https://github.com/Butterroach/tranci",
6060
"Bug Tracker": "https://github.com/Butterroach/tranci/issues",
6161
},
62+
include_package_data=True,
63+
package_data={
64+
'package': ['py.typed'],
65+
},
6266
)

0 commit comments

Comments
 (0)