colrs 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.
- colrs-0.1.0/PKG-INFO +148 -0
- colrs-0.1.0/README.md +114 -0
- colrs-0.1.0/colrs/__init__.py +22 -0
- colrs-0.1.0/colrs/core.py +116 -0
- colrs-0.1.0/colrs/magic.py +64 -0
- colrs-0.1.0/colrs.egg-info/PKG-INFO +148 -0
- colrs-0.1.0/colrs.egg-info/SOURCES.txt +10 -0
- colrs-0.1.0/colrs.egg-info/dependency_links.txt +1 -0
- colrs-0.1.0/colrs.egg-info/requires.txt +1 -0
- colrs-0.1.0/colrs.egg-info/top_level.txt +1 -0
- colrs-0.1.0/setup.cfg +4 -0
- colrs-0.1.0/setup.py +38 -0
colrs-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: colrs
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A simple and elegant Python library for terminal text coloring.
|
|
5
|
+
Home-page: https://github.com/kalth/colrs
|
|
6
|
+
Author: hussain_syrer
|
|
7
|
+
Author-email: h2311065@gmail.com
|
|
8
|
+
Keywords: color terminal ansi text style coloring cli print input
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Topic :: Terminals
|
|
20
|
+
Classifier: Topic :: Utilities
|
|
21
|
+
Requires-Python: >=3.7
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
Requires-Dist: colorama
|
|
24
|
+
Dynamic: author
|
|
25
|
+
Dynamic: author-email
|
|
26
|
+
Dynamic: classifier
|
|
27
|
+
Dynamic: description
|
|
28
|
+
Dynamic: description-content-type
|
|
29
|
+
Dynamic: home-page
|
|
30
|
+
Dynamic: keywords
|
|
31
|
+
Dynamic: requires-dist
|
|
32
|
+
Dynamic: requires-python
|
|
33
|
+
Dynamic: summary
|
|
34
|
+
|
|
35
|
+
# colorara 🎨
|
|
36
|
+
|
|
37
|
+
A simple, elegant, and easy-to-use Python library to add color to your terminal text and backgrounds.
|
|
38
|
+
|
|
39
|
+
## Features
|
|
40
|
+
|
|
41
|
+
- **Simple API:** Color your text with zero hassle.
|
|
42
|
+
- **Cross-Platform:** Works on Windows, macOS, and Linux thanks to `colorama`.
|
|
43
|
+
- **Inline Tag Coloring:** Color specific words within a string using simple tags like `<green>word</>`.
|
|
44
|
+
- **Colored User Input:** Control the color of the user's typed text in `input()` prompts.
|
|
45
|
+
- **"Magic":** An optional mode to make the built-in `print()` and `input()` color-aware.
|
|
46
|
+
- **Lightweight:** Has only one dependency (`colorama`) for cross-platform support.
|
|
47
|
+
|
|
48
|
+
## Installation
|
|
49
|
+
|
|
50
|
+
First, navigate to the `colorara` project directory. Then, install it using `pip`:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install .
|
|
54
|
+
```
|
|
55
|
+
After installation, you can import it in any Python script on your system.
|
|
56
|
+
|
|
57
|
+
## Usage
|
|
58
|
+
|
|
59
|
+
`colorara` is designed for flexibility and ease of use.
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
### `cprint()` and Inline Coloring
|
|
64
|
+
|
|
65
|
+
The `cprint()` function is your main tool for printing. It supports both coloring the entire line and coloring specific parts of a string using tags.
|
|
66
|
+
|
|
67
|
+
**Syntax:** `<color_name>text</>` or `<text_color,bg_color>text</>`
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from colorara import cprint
|
|
71
|
+
|
|
72
|
+
# Overall coloring (like before)
|
|
73
|
+
cprint("This entire line is green.", color="green")
|
|
74
|
+
|
|
75
|
+
# --- Inline Tag Coloring ---
|
|
76
|
+
# Color a specific word
|
|
77
|
+
cprint("Status: <green>OK</>")
|
|
78
|
+
|
|
79
|
+
# Use multiple colors in one line
|
|
80
|
+
cprint("Results: <green>SUCCESS</>, Warnings: <yellow>3</>, Errors: <red>0</>")
|
|
81
|
+
|
|
82
|
+
# You can also color backgrounds
|
|
83
|
+
cprint("System State: <white,bg_green>ONLINE</>")
|
|
84
|
+
cprint("Alert: <black,bg_yellow>CHECK CONFIG</>")
|
|
85
|
+
|
|
86
|
+
# If you provide a `color` argument with tags, it is ignored
|
|
87
|
+
cprint("The tag <green>always</> wins.", color="red") # "always" will be green
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### `cinput()` and Colored User Input
|
|
91
|
+
|
|
92
|
+
Use `cinput()` to get user input with a colored prompt and even colored user-typed text.
|
|
93
|
+
|
|
94
|
+
It accepts a new argument `inp_color`. If you provide it, the user's typing will be in that color. If you don't, the user's typing will have the same color as the prompt.
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from colorara import cinput
|
|
98
|
+
|
|
99
|
+
# The user's typed text will be cyan, just like the prompt
|
|
100
|
+
name = cinput("Enter your name: ", color="cyan")
|
|
101
|
+
print(f"Hello, {name}!")
|
|
102
|
+
|
|
103
|
+
# The prompt will be yellow, but the user's typing will be blue
|
|
104
|
+
age = cinput("Enter your age: ", color="yellow", inp_color="blue")
|
|
105
|
+
print(f"You are {age} years old.")
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
### Magic ✨
|
|
111
|
+
|
|
112
|
+
This mode is for maximum convenience. By calling `magic()` once, `colorara` patches the built-in `print()` and `input()` functions, giving them all the powers of `cprint` and `cinput`.
|
|
113
|
+
|
|
114
|
+
**⚠️ Warning:** This modifies Python's built-in functions and might cause conflicts if another library tries to do the same. Use it with caution.
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
from colorara import magic, revert
|
|
118
|
+
|
|
119
|
+
# Activate magic
|
|
120
|
+
magic()
|
|
121
|
+
|
|
122
|
+
# The built-in print now understands tags!
|
|
123
|
+
print("Magic <magenta>print</> supports tags too!")
|
|
124
|
+
print("Status: <green>OK</>, Mode: <cyan,bg_black>MAGIC</>")
|
|
125
|
+
|
|
126
|
+
# The magic input also supports `inp_color`
|
|
127
|
+
food = input("Favorite food (prompt is red, typing is green)? ", color="red", inp_color="green")
|
|
128
|
+
print(f"You like {food}!")
|
|
129
|
+
|
|
130
|
+
# You can revert the changes if needed
|
|
131
|
+
revert()
|
|
132
|
+
|
|
133
|
+
# This print will be normal again
|
|
134
|
+
print("Back to normal.")
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Available Colors
|
|
138
|
+
|
|
139
|
+
You can use the following color names for both `color` and `bg_color`:
|
|
140
|
+
|
|
141
|
+
- `black`
|
|
142
|
+
- `red`
|
|
143
|
+
- `green`
|
|
144
|
+
- `yellow`
|
|
145
|
+
- `blue`
|
|
146
|
+
- `magenta`
|
|
147
|
+
- `cyan`
|
|
148
|
+
- `white`
|
colrs-0.1.0/README.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# colorara 🎨
|
|
2
|
+
|
|
3
|
+
A simple, elegant, and easy-to-use Python library to add color to your terminal text and backgrounds.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Simple API:** Color your text with zero hassle.
|
|
8
|
+
- **Cross-Platform:** Works on Windows, macOS, and Linux thanks to `colorama`.
|
|
9
|
+
- **Inline Tag Coloring:** Color specific words within a string using simple tags like `<green>word</>`.
|
|
10
|
+
- **Colored User Input:** Control the color of the user's typed text in `input()` prompts.
|
|
11
|
+
- **"Magic":** An optional mode to make the built-in `print()` and `input()` color-aware.
|
|
12
|
+
- **Lightweight:** Has only one dependency (`colorama`) for cross-platform support.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
First, navigate to the `colorara` project directory. Then, install it using `pip`:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install .
|
|
20
|
+
```
|
|
21
|
+
After installation, you can import it in any Python script on your system.
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
`colorara` is designed for flexibility and ease of use.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
### `cprint()` and Inline Coloring
|
|
30
|
+
|
|
31
|
+
The `cprint()` function is your main tool for printing. It supports both coloring the entire line and coloring specific parts of a string using tags.
|
|
32
|
+
|
|
33
|
+
**Syntax:** `<color_name>text</>` or `<text_color,bg_color>text</>`
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from colorara import cprint
|
|
37
|
+
|
|
38
|
+
# Overall coloring (like before)
|
|
39
|
+
cprint("This entire line is green.", color="green")
|
|
40
|
+
|
|
41
|
+
# --- Inline Tag Coloring ---
|
|
42
|
+
# Color a specific word
|
|
43
|
+
cprint("Status: <green>OK</>")
|
|
44
|
+
|
|
45
|
+
# Use multiple colors in one line
|
|
46
|
+
cprint("Results: <green>SUCCESS</>, Warnings: <yellow>3</>, Errors: <red>0</>")
|
|
47
|
+
|
|
48
|
+
# You can also color backgrounds
|
|
49
|
+
cprint("System State: <white,bg_green>ONLINE</>")
|
|
50
|
+
cprint("Alert: <black,bg_yellow>CHECK CONFIG</>")
|
|
51
|
+
|
|
52
|
+
# If you provide a `color` argument with tags, it is ignored
|
|
53
|
+
cprint("The tag <green>always</> wins.", color="red") # "always" will be green
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### `cinput()` and Colored User Input
|
|
57
|
+
|
|
58
|
+
Use `cinput()` to get user input with a colored prompt and even colored user-typed text.
|
|
59
|
+
|
|
60
|
+
It accepts a new argument `inp_color`. If you provide it, the user's typing will be in that color. If you don't, the user's typing will have the same color as the prompt.
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from colorara import cinput
|
|
64
|
+
|
|
65
|
+
# The user's typed text will be cyan, just like the prompt
|
|
66
|
+
name = cinput("Enter your name: ", color="cyan")
|
|
67
|
+
print(f"Hello, {name}!")
|
|
68
|
+
|
|
69
|
+
# The prompt will be yellow, but the user's typing will be blue
|
|
70
|
+
age = cinput("Enter your age: ", color="yellow", inp_color="blue")
|
|
71
|
+
print(f"You are {age} years old.")
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
### Magic ✨
|
|
77
|
+
|
|
78
|
+
This mode is for maximum convenience. By calling `magic()` once, `colorara` patches the built-in `print()` and `input()` functions, giving them all the powers of `cprint` and `cinput`.
|
|
79
|
+
|
|
80
|
+
**⚠️ Warning:** This modifies Python's built-in functions and might cause conflicts if another library tries to do the same. Use it with caution.
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from colorara import magic, revert
|
|
84
|
+
|
|
85
|
+
# Activate magic
|
|
86
|
+
magic()
|
|
87
|
+
|
|
88
|
+
# The built-in print now understands tags!
|
|
89
|
+
print("Magic <magenta>print</> supports tags too!")
|
|
90
|
+
print("Status: <green>OK</>, Mode: <cyan,bg_black>MAGIC</>")
|
|
91
|
+
|
|
92
|
+
# The magic input also supports `inp_color`
|
|
93
|
+
food = input("Favorite food (prompt is red, typing is green)? ", color="red", inp_color="green")
|
|
94
|
+
print(f"You like {food}!")
|
|
95
|
+
|
|
96
|
+
# You can revert the changes if needed
|
|
97
|
+
revert()
|
|
98
|
+
|
|
99
|
+
# This print will be normal again
|
|
100
|
+
print("Back to normal.")
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Available Colors
|
|
104
|
+
|
|
105
|
+
You can use the following color names for both `color` and `bg_color`:
|
|
106
|
+
|
|
107
|
+
- `black`
|
|
108
|
+
- `red`
|
|
109
|
+
- `green`
|
|
110
|
+
- `yellow`
|
|
111
|
+
- `blue`
|
|
112
|
+
- `magenta`
|
|
113
|
+
- `cyan`
|
|
114
|
+
- `white`
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# colorara/colorara/__init__.py
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
colorara - A simple and elegant way to color your terminal text.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
__version__ = "0.1.0"
|
|
8
|
+
|
|
9
|
+
# Initialize colorama to make ANSI codes work on Windows and to auto-reset colors.
|
|
10
|
+
from colorama import init
|
|
11
|
+
init(autoreset=True)
|
|
12
|
+
|
|
13
|
+
from .core import cprint, cinput, colorize
|
|
14
|
+
from .magic import magic, revert
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
'cprint',
|
|
18
|
+
'cinput',
|
|
19
|
+
'colorize',
|
|
20
|
+
'magic',
|
|
21
|
+
'revert'
|
|
22
|
+
]
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# colorara/colorara/core.py
|
|
2
|
+
|
|
3
|
+
import builtins
|
|
4
|
+
import re
|
|
5
|
+
|
|
6
|
+
# ANSI escape codes
|
|
7
|
+
COLORS = {
|
|
8
|
+
"black": "\033[30m",
|
|
9
|
+
"red": "\033[31m",
|
|
10
|
+
"green": "\033[32m",
|
|
11
|
+
"yellow": "\033[33m",
|
|
12
|
+
"blue": "\033[34m",
|
|
13
|
+
"magenta": "\033[35m",
|
|
14
|
+
"cyan": "\033[36m",
|
|
15
|
+
"white": "\033[37m",
|
|
16
|
+
"reset": "\033[0m",
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
BG_COLORS = {
|
|
20
|
+
"black": "\033[40m",
|
|
21
|
+
"red": "\033[41m",
|
|
22
|
+
"green": "\033[42m",
|
|
23
|
+
"yellow": "\033[43m",
|
|
24
|
+
"blue": "\033[44m",
|
|
25
|
+
"magenta": "\033[45m",
|
|
26
|
+
"cyan": "\033[46m",
|
|
27
|
+
"white": "\033[47m",
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
def colorize(text: str, color: str = None, bg_color: str = None) -> str:
|
|
31
|
+
"""
|
|
32
|
+
Wraps text with ANSI color codes.
|
|
33
|
+
"""
|
|
34
|
+
if not isinstance(text, str):
|
|
35
|
+
text = str(text)
|
|
36
|
+
|
|
37
|
+
color_code = COLORS.get(str(color).lower()) if color else ""
|
|
38
|
+
bg_color_code = BG_COLORS.get(str(bg_color).lower()) if bg_color else ""
|
|
39
|
+
|
|
40
|
+
if color_code or bg_color_code:
|
|
41
|
+
return f"{bg_color_code}{color_code}{text}{COLORS['reset']}"
|
|
42
|
+
|
|
43
|
+
return text
|
|
44
|
+
|
|
45
|
+
def _process_text_for_printing(text: str, color: str = None, bg_color: str = None) -> str:
|
|
46
|
+
"""
|
|
47
|
+
Processes a string for printing, handling both inline color tags and
|
|
48
|
+
overall coloring. If tags are found, they take precedence.
|
|
49
|
+
"""
|
|
50
|
+
# Regex to find color tags like <green> or <white,bg_blue>
|
|
51
|
+
tag_regex = r"<([a-zA-Z0-9_,]+)>(.*?)</>"
|
|
52
|
+
|
|
53
|
+
if "<" not in text and "</>" not in text:
|
|
54
|
+
return colorize(text, color, bg_color)
|
|
55
|
+
|
|
56
|
+
def replacer(match):
|
|
57
|
+
tags = match.group(1).lower().split(',')
|
|
58
|
+
inner_text = match.group(2)
|
|
59
|
+
|
|
60
|
+
tag_color = None
|
|
61
|
+
tag_bg_color = None
|
|
62
|
+
|
|
63
|
+
for tag in tags:
|
|
64
|
+
if tag.startswith('bg_'):
|
|
65
|
+
tag_bg_color = tag[3:]
|
|
66
|
+
else:
|
|
67
|
+
tag_color = tag
|
|
68
|
+
|
|
69
|
+
return colorize(inner_text, tag_color, tag_bg_color)
|
|
70
|
+
|
|
71
|
+
# Apply default color to the whole string first, then parse tags
|
|
72
|
+
# This is complex. Let's just color the untagged parts.
|
|
73
|
+
# A simpler approach for now: tags override the main color.
|
|
74
|
+
return re.sub(tag_regex, replacer, text)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def cprint(*args, color: str = None, bg_color: str = None, **kwargs):
|
|
78
|
+
"""
|
|
79
|
+
A safe wrapper around the built-in print function that adds color,
|
|
80
|
+
supporting both overall coloring and inline color tags.
|
|
81
|
+
|
|
82
|
+
e.g. cprint("Status: <green>OK</>")
|
|
83
|
+
"""
|
|
84
|
+
text = " ".join(map(str, args))
|
|
85
|
+
processed_text = _process_text_for_printing(text, color, bg_color)
|
|
86
|
+
builtins.print(processed_text, **kwargs)
|
|
87
|
+
|
|
88
|
+
def _get_colored_input_prompt(prompt: str, color: str, bg_color: str, inp_color: str) -> str:
|
|
89
|
+
"""
|
|
90
|
+
Internal helper to construct the final prompt string for input,
|
|
91
|
+
handling both prompt color and user input color.
|
|
92
|
+
"""
|
|
93
|
+
# If inp_color is not given, it defaults to the prompt's text color
|
|
94
|
+
effective_inp_color = inp_color if inp_color is not None else color
|
|
95
|
+
|
|
96
|
+
# Color the prompt part (which includes a reset)
|
|
97
|
+
colored_prompt = colorize(prompt, color, bg_color)
|
|
98
|
+
|
|
99
|
+
# Get the color code for the user's input, or an empty string if no color
|
|
100
|
+
input_color_code = COLORS.get(str(effective_inp_color).lower(), "") if effective_inp_color else ""
|
|
101
|
+
|
|
102
|
+
# The final prompt string sets the color for the user's typing
|
|
103
|
+
return colored_prompt + input_color_code
|
|
104
|
+
|
|
105
|
+
def cinput(prompt: str = "", color: str = None, bg_color: str = None, inp_color: str = None) -> str:
|
|
106
|
+
"""
|
|
107
|
+
A safe wrapper around the built-in input function that adds color to the
|
|
108
|
+
prompt and optionally to the user's typed input.
|
|
109
|
+
|
|
110
|
+
:param prompt: The prompt string to display.
|
|
111
|
+
:param color: The color of the prompt string.
|
|
112
|
+
:param bg_color: The background color of the prompt string.
|
|
113
|
+
:param inp_color: The color of the user's typed text. If None, defaults to `color`.
|
|
114
|
+
"""
|
|
115
|
+
final_prompt = _get_colored_input_prompt(prompt, color, bg_color, inp_color)
|
|
116
|
+
return builtins.input(final_prompt)
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# colorara/colorara/magic.py
|
|
2
|
+
|
|
3
|
+
import builtins
|
|
4
|
+
from .core import cprint, _get_colored_input_prompt, _process_text_for_printing
|
|
5
|
+
|
|
6
|
+
_original_print = builtins.print
|
|
7
|
+
_original_input = builtins.input
|
|
8
|
+
|
|
9
|
+
def _magic_print(*args, **kwargs):
|
|
10
|
+
"""
|
|
11
|
+
A patched version of print that handles color arguments, including
|
|
12
|
+
inline color tags.
|
|
13
|
+
"""
|
|
14
|
+
# Extract our custom color arguments, removing them from kwargs
|
|
15
|
+
color = kwargs.pop("color", None)
|
|
16
|
+
bg_color = kwargs.pop("bg_color", None)
|
|
17
|
+
|
|
18
|
+
text = " ".join(map(str, args))
|
|
19
|
+
processed_text = _process_text_for_printing(text, color, bg_color)
|
|
20
|
+
|
|
21
|
+
_original_print(processed_text, **kwargs)
|
|
22
|
+
|
|
23
|
+
def _magic_input(prompt: str = "", **kwargs) -> str:
|
|
24
|
+
"""
|
|
25
|
+
A patched version of input that handles color arguments for the prompt
|
|
26
|
+
and for the user's typed input.
|
|
27
|
+
"""
|
|
28
|
+
# Extract our custom color arguments from kwargs
|
|
29
|
+
color = kwargs.get("color")
|
|
30
|
+
bg_color = kwargs.get("bg_color")
|
|
31
|
+
inp_color = kwargs.get("inp_color")
|
|
32
|
+
|
|
33
|
+
final_prompt = _get_colored_input_prompt(prompt, color, bg_color, inp_color)
|
|
34
|
+
return _original_input(final_prompt)
|
|
35
|
+
|
|
36
|
+
def magic():
|
|
37
|
+
"""
|
|
38
|
+
Activates 'Magic Mode' by patching the built-in print and input functions.
|
|
39
|
+
|
|
40
|
+
This allows you to use 'color' and 'bg_color' arguments directly in print()
|
|
41
|
+
and input() without calling a special function.
|
|
42
|
+
|
|
43
|
+
Warning: This modifies built-in functions and may conflict with other
|
|
44
|
+
libraries that also modify them. Use with caution.
|
|
45
|
+
"""
|
|
46
|
+
if builtins.print == _magic_print:
|
|
47
|
+
cprint("Magic is already active.", color="yellow")
|
|
48
|
+
return
|
|
49
|
+
|
|
50
|
+
builtins.print = _magic_print
|
|
51
|
+
builtins.input = _magic_input
|
|
52
|
+
cprint("Magic activated. `print` and `input` are now color-aware.", color="yellow")
|
|
53
|
+
|
|
54
|
+
def revert():
|
|
55
|
+
"""
|
|
56
|
+
Deactivates 'Magic' and restores the original built-in functions.
|
|
57
|
+
"""
|
|
58
|
+
if builtins.print != _magic_print:
|
|
59
|
+
cprint("Magic is not active.", color="yellow")
|
|
60
|
+
return
|
|
61
|
+
|
|
62
|
+
builtins.print = _original_print
|
|
63
|
+
builtins.input = _original_input
|
|
64
|
+
cprint("Magic deactivated. `print` and `input` restored.", color="yellow")
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: colrs
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A simple and elegant Python library for terminal text coloring.
|
|
5
|
+
Home-page: https://github.com/kalth/colrs
|
|
6
|
+
Author: hussain_syrer
|
|
7
|
+
Author-email: h2311065@gmail.com
|
|
8
|
+
Keywords: color terminal ansi text style coloring cli print input
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Topic :: Terminals
|
|
20
|
+
Classifier: Topic :: Utilities
|
|
21
|
+
Requires-Python: >=3.7
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
Requires-Dist: colorama
|
|
24
|
+
Dynamic: author
|
|
25
|
+
Dynamic: author-email
|
|
26
|
+
Dynamic: classifier
|
|
27
|
+
Dynamic: description
|
|
28
|
+
Dynamic: description-content-type
|
|
29
|
+
Dynamic: home-page
|
|
30
|
+
Dynamic: keywords
|
|
31
|
+
Dynamic: requires-dist
|
|
32
|
+
Dynamic: requires-python
|
|
33
|
+
Dynamic: summary
|
|
34
|
+
|
|
35
|
+
# colorara 🎨
|
|
36
|
+
|
|
37
|
+
A simple, elegant, and easy-to-use Python library to add color to your terminal text and backgrounds.
|
|
38
|
+
|
|
39
|
+
## Features
|
|
40
|
+
|
|
41
|
+
- **Simple API:** Color your text with zero hassle.
|
|
42
|
+
- **Cross-Platform:** Works on Windows, macOS, and Linux thanks to `colorama`.
|
|
43
|
+
- **Inline Tag Coloring:** Color specific words within a string using simple tags like `<green>word</>`.
|
|
44
|
+
- **Colored User Input:** Control the color of the user's typed text in `input()` prompts.
|
|
45
|
+
- **"Magic":** An optional mode to make the built-in `print()` and `input()` color-aware.
|
|
46
|
+
- **Lightweight:** Has only one dependency (`colorama`) for cross-platform support.
|
|
47
|
+
|
|
48
|
+
## Installation
|
|
49
|
+
|
|
50
|
+
First, navigate to the `colorara` project directory. Then, install it using `pip`:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install .
|
|
54
|
+
```
|
|
55
|
+
After installation, you can import it in any Python script on your system.
|
|
56
|
+
|
|
57
|
+
## Usage
|
|
58
|
+
|
|
59
|
+
`colorara` is designed for flexibility and ease of use.
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
### `cprint()` and Inline Coloring
|
|
64
|
+
|
|
65
|
+
The `cprint()` function is your main tool for printing. It supports both coloring the entire line and coloring specific parts of a string using tags.
|
|
66
|
+
|
|
67
|
+
**Syntax:** `<color_name>text</>` or `<text_color,bg_color>text</>`
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from colorara import cprint
|
|
71
|
+
|
|
72
|
+
# Overall coloring (like before)
|
|
73
|
+
cprint("This entire line is green.", color="green")
|
|
74
|
+
|
|
75
|
+
# --- Inline Tag Coloring ---
|
|
76
|
+
# Color a specific word
|
|
77
|
+
cprint("Status: <green>OK</>")
|
|
78
|
+
|
|
79
|
+
# Use multiple colors in one line
|
|
80
|
+
cprint("Results: <green>SUCCESS</>, Warnings: <yellow>3</>, Errors: <red>0</>")
|
|
81
|
+
|
|
82
|
+
# You can also color backgrounds
|
|
83
|
+
cprint("System State: <white,bg_green>ONLINE</>")
|
|
84
|
+
cprint("Alert: <black,bg_yellow>CHECK CONFIG</>")
|
|
85
|
+
|
|
86
|
+
# If you provide a `color` argument with tags, it is ignored
|
|
87
|
+
cprint("The tag <green>always</> wins.", color="red") # "always" will be green
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### `cinput()` and Colored User Input
|
|
91
|
+
|
|
92
|
+
Use `cinput()` to get user input with a colored prompt and even colored user-typed text.
|
|
93
|
+
|
|
94
|
+
It accepts a new argument `inp_color`. If you provide it, the user's typing will be in that color. If you don't, the user's typing will have the same color as the prompt.
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from colorara import cinput
|
|
98
|
+
|
|
99
|
+
# The user's typed text will be cyan, just like the prompt
|
|
100
|
+
name = cinput("Enter your name: ", color="cyan")
|
|
101
|
+
print(f"Hello, {name}!")
|
|
102
|
+
|
|
103
|
+
# The prompt will be yellow, but the user's typing will be blue
|
|
104
|
+
age = cinput("Enter your age: ", color="yellow", inp_color="blue")
|
|
105
|
+
print(f"You are {age} years old.")
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
### Magic ✨
|
|
111
|
+
|
|
112
|
+
This mode is for maximum convenience. By calling `magic()` once, `colorara` patches the built-in `print()` and `input()` functions, giving them all the powers of `cprint` and `cinput`.
|
|
113
|
+
|
|
114
|
+
**⚠️ Warning:** This modifies Python's built-in functions and might cause conflicts if another library tries to do the same. Use it with caution.
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
from colorara import magic, revert
|
|
118
|
+
|
|
119
|
+
# Activate magic
|
|
120
|
+
magic()
|
|
121
|
+
|
|
122
|
+
# The built-in print now understands tags!
|
|
123
|
+
print("Magic <magenta>print</> supports tags too!")
|
|
124
|
+
print("Status: <green>OK</>, Mode: <cyan,bg_black>MAGIC</>")
|
|
125
|
+
|
|
126
|
+
# The magic input also supports `inp_color`
|
|
127
|
+
food = input("Favorite food (prompt is red, typing is green)? ", color="red", inp_color="green")
|
|
128
|
+
print(f"You like {food}!")
|
|
129
|
+
|
|
130
|
+
# You can revert the changes if needed
|
|
131
|
+
revert()
|
|
132
|
+
|
|
133
|
+
# This print will be normal again
|
|
134
|
+
print("Back to normal.")
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Available Colors
|
|
138
|
+
|
|
139
|
+
You can use the following color names for both `color` and `bg_color`:
|
|
140
|
+
|
|
141
|
+
- `black`
|
|
142
|
+
- `red`
|
|
143
|
+
- `green`
|
|
144
|
+
- `yellow`
|
|
145
|
+
- `blue`
|
|
146
|
+
- `magenta`
|
|
147
|
+
- `cyan`
|
|
148
|
+
- `white`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
colorama
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
colrs
|
colrs-0.1.0/setup.cfg
ADDED
colrs-0.1.0/setup.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# colorara/setup.py
|
|
2
|
+
|
|
3
|
+
from setuptools import setup, find_packages
|
|
4
|
+
|
|
5
|
+
# Read the contents of your README file
|
|
6
|
+
with open("README.md", "r", encoding="utf-8") as fh:
|
|
7
|
+
long_description = fh.read()
|
|
8
|
+
|
|
9
|
+
setup(
|
|
10
|
+
name='colrs',
|
|
11
|
+
version='0.1.0',
|
|
12
|
+
author='hussain_syrer',
|
|
13
|
+
author_email='h2311065@gmail.com',
|
|
14
|
+
description='A simple and elegant Python library for terminal text coloring.',
|
|
15
|
+
long_description=long_description,
|
|
16
|
+
long_description_content_type='text/markdown',
|
|
17
|
+
url='https://github.com/kalth/colrs', # Placeholder URL
|
|
18
|
+
packages=find_packages(),
|
|
19
|
+
install_requires=[
|
|
20
|
+
'colorama',
|
|
21
|
+
],
|
|
22
|
+
classifiers=[
|
|
23
|
+
'Development Status :: 4 - Beta',
|
|
24
|
+
'Intended Audience :: Developers',
|
|
25
|
+
'License :: OSI Approved :: MIT License',
|
|
26
|
+
'Programming Language :: Python :: 3',
|
|
27
|
+
'Programming Language :: Python :: 3.7',
|
|
28
|
+
'Programming Language :: Python :: 3.8',
|
|
29
|
+
'Programming Language :: Python :: 3.9',
|
|
30
|
+
'Programming Language :: Python :: 3.10',
|
|
31
|
+
'Programming Language :: Python :: 3.11',
|
|
32
|
+
'Operating System :: OS Independent',
|
|
33
|
+
'Topic :: Terminals',
|
|
34
|
+
'Topic :: Utilities',
|
|
35
|
+
],
|
|
36
|
+
python_requires='>=3.7',
|
|
37
|
+
keywords='color terminal ansi text style coloring cli print input',
|
|
38
|
+
)
|