thds.termtool 1.0.20251104012942__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ from thds.core import meta
2
+
3
+ __version__ = meta.get_version(__name__)
4
+ __commit__ = meta.read_metadata(__name__).git_commit
@@ -0,0 +1,110 @@
1
+ import itertools
2
+ import random
3
+ import typing as ty
4
+ from functools import partial
5
+
6
+ from colors import color, csscolors
7
+
8
+ pref = "\033["
9
+ reset = f"{pref}0m"
10
+
11
+ _RESERVED_COLORS = [
12
+ "black",
13
+ # Various whitish-looking colors
14
+ "aliceblue",
15
+ "antiquewhite",
16
+ "floralwhite",
17
+ "ghostwhite",
18
+ "ivory",
19
+ "white",
20
+ "whitesmoke",
21
+ "snow",
22
+ "seashell",
23
+ "mintcream",
24
+ "honeydew",
25
+ "azure",
26
+ "beige",
27
+ "cornsilk",
28
+ "floralwhite",
29
+ # These are pretty illegible on a black background
30
+ "darkblue",
31
+ "indigo",
32
+ "mediumblue",
33
+ "navy",
34
+ "purple",
35
+ ]
36
+
37
+ _PREFERRED_COLORS = [
38
+ "mediumseagreen",
39
+ "cornflowerblue",
40
+ "gold",
41
+ "salmon",
42
+ "violet",
43
+ "limegreen",
44
+ "dodgerblue",
45
+ "goldenrod",
46
+ "indianred",
47
+ "fuchsia",
48
+ "forestgreen",
49
+ "royalblue",
50
+ "yellow",
51
+ "chocolate",
52
+ "palevioletred",
53
+ "mediumspringgreen",
54
+ "deepskyblue",
55
+ "khaki",
56
+ "red",
57
+ "deeppink",
58
+ "seagreen",
59
+ "cyan",
60
+ "greenyellow",
61
+ "sandybrown",
62
+ "orchid",
63
+ "lightgreen",
64
+ "steelblue",
65
+ "darkgoldenrod",
66
+ "coral",
67
+ "darkorchid",
68
+ ]
69
+
70
+
71
+ def _start_from(color_list: ty.List[str], index: int) -> ty.List[str]:
72
+ return color_list[index:] + color_list[:index]
73
+
74
+
75
+ def _preferred_randgreen_start() -> ty.List[str]:
76
+ return _start_from(_PREFERRED_COLORS, random.randint(0, 6) * 5)
77
+
78
+
79
+ def _all_colors() -> ty.List[str]:
80
+ forbidden_colors = {csscolors.css_colors[name] for name in _RESERVED_COLORS}
81
+ used_colors = {csscolors.css_colors[name] for name in _PREFERRED_COLORS}
82
+ assert len(used_colors) == len(_PREFERRED_COLORS) # assert no RGB dupes in the preferred list
83
+ all_colors = list(csscolors.css_colors.items())
84
+ random.shuffle(all_colors)
85
+ return _preferred_randgreen_start() + [
86
+ name
87
+ for name, rgb in all_colors
88
+ if rgb not in used_colors
89
+ and not used_colors.add(rgb) # type: ignore
90
+ and rgb not in forbidden_colors
91
+ ]
92
+
93
+
94
+ next_color = ty.cast(ty.Callable[[], str], partial(next, itertools.cycle(_all_colors())))
95
+
96
+
97
+ def colorized(fg: str, bg: str = "", style: str = "") -> ty.Callable[[str], str]:
98
+ def colorize(s: str) -> str:
99
+ return color(s, fg=fg, bg=bg, style=style)
100
+
101
+ return colorize
102
+
103
+
104
+ def make_colorized_out(
105
+ colorized: ty.Callable[[str], str], *, fmt_str: str = "{}", out: ty.Callable[[str], ty.Any] = print
106
+ ) -> ty.Callable[[str], None]:
107
+ def _out(s: str) -> None:
108
+ out(colorized(fmt_str.format(s)))
109
+
110
+ return _out
thds/termtool/py.typed ADDED
File without changes
@@ -0,0 +1,14 @@
1
+ Metadata-Version: 2.4
2
+ Name: thds.termtool
3
+ Version: 1.0.20251104012942
4
+ Summary: Tools for terminal-based applications
5
+ Author-email: Trilliant Health <info@trillianthealth.com>
6
+ Project-URL: repository, https://github.com/TrilliantHealth/ds-monorepo
7
+ Requires-Python: >=3.9
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: ansicolors
10
+ Requires-Dist: thds-core
11
+
12
+ # `thds.termtool` Library
13
+
14
+ Tools for terminal-based applications
@@ -0,0 +1,7 @@
1
+ thds/termtool/__init__.py,sha256=7hP-VWe-nq56jMk4jqsDanussQDzTUgOG94zUn7GgwA,122
2
+ thds/termtool/colorize.py,sha256=RmygwyL7L_Ue218AQOBp57p4r97PWqTiA1-M5AFvV6Y,2506
3
+ thds/termtool/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ thds_termtool-1.0.20251104012942.dist-info/METADATA,sha256=hDeBjMLHwAI9_cyGeBPq9o-0sHpsjGN8JFz6QRKm0Z8,427
5
+ thds_termtool-1.0.20251104012942.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
+ thds_termtool-1.0.20251104012942.dist-info/top_level.txt,sha256=LTZaE5SkWJwv9bwOlMbIhiS-JWQEEIcjVYnJrt-CriY,5
7
+ thds_termtool-1.0.20251104012942.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+