tcolorize 0.1.0__tar.gz
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.
tcolorize-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: tcolorize
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Very simple cross-platform colored terminal text in Python
|
|
5
|
+
Author: grayphi
|
|
6
|
+
Author-email: grayphi <>
|
|
7
|
+
Requires-Python: >=3.14
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
|
|
10
|
+
# tcolorize
|
|
11
|
+
Very simple cross-platform colored terminal text in Python
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "tcolorize"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Very simple cross-platform colored terminal text in Python"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.14"
|
|
7
|
+
dependencies = []
|
|
8
|
+
|
|
9
|
+
[[project.authors]]
|
|
10
|
+
name = "grayphi"
|
|
11
|
+
email = ""
|
|
12
|
+
|
|
13
|
+
[build-system]
|
|
14
|
+
requires = ["uv_build>=0.12.15,<0.13.0"]
|
|
15
|
+
build-backend = "uv_build"
|
|
16
|
+
|
|
17
|
+
[dependency-groups]
|
|
18
|
+
dev = [
|
|
19
|
+
"pylint>=4.0.9",
|
|
20
|
+
"pytest>=9.1.1",
|
|
21
|
+
]
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "tcolorize"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Very simple cross-platform colored terminal text in Python"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "grayphi", email = "" }
|
|
8
|
+
]
|
|
9
|
+
requires-python = ">=3.14"
|
|
10
|
+
dependencies = []
|
|
11
|
+
|
|
12
|
+
[build-system]
|
|
13
|
+
requires = ["uv_build>=0.12.15,<0.13.0"]
|
|
14
|
+
build-backend = "uv_build"
|
|
15
|
+
|
|
16
|
+
[dependency-groups]
|
|
17
|
+
dev = [
|
|
18
|
+
"pylint>=4.0.9",
|
|
19
|
+
"pytest>=9.1.1",
|
|
20
|
+
]
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# vim:ts=4:sw=4:cc=80:et:si:sta:ai:nu:nowrap:cul:sm:is:hls:pt=<F3>:
|
|
2
|
+
# pylint: disable=missing-module-docstring, missing-function-docstring
|
|
3
|
+
# pylint: disable=trailing-newlines
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
from tcolorize.main import (
|
|
7
|
+
as_red,
|
|
8
|
+
as_cyan,
|
|
9
|
+
as_yellow,
|
|
10
|
+
as_orange,
|
|
11
|
+
as_light_blue,
|
|
12
|
+
as_light_green,
|
|
13
|
+
as_light_green_2,
|
|
14
|
+
as_light_red,
|
|
15
|
+
on_black,
|
|
16
|
+
on_light_black,
|
|
17
|
+
on_dark_black,
|
|
18
|
+
as_bold,
|
|
19
|
+
as_dim,
|
|
20
|
+
as_underline
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
__version__ = '0.1.0'
|
|
25
|
+
|
|
26
|
+
__all__ = [
|
|
27
|
+
'as_red',
|
|
28
|
+
'as_cyan',
|
|
29
|
+
'as_yellow',
|
|
30
|
+
'as_orange',
|
|
31
|
+
'as_light_blue',
|
|
32
|
+
'as_light_green',
|
|
33
|
+
'as_light_green_2',
|
|
34
|
+
'as_light_red',
|
|
35
|
+
'on_black',
|
|
36
|
+
'on_light_black',
|
|
37
|
+
'on_dark_black',
|
|
38
|
+
'as_bold',
|
|
39
|
+
'as_dim',
|
|
40
|
+
'as_underline'
|
|
41
|
+
]
|
|
42
|
+
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# vim:ts=4:sw=4:cc=80:et:si:sta:ai:nu:nowrap:cul:sm:is:hls:pt=<F3>:
|
|
2
|
+
# pylint: disable=missing-module-docstring, missing-function-docstring
|
|
3
|
+
# pylint: disable=trailing-newlines
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
from tcolorize import tput
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
_NO_COLOR = False
|
|
11
|
+
_NC_ENVARS = [
|
|
12
|
+
"NO_COLOR",
|
|
13
|
+
"TCOLORIZE_NO_COLOR"
|
|
14
|
+
]
|
|
15
|
+
_NC_ENV_VALS = ["0", "no_color", "true"]
|
|
16
|
+
|
|
17
|
+
for ev in _NC_ENVARS:
|
|
18
|
+
if os.environ.get(ev, "").lower() in _NC_ENV_VALS:
|
|
19
|
+
_NO_COLOR = True
|
|
20
|
+
break
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _cont(t, es):
|
|
24
|
+
return t.replace(tput.reset_all(), tput.reset_all() + es)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _color(t, es):
|
|
28
|
+
return es + _cont(t, es) + tput.reset_all()
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def as_red(text):
|
|
32
|
+
return text if _NO_COLOR else _color(text, tput.fg_red())
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def as_cyan(text):
|
|
36
|
+
return text if _NO_COLOR else _color(text, tput.fg_cyan())
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def as_yellow(text):
|
|
40
|
+
return text if _NO_COLOR else _color(text, tput.fg_yellow())
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def as_orange(text):
|
|
44
|
+
return text if _NO_COLOR else _color(text, tput.fg_orange())
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def as_light_blue(text):
|
|
48
|
+
return text if _NO_COLOR else _color(text, tput.fg_light_blue())
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def as_light_green(text):
|
|
52
|
+
return text if _NO_COLOR else _color(text, tput.fg_light_green())
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def as_light_green_2(text):
|
|
56
|
+
return text if _NO_COLOR else _color(text, tput.fg_light_green_2())
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def as_light_red(text):
|
|
60
|
+
return text if _NO_COLOR else _color(text, tput.fg_light_red())
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def on_black(text):
|
|
64
|
+
return text if _NO_COLOR else _color(text, tput.bg_black())
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def on_light_black(text):
|
|
68
|
+
return text if _NO_COLOR else _color(text, tput.bg_light_black())
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def on_dark_black(text):
|
|
72
|
+
return text if _NO_COLOR else _color(text, tput.bg_dark_black())
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def as_bold(text):
|
|
76
|
+
return text if _NO_COLOR else _color(text, tput.style_bold())
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def as_dim(text):
|
|
80
|
+
return text if _NO_COLOR else _color(text, tput.style_dim())
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def as_underline(text):
|
|
84
|
+
return text if _NO_COLOR else _color(text, tput.style_underline())
|
|
85
|
+
|
|
86
|
+
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# vim:ts=4:sw=4:cc=80:et:si:sta:ai:nu:nowrap:cul:sm:is:hls:pt=<F3>:
|
|
2
|
+
# pylint: disable=missing-module-docstring, missing-function-docstring
|
|
3
|
+
# pylint: disable=trailing-newlines
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import shutil
|
|
7
|
+
import subprocess
|
|
8
|
+
from functools import cache
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@cache
|
|
12
|
+
def can_tput():
|
|
13
|
+
return (
|
|
14
|
+
os.isatty(1)
|
|
15
|
+
and shutil.which("tput") is not None
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@cache
|
|
20
|
+
def get_tput(*args):
|
|
21
|
+
if not can_tput():
|
|
22
|
+
return None
|
|
23
|
+
|
|
24
|
+
result = subprocess.run(
|
|
25
|
+
["tput", *args],
|
|
26
|
+
capture_output=True,
|
|
27
|
+
text=True,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
if result and result.returncode == 0:
|
|
31
|
+
return result.stdout
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class Fg:
|
|
35
|
+
LIGHT_GREEN = "2"
|
|
36
|
+
LIGHT_RED = "9"
|
|
37
|
+
LIGHT_GREEN_2 = "10"
|
|
38
|
+
LIGHT_BLUE = "42"
|
|
39
|
+
CYAN = "44"
|
|
40
|
+
YELLOW = "190"
|
|
41
|
+
ORANGE = "202"
|
|
42
|
+
RED = "196"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class Bg:
|
|
46
|
+
BLACK = "16"
|
|
47
|
+
DARK_BLACK = "233"
|
|
48
|
+
LIGHT_BLACK = "236"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class Style:
|
|
52
|
+
BOLD = "bold"
|
|
53
|
+
DIM = "dim"
|
|
54
|
+
UNDERLINE = "smul"
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class Other:
|
|
58
|
+
RESET_ALL = "sgr0"
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
fg = Fg()
|
|
62
|
+
bg = Bg()
|
|
63
|
+
style = Style()
|
|
64
|
+
other = Other()
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@cache
|
|
68
|
+
def fg_red():
|
|
69
|
+
return get_tput("setaf", fg.RED) or ""
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@cache
|
|
73
|
+
def fg_cyan():
|
|
74
|
+
return get_tput("setaf", fg.CYAN) or ""
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@cache
|
|
78
|
+
def fg_yellow():
|
|
79
|
+
return get_tput("setaf", fg.YELLOW) or ""
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@cache
|
|
83
|
+
def fg_orange():
|
|
84
|
+
return get_tput("setaf", fg.ORANGE) or ""
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@cache
|
|
88
|
+
def fg_light_blue():
|
|
89
|
+
return get_tput("setaf", fg.LIGHT_BLUE) or ""
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@cache
|
|
93
|
+
def fg_light_green():
|
|
94
|
+
return get_tput("setaf", fg.LIGHT_GREEN) or ""
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
@cache
|
|
98
|
+
def fg_light_green_2():
|
|
99
|
+
return get_tput("setaf", fg.LIGHT_GREEN_2) or ""
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
@cache
|
|
103
|
+
def fg_light_red():
|
|
104
|
+
return get_tput("setaf", fg.LIGHT_RED) or ""
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
@cache
|
|
108
|
+
def bg_black():
|
|
109
|
+
return get_tput("setab", bg.BLACK) or ""
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
@cache
|
|
113
|
+
def bg_light_black():
|
|
114
|
+
return get_tput("setab", bg.LIGHT_BLACK) or ""
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
@cache
|
|
118
|
+
def bg_dark_black():
|
|
119
|
+
return get_tput("setab", bg.DARK_BLACK) or ""
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
@cache
|
|
123
|
+
def style_bold():
|
|
124
|
+
return get_tput(style.BOLD) or ""
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
@cache
|
|
128
|
+
def style_dim():
|
|
129
|
+
return get_tput(style.DIM) or ""
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
@cache
|
|
133
|
+
def style_underline():
|
|
134
|
+
return get_tput(style.UNDERLINE) or ""
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
@cache
|
|
138
|
+
def reset_all():
|
|
139
|
+
return get_tput(other.RESET_ALL) or ""
|
|
140
|
+
|
|
141
|
+
|