shellcolorize 0.3__tar.gz → 1.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.
- shellcolorize-1.1.0/LICENSE +21 -0
- shellcolorize-1.1.0/PKG-INFO +181 -0
- shellcolorize-1.1.0/README.md +157 -0
- shellcolorize-1.1.0/pyproject.toml +45 -0
- shellcolorize-1.1.0/shellcolorize/__init__.py +4 -0
- shellcolorize-1.1.0/shellcolorize/color.py +126 -0
- shellcolorize-1.1.0/shellcolorize/py.typed +0 -0
- shellcolorize-1.1.0/shellcolorize.egg-info/PKG-INFO +181 -0
- {shellcolorize-0.3 → shellcolorize-1.1.0}/shellcolorize.egg-info/SOURCES.txt +6 -2
- shellcolorize-1.1.0/shellcolorize.egg-info/requires.txt +4 -0
- shellcolorize-1.1.0/tests/test_color.py +74 -0
- shellcolorize-0.3/PKG-INFO +0 -124
- shellcolorize-0.3/README.md +0 -109
- shellcolorize-0.3/setup.py +0 -23
- shellcolorize-0.3/shellcolorize/__init__.py +0 -5
- shellcolorize-0.3/shellcolorize/color.py +0 -23
- shellcolorize-0.3/shellcolorize.egg-info/PKG-INFO +0 -124
- {shellcolorize-0.3 → shellcolorize-1.1.0}/setup.cfg +0 -0
- {shellcolorize-0.3 → shellcolorize-1.1.0}/shellcolorize.egg-info/dependency_links.txt +0 -0
- {shellcolorize-0.3 → shellcolorize-1.1.0}/shellcolorize.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Serber1990
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: shellcolorize
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: Add color and style to terminal output using ANSI codes
|
|
5
|
+
Author-email: Serber1990 <serber1990@pm.me>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/serber1990/shell-colorize
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/serber1990/shell-colorize/issues
|
|
9
|
+
Project-URL: Source Code, https://github.com/serber1990/shell-colorize
|
|
10
|
+
Project-URL: Changelog, https://github.com/serber1990/shell-colorize/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: ansi,color,terminal,cli,no-color
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Environment :: Console
|
|
15
|
+
Classifier: Topic :: Terminals
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Provides-Extra: dev
|
|
21
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
22
|
+
Requires-Dist: ruff>=0.4; extra == "dev"
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# 🌈 `shellcolorize`
|
|
26
|
+
|
|
27
|
+
[](https://github.com/serber1990/shell-colorize/actions/workflows/ci.yml)
|
|
28
|
+
[](https://badge.fury.io/py/shellcolorize)
|
|
29
|
+
[](https://opensource.org/licenses/MIT)
|
|
30
|
+
[](https://github.com/serber1990/shell-colorize/stargazers)
|
|
31
|
+
|
|
32
|
+
**`shellcolorize`** is a lightweight Python library for adding color and style to terminal output using ANSI codes. Zero dependencies, no configuration — just import and use.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## ✨ Features
|
|
37
|
+
|
|
38
|
+
- 🎨 **Full ANSI palette** — 8 standard + 8 bright text colors, same for backgrounds.
|
|
39
|
+
- ✍️ **Text styles** — bold, dim, italic, underline, blink, reverse, strikethrough.
|
|
40
|
+
- 🛠 **`colorize()` helper** — applies styles and resets automatically, no manual `RESET` needed.
|
|
41
|
+
- 🔇 **Smart color detection** — plain text when piped to a file, honours [`NO_COLOR`](https://no-color.org) and `FORCE_COLOR`.
|
|
42
|
+
- 🔌 **Global on/off switch** — `Color.auto()` / `Color.disable()` make every f-string plain text in one call.
|
|
43
|
+
- 🔗 **Open Source** — MIT License.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## 📥 Installation
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install shellcolorize
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## 🛠 Usage
|
|
56
|
+
|
|
57
|
+
### Using `colorize()` (recommended)
|
|
58
|
+
|
|
59
|
+
`colorize(text, *styles)` applies any combination of colors and styles and resets automatically. It also returns plain text when the output is not a TTY or when the `NO_COLOR` env var is set.
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from shellcolorize import Color, colorize
|
|
63
|
+
|
|
64
|
+
print(colorize("This is red", Color.RED))
|
|
65
|
+
print(colorize("Bold and underlined", Color.BOLD, Color.UNDERLINE))
|
|
66
|
+
print(colorize("White on blue background", Color.BG_BLUE, Color.WHITE))
|
|
67
|
+
print(colorize("Bright green, bold", Color.BRIGHT_GREEN, Color.BOLD))
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Using `Color` attributes directly
|
|
71
|
+
|
|
72
|
+
For inline use in f-strings. Remember to close with `Color.RESET`.
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
from shellcolorize import Color
|
|
76
|
+
|
|
77
|
+
print(f"{Color.RED}This is red{Color.RESET}")
|
|
78
|
+
print(f"{Color.BG_YELLOW}{Color.BLACK}Black on yellow{Color.RESET}")
|
|
79
|
+
print(f"{Color.BOLD}{Color.CYAN}Bold cyan{Color.RESET}")
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## 🎨 Available Colors
|
|
85
|
+
|
|
86
|
+
### Standard text colors
|
|
87
|
+
|
|
88
|
+
| Attribute | Attribute |
|
|
89
|
+
|-----------|-----------|
|
|
90
|
+
| `Color.BLACK` | `Color.BRIGHT_BLACK` |
|
|
91
|
+
| `Color.RED` | `Color.BRIGHT_RED` |
|
|
92
|
+
| `Color.GREEN` | `Color.BRIGHT_GREEN` |
|
|
93
|
+
| `Color.YELLOW` | `Color.BRIGHT_YELLOW` |
|
|
94
|
+
| `Color.BLUE` | `Color.BRIGHT_BLUE` |
|
|
95
|
+
| `Color.MAGENTA` | `Color.BRIGHT_MAGENTA` |
|
|
96
|
+
| `Color.CYAN` | `Color.BRIGHT_CYAN` |
|
|
97
|
+
| `Color.WHITE` | `Color.BRIGHT_WHITE` |
|
|
98
|
+
|
|
99
|
+
### Background colors
|
|
100
|
+
|
|
101
|
+
| Attribute | Attribute |
|
|
102
|
+
|-----------|-----------|
|
|
103
|
+
| `Color.BG_BLACK` | `Color.BG_BRIGHT_BLACK` |
|
|
104
|
+
| `Color.BG_RED` | `Color.BG_BRIGHT_RED` |
|
|
105
|
+
| `Color.BG_GREEN` | `Color.BG_BRIGHT_GREEN` |
|
|
106
|
+
| `Color.BG_YELLOW` | `Color.BG_BRIGHT_YELLOW` |
|
|
107
|
+
| `Color.BG_BLUE` | `Color.BG_BRIGHT_BLUE` |
|
|
108
|
+
| `Color.BG_MAGENTA` | `Color.BG_BRIGHT_MAGENTA` |
|
|
109
|
+
| `Color.BG_CYAN` | `Color.BG_BRIGHT_CYAN` |
|
|
110
|
+
| `Color.BG_WHITE` | `Color.BG_BRIGHT_WHITE` |
|
|
111
|
+
|
|
112
|
+
### Text styles
|
|
113
|
+
|
|
114
|
+
| Attribute | Effect |
|
|
115
|
+
|-----------|--------|
|
|
116
|
+
| `Color.BOLD` | **Bold** |
|
|
117
|
+
| `Color.DIM` | Dimmed |
|
|
118
|
+
| `Color.ITALIC` | *Italic* |
|
|
119
|
+
| `Color.UNDERLINE` | Underline |
|
|
120
|
+
| `Color.BLINK` | Blinking |
|
|
121
|
+
| `Color.REVERSE` | Swaps fg/bg colors |
|
|
122
|
+
| `Color.STRIKETHROUGH` | ~~Strikethrough~~ |
|
|
123
|
+
| `Color.RESET` | Clears all styles |
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## 🔇 Color detection
|
|
128
|
+
|
|
129
|
+
`supports_color()` decides whether colors should be used, following common CLI conventions:
|
|
130
|
+
|
|
131
|
+
| Situation | Result |
|
|
132
|
+
|-----------|--------|
|
|
133
|
+
| `NO_COLOR` set (any value) — see [no-color.org](https://no-color.org) | plain text |
|
|
134
|
+
| `FORCE_COLOR` set (any value except `0`) | colors |
|
|
135
|
+
| Output is a terminal | colors |
|
|
136
|
+
| Output redirected to a file or piped | plain text |
|
|
137
|
+
|
|
138
|
+
`colorize()` applies this check on every call. For f-strings that use `Color` attributes directly,
|
|
139
|
+
call `Color.auto()` once at start-up and every attribute becomes an empty string when colors are not supported:
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
from shellcolorize import Color
|
|
143
|
+
|
|
144
|
+
def main():
|
|
145
|
+
Color.auto() # respects NO_COLOR / FORCE_COLOR / TTY detection
|
|
146
|
+
print(f"{Color.GREEN}✔ done{Color.RESET}") # plain "✔ done" when piped
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
`Color.disable()` and `Color.enable()` switch colors off and on explicitly (e.g. for a `--no-color` flag).
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
python script.py > output.txt # plain text in the file
|
|
153
|
+
NO_COLOR=1 python script.py # plain text
|
|
154
|
+
FORCE_COLOR=1 python script.py | less -R # keep colors through a pager
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## 🧪 Development
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
pip install -e ".[dev]"
|
|
163
|
+
ruff check .
|
|
164
|
+
pytest
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## 📝 License
|
|
170
|
+
|
|
171
|
+
MIT — see [LICENSE](LICENSE).
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## 💬 Feedback
|
|
176
|
+
|
|
177
|
+
Open an issue or reach out via GitHub.
|
|
178
|
+
|
|
179
|
+
## 🌐 Connect
|
|
180
|
+
|
|
181
|
+
[](https://github.com/serber1990)
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# 🌈 `shellcolorize`
|
|
2
|
+
|
|
3
|
+
[](https://github.com/serber1990/shell-colorize/actions/workflows/ci.yml)
|
|
4
|
+
[](https://badge.fury.io/py/shellcolorize)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://github.com/serber1990/shell-colorize/stargazers)
|
|
7
|
+
|
|
8
|
+
**`shellcolorize`** is a lightweight Python library for adding color and style to terminal output using ANSI codes. Zero dependencies, no configuration — just import and use.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## ✨ Features
|
|
13
|
+
|
|
14
|
+
- 🎨 **Full ANSI palette** — 8 standard + 8 bright text colors, same for backgrounds.
|
|
15
|
+
- ✍️ **Text styles** — bold, dim, italic, underline, blink, reverse, strikethrough.
|
|
16
|
+
- 🛠 **`colorize()` helper** — applies styles and resets automatically, no manual `RESET` needed.
|
|
17
|
+
- 🔇 **Smart color detection** — plain text when piped to a file, honours [`NO_COLOR`](https://no-color.org) and `FORCE_COLOR`.
|
|
18
|
+
- 🔌 **Global on/off switch** — `Color.auto()` / `Color.disable()` make every f-string plain text in one call.
|
|
19
|
+
- 🔗 **Open Source** — MIT License.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 📥 Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install shellcolorize
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## 🛠 Usage
|
|
32
|
+
|
|
33
|
+
### Using `colorize()` (recommended)
|
|
34
|
+
|
|
35
|
+
`colorize(text, *styles)` applies any combination of colors and styles and resets automatically. It also returns plain text when the output is not a TTY or when the `NO_COLOR` env var is set.
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from shellcolorize import Color, colorize
|
|
39
|
+
|
|
40
|
+
print(colorize("This is red", Color.RED))
|
|
41
|
+
print(colorize("Bold and underlined", Color.BOLD, Color.UNDERLINE))
|
|
42
|
+
print(colorize("White on blue background", Color.BG_BLUE, Color.WHITE))
|
|
43
|
+
print(colorize("Bright green, bold", Color.BRIGHT_GREEN, Color.BOLD))
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Using `Color` attributes directly
|
|
47
|
+
|
|
48
|
+
For inline use in f-strings. Remember to close with `Color.RESET`.
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from shellcolorize import Color
|
|
52
|
+
|
|
53
|
+
print(f"{Color.RED}This is red{Color.RESET}")
|
|
54
|
+
print(f"{Color.BG_YELLOW}{Color.BLACK}Black on yellow{Color.RESET}")
|
|
55
|
+
print(f"{Color.BOLD}{Color.CYAN}Bold cyan{Color.RESET}")
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## 🎨 Available Colors
|
|
61
|
+
|
|
62
|
+
### Standard text colors
|
|
63
|
+
|
|
64
|
+
| Attribute | Attribute |
|
|
65
|
+
|-----------|-----------|
|
|
66
|
+
| `Color.BLACK` | `Color.BRIGHT_BLACK` |
|
|
67
|
+
| `Color.RED` | `Color.BRIGHT_RED` |
|
|
68
|
+
| `Color.GREEN` | `Color.BRIGHT_GREEN` |
|
|
69
|
+
| `Color.YELLOW` | `Color.BRIGHT_YELLOW` |
|
|
70
|
+
| `Color.BLUE` | `Color.BRIGHT_BLUE` |
|
|
71
|
+
| `Color.MAGENTA` | `Color.BRIGHT_MAGENTA` |
|
|
72
|
+
| `Color.CYAN` | `Color.BRIGHT_CYAN` |
|
|
73
|
+
| `Color.WHITE` | `Color.BRIGHT_WHITE` |
|
|
74
|
+
|
|
75
|
+
### Background colors
|
|
76
|
+
|
|
77
|
+
| Attribute | Attribute |
|
|
78
|
+
|-----------|-----------|
|
|
79
|
+
| `Color.BG_BLACK` | `Color.BG_BRIGHT_BLACK` |
|
|
80
|
+
| `Color.BG_RED` | `Color.BG_BRIGHT_RED` |
|
|
81
|
+
| `Color.BG_GREEN` | `Color.BG_BRIGHT_GREEN` |
|
|
82
|
+
| `Color.BG_YELLOW` | `Color.BG_BRIGHT_YELLOW` |
|
|
83
|
+
| `Color.BG_BLUE` | `Color.BG_BRIGHT_BLUE` |
|
|
84
|
+
| `Color.BG_MAGENTA` | `Color.BG_BRIGHT_MAGENTA` |
|
|
85
|
+
| `Color.BG_CYAN` | `Color.BG_BRIGHT_CYAN` |
|
|
86
|
+
| `Color.BG_WHITE` | `Color.BG_BRIGHT_WHITE` |
|
|
87
|
+
|
|
88
|
+
### Text styles
|
|
89
|
+
|
|
90
|
+
| Attribute | Effect |
|
|
91
|
+
|-----------|--------|
|
|
92
|
+
| `Color.BOLD` | **Bold** |
|
|
93
|
+
| `Color.DIM` | Dimmed |
|
|
94
|
+
| `Color.ITALIC` | *Italic* |
|
|
95
|
+
| `Color.UNDERLINE` | Underline |
|
|
96
|
+
| `Color.BLINK` | Blinking |
|
|
97
|
+
| `Color.REVERSE` | Swaps fg/bg colors |
|
|
98
|
+
| `Color.STRIKETHROUGH` | ~~Strikethrough~~ |
|
|
99
|
+
| `Color.RESET` | Clears all styles |
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## 🔇 Color detection
|
|
104
|
+
|
|
105
|
+
`supports_color()` decides whether colors should be used, following common CLI conventions:
|
|
106
|
+
|
|
107
|
+
| Situation | Result |
|
|
108
|
+
|-----------|--------|
|
|
109
|
+
| `NO_COLOR` set (any value) — see [no-color.org](https://no-color.org) | plain text |
|
|
110
|
+
| `FORCE_COLOR` set (any value except `0`) | colors |
|
|
111
|
+
| Output is a terminal | colors |
|
|
112
|
+
| Output redirected to a file or piped | plain text |
|
|
113
|
+
|
|
114
|
+
`colorize()` applies this check on every call. For f-strings that use `Color` attributes directly,
|
|
115
|
+
call `Color.auto()` once at start-up and every attribute becomes an empty string when colors are not supported:
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
from shellcolorize import Color
|
|
119
|
+
|
|
120
|
+
def main():
|
|
121
|
+
Color.auto() # respects NO_COLOR / FORCE_COLOR / TTY detection
|
|
122
|
+
print(f"{Color.GREEN}✔ done{Color.RESET}") # plain "✔ done" when piped
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
`Color.disable()` and `Color.enable()` switch colors off and on explicitly (e.g. for a `--no-color` flag).
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
python script.py > output.txt # plain text in the file
|
|
129
|
+
NO_COLOR=1 python script.py # plain text
|
|
130
|
+
FORCE_COLOR=1 python script.py | less -R # keep colors through a pager
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## 🧪 Development
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
pip install -e ".[dev]"
|
|
139
|
+
ruff check .
|
|
140
|
+
pytest
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## 📝 License
|
|
146
|
+
|
|
147
|
+
MIT — see [LICENSE](LICENSE).
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## 💬 Feedback
|
|
152
|
+
|
|
153
|
+
Open an issue or reach out via GitHub.
|
|
154
|
+
|
|
155
|
+
## 🌐 Connect
|
|
156
|
+
|
|
157
|
+
[](https://github.com/serber1990)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "shellcolorize"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Add color and style to terminal output using ANSI codes"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
authors = [{ name = "Serber1990", email = "serber1990@pm.me" }]
|
|
13
|
+
requires-python = ">=3.9"
|
|
14
|
+
keywords = ["ansi", "color", "terminal", "cli", "no-color"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
"Environment :: Console",
|
|
19
|
+
"Topic :: Terminals",
|
|
20
|
+
"Typing :: Typed",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[project.optional-dependencies]
|
|
24
|
+
dev = ["pytest>=7", "ruff>=0.4"]
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Homepage = "https://github.com/serber1990/shell-colorize"
|
|
28
|
+
"Bug Tracker" = "https://github.com/serber1990/shell-colorize/issues"
|
|
29
|
+
"Source Code" = "https://github.com/serber1990/shell-colorize"
|
|
30
|
+
Changelog = "https://github.com/serber1990/shell-colorize/blob/main/CHANGELOG.md"
|
|
31
|
+
|
|
32
|
+
[tool.setuptools]
|
|
33
|
+
packages = ["shellcolorize"]
|
|
34
|
+
|
|
35
|
+
[tool.setuptools.dynamic]
|
|
36
|
+
version = { attr = "shellcolorize.__version__" }
|
|
37
|
+
|
|
38
|
+
[tool.setuptools.package-data]
|
|
39
|
+
shellcolorize = ["py.typed"]
|
|
40
|
+
|
|
41
|
+
[tool.ruff]
|
|
42
|
+
target-version = "py39"
|
|
43
|
+
|
|
44
|
+
[tool.ruff.lint]
|
|
45
|
+
select = ["E9", "F", "B"]
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
__all__ = ["Color", "colorize", "supports_color"]
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def supports_color(stream=None) -> bool:
|
|
8
|
+
"""Return True when ANSI colors should be written to *stream* (default: stdout).
|
|
9
|
+
|
|
10
|
+
Follows the https://no-color.org and ``FORCE_COLOR`` conventions:
|
|
11
|
+
|
|
12
|
+
- ``NO_COLOR`` set to any non-empty value disables color.
|
|
13
|
+
- ``FORCE_COLOR`` set to any non-empty value other than ``0`` enables it.
|
|
14
|
+
- Otherwise color is used only when the stream is an interactive terminal.
|
|
15
|
+
"""
|
|
16
|
+
if os.environ.get("NO_COLOR"):
|
|
17
|
+
return False
|
|
18
|
+
force = os.environ.get("FORCE_COLOR")
|
|
19
|
+
if force and force != "0":
|
|
20
|
+
return True
|
|
21
|
+
stream = sys.stdout if stream is None else stream
|
|
22
|
+
isatty = getattr(stream, "isatty", None)
|
|
23
|
+
try:
|
|
24
|
+
return bool(isatty and isatty())
|
|
25
|
+
except ValueError: # closed stream
|
|
26
|
+
return False
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class Color:
|
|
30
|
+
# ── Text colors ───────────────────────────────────────────────────────────
|
|
31
|
+
BLACK = "\033[30m"
|
|
32
|
+
RED = "\033[31m"
|
|
33
|
+
GREEN = "\033[32m"
|
|
34
|
+
YELLOW = "\033[33m"
|
|
35
|
+
BLUE = "\033[34m"
|
|
36
|
+
MAGENTA = "\033[35m"
|
|
37
|
+
CYAN = "\033[36m"
|
|
38
|
+
WHITE = "\033[37m"
|
|
39
|
+
|
|
40
|
+
# ── Bright text colors ────────────────────────────────────────────────────
|
|
41
|
+
BRIGHT_BLACK = "\033[90m"
|
|
42
|
+
BRIGHT_RED = "\033[91m"
|
|
43
|
+
BRIGHT_GREEN = "\033[92m"
|
|
44
|
+
BRIGHT_YELLOW = "\033[93m"
|
|
45
|
+
BRIGHT_BLUE = "\033[94m"
|
|
46
|
+
BRIGHT_MAGENTA = "\033[95m"
|
|
47
|
+
BRIGHT_CYAN = "\033[96m"
|
|
48
|
+
BRIGHT_WHITE = "\033[97m"
|
|
49
|
+
|
|
50
|
+
# ── Text styles ───────────────────────────────────────────────────────────
|
|
51
|
+
BOLD = "\033[1m"
|
|
52
|
+
DIM = "\033[2m"
|
|
53
|
+
ITALIC = "\033[3m"
|
|
54
|
+
UNDERLINE = "\033[4m"
|
|
55
|
+
BLINK = "\033[5m"
|
|
56
|
+
REVERSE = "\033[7m"
|
|
57
|
+
STRIKETHROUGH = "\033[9m"
|
|
58
|
+
|
|
59
|
+
# ── Background colors ─────────────────────────────────────────────────────
|
|
60
|
+
BG_BLACK = "\033[40m"
|
|
61
|
+
BG_RED = "\033[41m"
|
|
62
|
+
BG_GREEN = "\033[42m"
|
|
63
|
+
BG_YELLOW = "\033[43m"
|
|
64
|
+
BG_BLUE = "\033[44m"
|
|
65
|
+
BG_MAGENTA = "\033[45m"
|
|
66
|
+
BG_CYAN = "\033[46m"
|
|
67
|
+
BG_WHITE = "\033[47m"
|
|
68
|
+
|
|
69
|
+
# ── Bright background colors ──────────────────────────────────────────────
|
|
70
|
+
BG_BRIGHT_BLACK = "\033[100m"
|
|
71
|
+
BG_BRIGHT_RED = "\033[101m"
|
|
72
|
+
BG_BRIGHT_GREEN = "\033[102m"
|
|
73
|
+
BG_BRIGHT_YELLOW = "\033[103m"
|
|
74
|
+
BG_BRIGHT_BLUE = "\033[104m"
|
|
75
|
+
BG_BRIGHT_MAGENTA = "\033[105m"
|
|
76
|
+
BG_BRIGHT_CYAN = "\033[106m"
|
|
77
|
+
BG_BRIGHT_WHITE = "\033[107m"
|
|
78
|
+
|
|
79
|
+
# ── Reset ─────────────────────────────────────────────────────────────────
|
|
80
|
+
RESET = "\033[0m"
|
|
81
|
+
|
|
82
|
+
# ── Global switch ─────────────────────────────────────────────────────────
|
|
83
|
+
|
|
84
|
+
@classmethod
|
|
85
|
+
def disable(cls) -> None:
|
|
86
|
+
"""Turn every attribute into an empty string, so f-strings print plain text."""
|
|
87
|
+
for name in _CODES:
|
|
88
|
+
setattr(cls, name, "")
|
|
89
|
+
|
|
90
|
+
@classmethod
|
|
91
|
+
def enable(cls) -> None:
|
|
92
|
+
"""Restore every attribute to its ANSI escape code."""
|
|
93
|
+
for name, code in _CODES.items():
|
|
94
|
+
setattr(cls, name, code)
|
|
95
|
+
|
|
96
|
+
@classmethod
|
|
97
|
+
def auto(cls, stream=None) -> bool:
|
|
98
|
+
"""Enable or disable colors according to :func:`supports_color`.
|
|
99
|
+
|
|
100
|
+
Call it once at program start-up. Returns whether colors are enabled.
|
|
101
|
+
"""
|
|
102
|
+
enabled = supports_color(stream)
|
|
103
|
+
if enabled:
|
|
104
|
+
cls.enable()
|
|
105
|
+
else:
|
|
106
|
+
cls.disable()
|
|
107
|
+
return enabled
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
_CODES = {name: value for name, value in vars(Color).items() if name.isupper()}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def colorize(text: str, *styles: str) -> str:
|
|
114
|
+
"""Apply one or more Color attributes to text, then reset automatically.
|
|
115
|
+
|
|
116
|
+
Returns plain text unchanged when the terminal does not support color
|
|
117
|
+
(non-TTY output, or the NO_COLOR environment variable is set).
|
|
118
|
+
|
|
119
|
+
Examples:
|
|
120
|
+
colorize("Hello", Color.RED)
|
|
121
|
+
colorize("World", Color.BOLD, Color.UNDERLINE, Color.CYAN)
|
|
122
|
+
colorize("Alert", Color.BG_RED, Color.WHITE, Color.BOLD)
|
|
123
|
+
"""
|
|
124
|
+
if not supports_color():
|
|
125
|
+
return text
|
|
126
|
+
return "".join(styles) + text + Color.RESET
|
|
File without changes
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: shellcolorize
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: Add color and style to terminal output using ANSI codes
|
|
5
|
+
Author-email: Serber1990 <serber1990@pm.me>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/serber1990/shell-colorize
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/serber1990/shell-colorize/issues
|
|
9
|
+
Project-URL: Source Code, https://github.com/serber1990/shell-colorize
|
|
10
|
+
Project-URL: Changelog, https://github.com/serber1990/shell-colorize/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: ansi,color,terminal,cli,no-color
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Environment :: Console
|
|
15
|
+
Classifier: Topic :: Terminals
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Provides-Extra: dev
|
|
21
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
22
|
+
Requires-Dist: ruff>=0.4; extra == "dev"
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# 🌈 `shellcolorize`
|
|
26
|
+
|
|
27
|
+
[](https://github.com/serber1990/shell-colorize/actions/workflows/ci.yml)
|
|
28
|
+
[](https://badge.fury.io/py/shellcolorize)
|
|
29
|
+
[](https://opensource.org/licenses/MIT)
|
|
30
|
+
[](https://github.com/serber1990/shell-colorize/stargazers)
|
|
31
|
+
|
|
32
|
+
**`shellcolorize`** is a lightweight Python library for adding color and style to terminal output using ANSI codes. Zero dependencies, no configuration — just import and use.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## ✨ Features
|
|
37
|
+
|
|
38
|
+
- 🎨 **Full ANSI palette** — 8 standard + 8 bright text colors, same for backgrounds.
|
|
39
|
+
- ✍️ **Text styles** — bold, dim, italic, underline, blink, reverse, strikethrough.
|
|
40
|
+
- 🛠 **`colorize()` helper** — applies styles and resets automatically, no manual `RESET` needed.
|
|
41
|
+
- 🔇 **Smart color detection** — plain text when piped to a file, honours [`NO_COLOR`](https://no-color.org) and `FORCE_COLOR`.
|
|
42
|
+
- 🔌 **Global on/off switch** — `Color.auto()` / `Color.disable()` make every f-string plain text in one call.
|
|
43
|
+
- 🔗 **Open Source** — MIT License.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## 📥 Installation
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install shellcolorize
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## 🛠 Usage
|
|
56
|
+
|
|
57
|
+
### Using `colorize()` (recommended)
|
|
58
|
+
|
|
59
|
+
`colorize(text, *styles)` applies any combination of colors and styles and resets automatically. It also returns plain text when the output is not a TTY or when the `NO_COLOR` env var is set.
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from shellcolorize import Color, colorize
|
|
63
|
+
|
|
64
|
+
print(colorize("This is red", Color.RED))
|
|
65
|
+
print(colorize("Bold and underlined", Color.BOLD, Color.UNDERLINE))
|
|
66
|
+
print(colorize("White on blue background", Color.BG_BLUE, Color.WHITE))
|
|
67
|
+
print(colorize("Bright green, bold", Color.BRIGHT_GREEN, Color.BOLD))
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Using `Color` attributes directly
|
|
71
|
+
|
|
72
|
+
For inline use in f-strings. Remember to close with `Color.RESET`.
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
from shellcolorize import Color
|
|
76
|
+
|
|
77
|
+
print(f"{Color.RED}This is red{Color.RESET}")
|
|
78
|
+
print(f"{Color.BG_YELLOW}{Color.BLACK}Black on yellow{Color.RESET}")
|
|
79
|
+
print(f"{Color.BOLD}{Color.CYAN}Bold cyan{Color.RESET}")
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## 🎨 Available Colors
|
|
85
|
+
|
|
86
|
+
### Standard text colors
|
|
87
|
+
|
|
88
|
+
| Attribute | Attribute |
|
|
89
|
+
|-----------|-----------|
|
|
90
|
+
| `Color.BLACK` | `Color.BRIGHT_BLACK` |
|
|
91
|
+
| `Color.RED` | `Color.BRIGHT_RED` |
|
|
92
|
+
| `Color.GREEN` | `Color.BRIGHT_GREEN` |
|
|
93
|
+
| `Color.YELLOW` | `Color.BRIGHT_YELLOW` |
|
|
94
|
+
| `Color.BLUE` | `Color.BRIGHT_BLUE` |
|
|
95
|
+
| `Color.MAGENTA` | `Color.BRIGHT_MAGENTA` |
|
|
96
|
+
| `Color.CYAN` | `Color.BRIGHT_CYAN` |
|
|
97
|
+
| `Color.WHITE` | `Color.BRIGHT_WHITE` |
|
|
98
|
+
|
|
99
|
+
### Background colors
|
|
100
|
+
|
|
101
|
+
| Attribute | Attribute |
|
|
102
|
+
|-----------|-----------|
|
|
103
|
+
| `Color.BG_BLACK` | `Color.BG_BRIGHT_BLACK` |
|
|
104
|
+
| `Color.BG_RED` | `Color.BG_BRIGHT_RED` |
|
|
105
|
+
| `Color.BG_GREEN` | `Color.BG_BRIGHT_GREEN` |
|
|
106
|
+
| `Color.BG_YELLOW` | `Color.BG_BRIGHT_YELLOW` |
|
|
107
|
+
| `Color.BG_BLUE` | `Color.BG_BRIGHT_BLUE` |
|
|
108
|
+
| `Color.BG_MAGENTA` | `Color.BG_BRIGHT_MAGENTA` |
|
|
109
|
+
| `Color.BG_CYAN` | `Color.BG_BRIGHT_CYAN` |
|
|
110
|
+
| `Color.BG_WHITE` | `Color.BG_BRIGHT_WHITE` |
|
|
111
|
+
|
|
112
|
+
### Text styles
|
|
113
|
+
|
|
114
|
+
| Attribute | Effect |
|
|
115
|
+
|-----------|--------|
|
|
116
|
+
| `Color.BOLD` | **Bold** |
|
|
117
|
+
| `Color.DIM` | Dimmed |
|
|
118
|
+
| `Color.ITALIC` | *Italic* |
|
|
119
|
+
| `Color.UNDERLINE` | Underline |
|
|
120
|
+
| `Color.BLINK` | Blinking |
|
|
121
|
+
| `Color.REVERSE` | Swaps fg/bg colors |
|
|
122
|
+
| `Color.STRIKETHROUGH` | ~~Strikethrough~~ |
|
|
123
|
+
| `Color.RESET` | Clears all styles |
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## 🔇 Color detection
|
|
128
|
+
|
|
129
|
+
`supports_color()` decides whether colors should be used, following common CLI conventions:
|
|
130
|
+
|
|
131
|
+
| Situation | Result |
|
|
132
|
+
|-----------|--------|
|
|
133
|
+
| `NO_COLOR` set (any value) — see [no-color.org](https://no-color.org) | plain text |
|
|
134
|
+
| `FORCE_COLOR` set (any value except `0`) | colors |
|
|
135
|
+
| Output is a terminal | colors |
|
|
136
|
+
| Output redirected to a file or piped | plain text |
|
|
137
|
+
|
|
138
|
+
`colorize()` applies this check on every call. For f-strings that use `Color` attributes directly,
|
|
139
|
+
call `Color.auto()` once at start-up and every attribute becomes an empty string when colors are not supported:
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
from shellcolorize import Color
|
|
143
|
+
|
|
144
|
+
def main():
|
|
145
|
+
Color.auto() # respects NO_COLOR / FORCE_COLOR / TTY detection
|
|
146
|
+
print(f"{Color.GREEN}✔ done{Color.RESET}") # plain "✔ done" when piped
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
`Color.disable()` and `Color.enable()` switch colors off and on explicitly (e.g. for a `--no-color` flag).
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
python script.py > output.txt # plain text in the file
|
|
153
|
+
NO_COLOR=1 python script.py # plain text
|
|
154
|
+
FORCE_COLOR=1 python script.py | less -R # keep colors through a pager
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## 🧪 Development
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
pip install -e ".[dev]"
|
|
163
|
+
ruff check .
|
|
164
|
+
pytest
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## 📝 License
|
|
170
|
+
|
|
171
|
+
MIT — see [LICENSE](LICENSE).
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## 💬 Feedback
|
|
176
|
+
|
|
177
|
+
Open an issue or reach out via GitHub.
|
|
178
|
+
|
|
179
|
+
## 🌐 Connect
|
|
180
|
+
|
|
181
|
+
[](https://github.com/serber1990)
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
LICENSE
|
|
1
2
|
README.md
|
|
2
|
-
|
|
3
|
+
pyproject.toml
|
|
3
4
|
shellcolorize/__init__.py
|
|
4
5
|
shellcolorize/color.py
|
|
6
|
+
shellcolorize/py.typed
|
|
5
7
|
shellcolorize.egg-info/PKG-INFO
|
|
6
8
|
shellcolorize.egg-info/SOURCES.txt
|
|
7
9
|
shellcolorize.egg-info/dependency_links.txt
|
|
8
|
-
shellcolorize.egg-info/
|
|
10
|
+
shellcolorize.egg-info/requires.txt
|
|
11
|
+
shellcolorize.egg-info/top_level.txt
|
|
12
|
+
tests/test_color.py
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import io
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from shellcolorize import Color, colorize, supports_color
|
|
6
|
+
from shellcolorize.color import _CODES
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class FakeTTY(io.StringIO):
|
|
10
|
+
def isatty(self):
|
|
11
|
+
return True
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@pytest.fixture(autouse=True)
|
|
15
|
+
def clean_env(monkeypatch):
|
|
16
|
+
monkeypatch.delenv("NO_COLOR", raising=False)
|
|
17
|
+
monkeypatch.delenv("FORCE_COLOR", raising=False)
|
|
18
|
+
yield
|
|
19
|
+
Color.enable()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_codes_are_ansi_sequences():
|
|
23
|
+
assert Color.RED == "\033[31m"
|
|
24
|
+
assert Color.BG_BRIGHT_WHITE == "\033[107m"
|
|
25
|
+
assert Color.RESET == "\033[0m"
|
|
26
|
+
assert all(code.startswith("\033[") and code.endswith("m") for code in _CODES.values())
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def test_supports_color_follows_tty():
|
|
30
|
+
assert supports_color(FakeTTY()) is True
|
|
31
|
+
assert supports_color(io.StringIO()) is False
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_no_color_wins_over_tty(monkeypatch):
|
|
35
|
+
monkeypatch.setenv("NO_COLOR", "1")
|
|
36
|
+
assert supports_color(FakeTTY()) is False
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_force_color_enables_without_tty(monkeypatch):
|
|
40
|
+
monkeypatch.setenv("FORCE_COLOR", "1")
|
|
41
|
+
assert supports_color(io.StringIO()) is True
|
|
42
|
+
monkeypatch.setenv("FORCE_COLOR", "0")
|
|
43
|
+
assert supports_color(io.StringIO()) is False
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def test_closed_stream_does_not_raise():
|
|
47
|
+
stream = io.StringIO()
|
|
48
|
+
stream.close()
|
|
49
|
+
assert supports_color(stream) is False
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_disable_and_enable_roundtrip():
|
|
53
|
+
Color.disable()
|
|
54
|
+
assert Color.RED == "" and Color.RESET == ""
|
|
55
|
+
assert f"{Color.BOLD}text{Color.RESET}" == "text"
|
|
56
|
+
Color.enable()
|
|
57
|
+
assert Color.RED == "\033[31m"
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_auto_matches_stream():
|
|
61
|
+
assert Color.auto(io.StringIO()) is False
|
|
62
|
+
assert Color.GREEN == ""
|
|
63
|
+
assert Color.auto(FakeTTY()) is True
|
|
64
|
+
assert Color.GREEN == "\033[32m"
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def test_colorize_plain_when_not_supported(monkeypatch):
|
|
68
|
+
monkeypatch.setenv("NO_COLOR", "1")
|
|
69
|
+
assert colorize("hi", Color.RED) == "hi"
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def test_colorize_wraps_and_resets(monkeypatch):
|
|
73
|
+
monkeypatch.setenv("FORCE_COLOR", "1")
|
|
74
|
+
assert colorize("hi", Color.BOLD, Color.RED) == "\033[1m\033[31mhi\033[0m"
|
shellcolorize-0.3/PKG-INFO
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: shellcolorize
|
|
3
|
-
Version: 0.3
|
|
4
|
-
Summary: Add color to Linux CLI shell terminal output in ANSI
|
|
5
|
-
Home-page: https://github.com/serber1990/shell-colorize
|
|
6
|
-
Author: Serber1990
|
|
7
|
-
Author-email: serber1990@pm.me
|
|
8
|
-
Project-URL: Bug Tracker, https://github.com/serber1990/shell-colorize/issues
|
|
9
|
-
Project-URL: Documentation, https://github.com/serber1990/shell-colorize
|
|
10
|
-
Project-URL: Source Code, https://github.com/serber1990/shell-colorize
|
|
11
|
-
Classifier: Programming Language :: Python :: 3
|
|
12
|
-
Classifier: Operating System :: OS Independent
|
|
13
|
-
Requires-Python: >=3.6
|
|
14
|
-
Description-Content-Type: text/markdown
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
# 🌈 `shellcolorize`
|
|
18
|
-
|
|
19
|
-
[](https://badge.fury.io/py/shellcolorize)
|
|
20
|
-
[](https://opensource.org/licenses/MIT)
|
|
21
|
-
[](https://github.com/serber1990/shellcolorize/stargazers)
|
|
22
|
-
|
|
23
|
-
**`shellcolorize`** is a lightweight Python library for adding color to terminal text using ANSI color codes. This library makes it easy to style your command-line output with vibrant colors and backgrounds, perfect for enhancing readability and making CLI applications more visually appealing.
|
|
24
|
-
|
|
25
|
-
---
|
|
26
|
-
|
|
27
|
-
## ✨ Features
|
|
28
|
-
|
|
29
|
-
- 🌈 **Wide Range of Colors**: Includes standard text and background colors.
|
|
30
|
-
- 🚀 **Easy to Use**: Simple and intuitive API to add color to terminal text.
|
|
31
|
-
- 💡 **ANSI Standard**: Uses ANSI color codes, compatible with most Unix-based terminals and compatible environments.
|
|
32
|
-
- 🔗 **Open Source**: Licensed under the MIT License.
|
|
33
|
-
|
|
34
|
-
---
|
|
35
|
-
|
|
36
|
-
## 📥 Installation
|
|
37
|
-
|
|
38
|
-
Install `shellcolorize` from PyPI:
|
|
39
|
-
|
|
40
|
-
```bash
|
|
41
|
-
pip install shellcolorize
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
---
|
|
45
|
-
|
|
46
|
-
## 🛠 Usage
|
|
47
|
-
|
|
48
|
-
`shellcolorize` makes it easy to color your terminal text. Import `Color` from `shellcolorize` and use the color attributes as shown below.
|
|
49
|
-
|
|
50
|
-
### Basic Usage
|
|
51
|
-
```python
|
|
52
|
-
from shellcolorize import Color
|
|
53
|
-
|
|
54
|
-
print(f"{Color.RED}This is red text{Color.RESET}")
|
|
55
|
-
print(f"{Color.GREEN}This is green text{Color.RESET}")
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
### Using Background Colors
|
|
59
|
-
```python
|
|
60
|
-
from shellcolorize import Color
|
|
61
|
-
|
|
62
|
-
print(f"{Color.BG_YELLOW}{Color.BLACK}Black text on yellow background{Color.RESET}")
|
|
63
|
-
print(f"{Color.BG_BLUE}{Color.WHITE}White text on blue background{Color.RESET}")
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
### Combining Text and Background Colors
|
|
67
|
-
```python
|
|
68
|
-
from shellcolorize import Color
|
|
69
|
-
|
|
70
|
-
print(f"{Color.BG_RED}{Color.CYAN}Cyan text on red background{Color.RESET}")
|
|
71
|
-
print(f"{Color.BG_GREEN}{Color.MAGENTA}Magenta text on green background{Color.RESET}")
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
---
|
|
75
|
-
|
|
76
|
-
## 🎨 Available Colors
|
|
77
|
-
|
|
78
|
-
### Text Colors
|
|
79
|
-
|
|
80
|
-
| Color | Usage Example |
|
|
81
|
-
|-------|------------------------------|
|
|
82
|
-
| Black | `{Color.BLACK}Text{Color.RESET}` |
|
|
83
|
-
| Red | `{Color.RED}Text{Color.RESET}` |
|
|
84
|
-
| Green | `{Color.GREEN}Text{Color.RESET}` |
|
|
85
|
-
| Yellow| `{Color.YELLOW}Text{Color.RESET}` |
|
|
86
|
-
| Blue | `{Color.BLUE}Text{Color.RESET}` |
|
|
87
|
-
| Magenta | `{Color.MAGENTA}Text{Color.RESET}` |
|
|
88
|
-
| Cyan | `{Color.CYAN}Text{Color.RESET}` |
|
|
89
|
-
| White | `{Color.WHITE}Text{Color.RESET}` |
|
|
90
|
-
|
|
91
|
-
### Background Colors
|
|
92
|
-
|
|
93
|
-
| Color | Usage Example |
|
|
94
|
-
|-------------|--------------------------------------|
|
|
95
|
-
| Black | `{Color.BG_BLACK}Text{Color.RESET}` |
|
|
96
|
-
| Red | `{Color.BG_RED}Text{Color.RESET}` |
|
|
97
|
-
| Green | `{Color.BG_GREEN}Text{Color.RESET}` |
|
|
98
|
-
| Yellow | `{Color.BG_YELLOW}Text{Color.RESET}` |
|
|
99
|
-
| Blue | `{Color.BG_BLUE}Text{Color.RESET}` |
|
|
100
|
-
| Magenta | `{Color.BG_MAGENTA}Text{Color.RESET}`|
|
|
101
|
-
| Cyan | `{Color.BG_CYAN}Text{Color.RESET}` |
|
|
102
|
-
| White | `{Color.BG_WHITE}Text{Color.RESET}` |
|
|
103
|
-
|
|
104
|
-
---
|
|
105
|
-
|
|
106
|
-
## 📝 License
|
|
107
|
-
|
|
108
|
-
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
109
|
-
|
|
110
|
-
---
|
|
111
|
-
|
|
112
|
-
## 💬 Feedback
|
|
113
|
-
|
|
114
|
-
If you have any questions, issues, or suggestions, please feel free to open an issue in the repository or contact me directly via GitHub.
|
|
115
|
-
|
|
116
|
-
---
|
|
117
|
-
|
|
118
|
-
## 🌐 Connect with Me
|
|
119
|
-
|
|
120
|
-
[](https://github.com/serber1990)
|
|
121
|
-
|
|
122
|
-
---
|
|
123
|
-
|
|
124
|
-
### 🚀 Let's bring more color to the command line with `shellcolorize`!
|
shellcolorize-0.3/README.md
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
# 🌈 `shellcolorize`
|
|
3
|
-
|
|
4
|
-
[](https://badge.fury.io/py/shellcolorize)
|
|
5
|
-
[](https://opensource.org/licenses/MIT)
|
|
6
|
-
[](https://github.com/serber1990/shellcolorize/stargazers)
|
|
7
|
-
|
|
8
|
-
**`shellcolorize`** is a lightweight Python library for adding color to terminal text using ANSI color codes. This library makes it easy to style your command-line output with vibrant colors and backgrounds, perfect for enhancing readability and making CLI applications more visually appealing.
|
|
9
|
-
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
## ✨ Features
|
|
13
|
-
|
|
14
|
-
- 🌈 **Wide Range of Colors**: Includes standard text and background colors.
|
|
15
|
-
- 🚀 **Easy to Use**: Simple and intuitive API to add color to terminal text.
|
|
16
|
-
- 💡 **ANSI Standard**: Uses ANSI color codes, compatible with most Unix-based terminals and compatible environments.
|
|
17
|
-
- 🔗 **Open Source**: Licensed under the MIT License.
|
|
18
|
-
|
|
19
|
-
---
|
|
20
|
-
|
|
21
|
-
## 📥 Installation
|
|
22
|
-
|
|
23
|
-
Install `shellcolorize` from PyPI:
|
|
24
|
-
|
|
25
|
-
```bash
|
|
26
|
-
pip install shellcolorize
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
---
|
|
30
|
-
|
|
31
|
-
## 🛠 Usage
|
|
32
|
-
|
|
33
|
-
`shellcolorize` makes it easy to color your terminal text. Import `Color` from `shellcolorize` and use the color attributes as shown below.
|
|
34
|
-
|
|
35
|
-
### Basic Usage
|
|
36
|
-
```python
|
|
37
|
-
from shellcolorize import Color
|
|
38
|
-
|
|
39
|
-
print(f"{Color.RED}This is red text{Color.RESET}")
|
|
40
|
-
print(f"{Color.GREEN}This is green text{Color.RESET}")
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
### Using Background Colors
|
|
44
|
-
```python
|
|
45
|
-
from shellcolorize import Color
|
|
46
|
-
|
|
47
|
-
print(f"{Color.BG_YELLOW}{Color.BLACK}Black text on yellow background{Color.RESET}")
|
|
48
|
-
print(f"{Color.BG_BLUE}{Color.WHITE}White text on blue background{Color.RESET}")
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### Combining Text and Background Colors
|
|
52
|
-
```python
|
|
53
|
-
from shellcolorize import Color
|
|
54
|
-
|
|
55
|
-
print(f"{Color.BG_RED}{Color.CYAN}Cyan text on red background{Color.RESET}")
|
|
56
|
-
print(f"{Color.BG_GREEN}{Color.MAGENTA}Magenta text on green background{Color.RESET}")
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
---
|
|
60
|
-
|
|
61
|
-
## 🎨 Available Colors
|
|
62
|
-
|
|
63
|
-
### Text Colors
|
|
64
|
-
|
|
65
|
-
| Color | Usage Example |
|
|
66
|
-
|-------|------------------------------|
|
|
67
|
-
| Black | `{Color.BLACK}Text{Color.RESET}` |
|
|
68
|
-
| Red | `{Color.RED}Text{Color.RESET}` |
|
|
69
|
-
| Green | `{Color.GREEN}Text{Color.RESET}` |
|
|
70
|
-
| Yellow| `{Color.YELLOW}Text{Color.RESET}` |
|
|
71
|
-
| Blue | `{Color.BLUE}Text{Color.RESET}` |
|
|
72
|
-
| Magenta | `{Color.MAGENTA}Text{Color.RESET}` |
|
|
73
|
-
| Cyan | `{Color.CYAN}Text{Color.RESET}` |
|
|
74
|
-
| White | `{Color.WHITE}Text{Color.RESET}` |
|
|
75
|
-
|
|
76
|
-
### Background Colors
|
|
77
|
-
|
|
78
|
-
| Color | Usage Example |
|
|
79
|
-
|-------------|--------------------------------------|
|
|
80
|
-
| Black | `{Color.BG_BLACK}Text{Color.RESET}` |
|
|
81
|
-
| Red | `{Color.BG_RED}Text{Color.RESET}` |
|
|
82
|
-
| Green | `{Color.BG_GREEN}Text{Color.RESET}` |
|
|
83
|
-
| Yellow | `{Color.BG_YELLOW}Text{Color.RESET}` |
|
|
84
|
-
| Blue | `{Color.BG_BLUE}Text{Color.RESET}` |
|
|
85
|
-
| Magenta | `{Color.BG_MAGENTA}Text{Color.RESET}`|
|
|
86
|
-
| Cyan | `{Color.BG_CYAN}Text{Color.RESET}` |
|
|
87
|
-
| White | `{Color.BG_WHITE}Text{Color.RESET}` |
|
|
88
|
-
|
|
89
|
-
---
|
|
90
|
-
|
|
91
|
-
## 📝 License
|
|
92
|
-
|
|
93
|
-
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
94
|
-
|
|
95
|
-
---
|
|
96
|
-
|
|
97
|
-
## 💬 Feedback
|
|
98
|
-
|
|
99
|
-
If you have any questions, issues, or suggestions, please feel free to open an issue in the repository or contact me directly via GitHub.
|
|
100
|
-
|
|
101
|
-
---
|
|
102
|
-
|
|
103
|
-
## 🌐 Connect with Me
|
|
104
|
-
|
|
105
|
-
[](https://github.com/serber1990)
|
|
106
|
-
|
|
107
|
-
---
|
|
108
|
-
|
|
109
|
-
### 🚀 Let's bring more color to the command line with `shellcolorize`!
|
shellcolorize-0.3/setup.py
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
from setuptools import setup, find_packages
|
|
2
|
-
|
|
3
|
-
setup(
|
|
4
|
-
name="shellcolorize",
|
|
5
|
-
version="0.3",
|
|
6
|
-
description="Add color to Linux CLI shell terminal output in ANSI",
|
|
7
|
-
long_description=open("README.md").read(),
|
|
8
|
-
long_description_content_type="text/markdown",
|
|
9
|
-
author="Serber1990",
|
|
10
|
-
author_email="serber1990@pm.me",
|
|
11
|
-
url="https://github.com/serber1990/shell-colorize", # Link to your GitHub repository
|
|
12
|
-
project_urls={
|
|
13
|
-
"Bug Tracker": "https://github.com/serber1990/shell-colorize/issues",
|
|
14
|
-
"Documentation": "https://github.com/serber1990/shell-colorize",
|
|
15
|
-
"Source Code": "https://github.com/serber1990/shell-colorize",
|
|
16
|
-
},
|
|
17
|
-
packages=find_packages(),
|
|
18
|
-
classifiers=[
|
|
19
|
-
"Programming Language :: Python :: 3",
|
|
20
|
-
"Operating System :: OS Independent",
|
|
21
|
-
],
|
|
22
|
-
python_requires=">=3.6",
|
|
23
|
-
)
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# color.py
|
|
2
|
-
|
|
3
|
-
class Color:
|
|
4
|
-
# Text colors
|
|
5
|
-
BLACK = "\033[30m"
|
|
6
|
-
RED = "\033[31m"
|
|
7
|
-
GREEN = "\033[32m"
|
|
8
|
-
YELLOW = "\033[33m"
|
|
9
|
-
BLUE = "\033[34m"
|
|
10
|
-
MAGENTA = "\033[35m"
|
|
11
|
-
CYAN = "\033[36m"
|
|
12
|
-
WHITE = "\033[37m"
|
|
13
|
-
RESET = "\033[0m"
|
|
14
|
-
|
|
15
|
-
# Background colors
|
|
16
|
-
BG_BLACK = "\033[40m"
|
|
17
|
-
BG_RED = "\033[41m"
|
|
18
|
-
BG_GREEN = "\033[42m"
|
|
19
|
-
BG_YELLOW = "\033[43m"
|
|
20
|
-
BG_BLUE = "\033[44m"
|
|
21
|
-
BG_MAGENTA = "\033[45m"
|
|
22
|
-
BG_CYAN = "\033[46m"
|
|
23
|
-
BG_WHITE = "\033[47m"
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: shellcolorize
|
|
3
|
-
Version: 0.3
|
|
4
|
-
Summary: Add color to Linux CLI shell terminal output in ANSI
|
|
5
|
-
Home-page: https://github.com/serber1990/shell-colorize
|
|
6
|
-
Author: Serber1990
|
|
7
|
-
Author-email: serber1990@pm.me
|
|
8
|
-
Project-URL: Bug Tracker, https://github.com/serber1990/shell-colorize/issues
|
|
9
|
-
Project-URL: Documentation, https://github.com/serber1990/shell-colorize
|
|
10
|
-
Project-URL: Source Code, https://github.com/serber1990/shell-colorize
|
|
11
|
-
Classifier: Programming Language :: Python :: 3
|
|
12
|
-
Classifier: Operating System :: OS Independent
|
|
13
|
-
Requires-Python: >=3.6
|
|
14
|
-
Description-Content-Type: text/markdown
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
# 🌈 `shellcolorize`
|
|
18
|
-
|
|
19
|
-
[](https://badge.fury.io/py/shellcolorize)
|
|
20
|
-
[](https://opensource.org/licenses/MIT)
|
|
21
|
-
[](https://github.com/serber1990/shellcolorize/stargazers)
|
|
22
|
-
|
|
23
|
-
**`shellcolorize`** is a lightweight Python library for adding color to terminal text using ANSI color codes. This library makes it easy to style your command-line output with vibrant colors and backgrounds, perfect for enhancing readability and making CLI applications more visually appealing.
|
|
24
|
-
|
|
25
|
-
---
|
|
26
|
-
|
|
27
|
-
## ✨ Features
|
|
28
|
-
|
|
29
|
-
- 🌈 **Wide Range of Colors**: Includes standard text and background colors.
|
|
30
|
-
- 🚀 **Easy to Use**: Simple and intuitive API to add color to terminal text.
|
|
31
|
-
- 💡 **ANSI Standard**: Uses ANSI color codes, compatible with most Unix-based terminals and compatible environments.
|
|
32
|
-
- 🔗 **Open Source**: Licensed under the MIT License.
|
|
33
|
-
|
|
34
|
-
---
|
|
35
|
-
|
|
36
|
-
## 📥 Installation
|
|
37
|
-
|
|
38
|
-
Install `shellcolorize` from PyPI:
|
|
39
|
-
|
|
40
|
-
```bash
|
|
41
|
-
pip install shellcolorize
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
---
|
|
45
|
-
|
|
46
|
-
## 🛠 Usage
|
|
47
|
-
|
|
48
|
-
`shellcolorize` makes it easy to color your terminal text. Import `Color` from `shellcolorize` and use the color attributes as shown below.
|
|
49
|
-
|
|
50
|
-
### Basic Usage
|
|
51
|
-
```python
|
|
52
|
-
from shellcolorize import Color
|
|
53
|
-
|
|
54
|
-
print(f"{Color.RED}This is red text{Color.RESET}")
|
|
55
|
-
print(f"{Color.GREEN}This is green text{Color.RESET}")
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
### Using Background Colors
|
|
59
|
-
```python
|
|
60
|
-
from shellcolorize import Color
|
|
61
|
-
|
|
62
|
-
print(f"{Color.BG_YELLOW}{Color.BLACK}Black text on yellow background{Color.RESET}")
|
|
63
|
-
print(f"{Color.BG_BLUE}{Color.WHITE}White text on blue background{Color.RESET}")
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
### Combining Text and Background Colors
|
|
67
|
-
```python
|
|
68
|
-
from shellcolorize import Color
|
|
69
|
-
|
|
70
|
-
print(f"{Color.BG_RED}{Color.CYAN}Cyan text on red background{Color.RESET}")
|
|
71
|
-
print(f"{Color.BG_GREEN}{Color.MAGENTA}Magenta text on green background{Color.RESET}")
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
---
|
|
75
|
-
|
|
76
|
-
## 🎨 Available Colors
|
|
77
|
-
|
|
78
|
-
### Text Colors
|
|
79
|
-
|
|
80
|
-
| Color | Usage Example |
|
|
81
|
-
|-------|------------------------------|
|
|
82
|
-
| Black | `{Color.BLACK}Text{Color.RESET}` |
|
|
83
|
-
| Red | `{Color.RED}Text{Color.RESET}` |
|
|
84
|
-
| Green | `{Color.GREEN}Text{Color.RESET}` |
|
|
85
|
-
| Yellow| `{Color.YELLOW}Text{Color.RESET}` |
|
|
86
|
-
| Blue | `{Color.BLUE}Text{Color.RESET}` |
|
|
87
|
-
| Magenta | `{Color.MAGENTA}Text{Color.RESET}` |
|
|
88
|
-
| Cyan | `{Color.CYAN}Text{Color.RESET}` |
|
|
89
|
-
| White | `{Color.WHITE}Text{Color.RESET}` |
|
|
90
|
-
|
|
91
|
-
### Background Colors
|
|
92
|
-
|
|
93
|
-
| Color | Usage Example |
|
|
94
|
-
|-------------|--------------------------------------|
|
|
95
|
-
| Black | `{Color.BG_BLACK}Text{Color.RESET}` |
|
|
96
|
-
| Red | `{Color.BG_RED}Text{Color.RESET}` |
|
|
97
|
-
| Green | `{Color.BG_GREEN}Text{Color.RESET}` |
|
|
98
|
-
| Yellow | `{Color.BG_YELLOW}Text{Color.RESET}` |
|
|
99
|
-
| Blue | `{Color.BG_BLUE}Text{Color.RESET}` |
|
|
100
|
-
| Magenta | `{Color.BG_MAGENTA}Text{Color.RESET}`|
|
|
101
|
-
| Cyan | `{Color.BG_CYAN}Text{Color.RESET}` |
|
|
102
|
-
| White | `{Color.BG_WHITE}Text{Color.RESET}` |
|
|
103
|
-
|
|
104
|
-
---
|
|
105
|
-
|
|
106
|
-
## 📝 License
|
|
107
|
-
|
|
108
|
-
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
109
|
-
|
|
110
|
-
---
|
|
111
|
-
|
|
112
|
-
## 💬 Feedback
|
|
113
|
-
|
|
114
|
-
If you have any questions, issues, or suggestions, please feel free to open an issue in the repository or contact me directly via GitHub.
|
|
115
|
-
|
|
116
|
-
---
|
|
117
|
-
|
|
118
|
-
## 🌐 Connect with Me
|
|
119
|
-
|
|
120
|
-
[](https://github.com/serber1990)
|
|
121
|
-
|
|
122
|
-
---
|
|
123
|
-
|
|
124
|
-
### 🚀 Let's bring more color to the command line with `shellcolorize`!
|
|
File without changes
|
|
File without changes
|
|
File without changes
|