colrs 0.1.3__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.
- colrs/__init__.py +21 -0
- colrs/animations.py +46 -0
- colrs/core.py +116 -0
- colrs/magic.py +60 -0
- colrs/style_1.py +23 -0
- colrs/style_10.py +15 -0
- colrs/style_2.py +15 -0
- colrs/style_3.py +14 -0
- colrs/style_4.py +19 -0
- colrs/style_5.py +21 -0
- colrs/style_6.py +15 -0
- colrs/style_7.py +16 -0
- colrs/style_8.py +14 -0
- colrs/style_9.py +17 -0
- colrs-0.1.3.dist-info/METADATA +137 -0
- colrs-0.1.3.dist-info/RECORD +18 -0
- colrs-0.1.3.dist-info/WHEEL +5 -0
- colrs-0.1.3.dist-info/top_level.txt +1 -0
colrs/__init__.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# colorara/colorara/__init__.py
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
colrs - A simple and elegant way to color your terminal text.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
__version__ = "0.1.3"
|
|
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
|
+
# The public API is now just act() and unact() for maximum simplicity.
|
|
14
|
+
from .magic import act, unact
|
|
15
|
+
from .animations import loading
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
'act',
|
|
19
|
+
'unact',
|
|
20
|
+
'loading'
|
|
21
|
+
]
|
colrs/animations.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# colorara/colrs/animations.py
|
|
2
|
+
|
|
3
|
+
import time
|
|
4
|
+
import importlib
|
|
5
|
+
import sys
|
|
6
|
+
from .magic import act, unact
|
|
7
|
+
|
|
8
|
+
def loading(style=1, duration=3, text="Loading...", color="yellow", end_text="Done!", end_color="green"):
|
|
9
|
+
"""
|
|
10
|
+
Displays a loading animation in the terminal.
|
|
11
|
+
|
|
12
|
+
This function dynamically imports and runs a loader style. It ensures that
|
|
13
|
+
the `colrs` patching is active during the animation and deactivates it
|
|
14
|
+
afterwards to avoid side effects.
|
|
15
|
+
|
|
16
|
+
:param style: The style of the loader to display (e.g., 1, 2, 'bar', 'spinner').
|
|
17
|
+
:param duration: The total duration of the animation in seconds.
|
|
18
|
+
:param text: The text to display alongside the animation.
|
|
19
|
+
:param color: The primary color of the animation and text.
|
|
20
|
+
:param end_text: The text to display upon completion.
|
|
21
|
+
:param end_color: The color of the completion text.
|
|
22
|
+
"""
|
|
23
|
+
# Ensure patching is active for the animation
|
|
24
|
+
act()
|
|
25
|
+
|
|
26
|
+
try:
|
|
27
|
+
# Dynamically import the chosen style module
|
|
28
|
+
loader_module = importlib.import_lib(f'.loaders.style_{style}', package='colrs')
|
|
29
|
+
|
|
30
|
+
# Run the animation from the imported module
|
|
31
|
+
loader_module.run(duration, text, color)
|
|
32
|
+
|
|
33
|
+
# Print completion message
|
|
34
|
+
# Use \r to overwrite the loader line and clear it with spaces
|
|
35
|
+
sys.stdout.write('\r' + ' ' * 80 + '\r')
|
|
36
|
+
print(f"<{end_color}>{end_text}</>")
|
|
37
|
+
|
|
38
|
+
except ImportError:
|
|
39
|
+
print(f"<red>Error: Loader style '{style}' not found.</red>")
|
|
40
|
+
except Exception as e:
|
|
41
|
+
# Clean up the line in case of an error during animation
|
|
42
|
+
sys.stdout.write('\r' + ' ' * 80 + '\r')
|
|
43
|
+
print(f"<red>An error occurred during animation: {e}</red>")
|
|
44
|
+
finally:
|
|
45
|
+
# Deactivate patching to restore normal print/input functions
|
|
46
|
+
unact()
|
colrs/core.py
ADDED
|
@@ -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
|
+
# Process the prompt for any inline tags, applying base colors if no tags exist.
|
|
97
|
+
processed_prompt = _process_text_for_printing(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 processed_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)
|
colrs/magic.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# colorara/colorara/magic.py
|
|
2
|
+
|
|
3
|
+
import builtins
|
|
4
|
+
from .core import _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 act():
|
|
37
|
+
"""
|
|
38
|
+
Activates the patching of 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 is _magic_print:
|
|
47
|
+
return
|
|
48
|
+
|
|
49
|
+
builtins.print = _magic_print
|
|
50
|
+
builtins.input = _magic_input
|
|
51
|
+
|
|
52
|
+
def unact():
|
|
53
|
+
"""
|
|
54
|
+
Deactivates the patching and restores the original built-in functions.
|
|
55
|
+
"""
|
|
56
|
+
if builtins.print is not _magic_print:
|
|
57
|
+
return
|
|
58
|
+
|
|
59
|
+
builtins.print = _original_print
|
|
60
|
+
builtins.input = _original_input
|
colrs/style_1.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# style_1.py: Progress Bar
|
|
2
|
+
import time
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
def run(duration, text, color):
|
|
6
|
+
"""Displays a dynamic, multi-colored progress bar."""
|
|
7
|
+
length = 40
|
|
8
|
+
start_time = time.time()
|
|
9
|
+
|
|
10
|
+
while (time.time() - start_time) < duration:
|
|
11
|
+
elapsed = time.time() - start_time
|
|
12
|
+
progress = elapsed / duration
|
|
13
|
+
percent = progress * 100
|
|
14
|
+
|
|
15
|
+
filled_len = int(length * progress)
|
|
16
|
+
filled = '█' * filled_len
|
|
17
|
+
empty = '─' * (length - filled_len)
|
|
18
|
+
|
|
19
|
+
bar_color = "green" if percent > 80 else "yellow" if percent > 40 else "red"
|
|
20
|
+
|
|
21
|
+
sys.stdout.write(f'\r<white>{text}</> <{bar_color}>[{filled}{empty}]</> {percent:.0f}%')
|
|
22
|
+
sys.stdout.flush()
|
|
23
|
+
time.sleep(0.05)
|
colrs/style_10.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# style_10.py: Pac-Man
|
|
2
|
+
import time
|
|
3
|
+
import sys
|
|
4
|
+
import itertools
|
|
5
|
+
|
|
6
|
+
def run(duration, text, color):
|
|
7
|
+
"""Displays a Pac-Man style animation."""
|
|
8
|
+
pacman = itertools.cycle(['<', 'V', '>', '^'])
|
|
9
|
+
dots = " · " * 5
|
|
10
|
+
start_time = time.time()
|
|
11
|
+
|
|
12
|
+
while (time.time() - start_time) < duration:
|
|
13
|
+
sys.stdout.write(f'\r<yellow>{next(pacman)}</> <white>{text}</> <{color}>{dots}</>')
|
|
14
|
+
sys.stdout.flush()
|
|
15
|
+
time.sleep(0.2)
|
colrs/style_2.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# style_2.py: Spinner
|
|
2
|
+
import time
|
|
3
|
+
import sys
|
|
4
|
+
import itertools
|
|
5
|
+
|
|
6
|
+
def run(duration, text, color):
|
|
7
|
+
"""Displays a simple spinning line animation."""
|
|
8
|
+
spinner = itertools.cycle(['|', '/', '—', '\\'])
|
|
9
|
+
start_time = time.time()
|
|
10
|
+
|
|
11
|
+
while (time.time() - start_time) < duration:
|
|
12
|
+
char = next(spinner)
|
|
13
|
+
sys.stdout.write(f'\r<{color}>{text} {char}</>')
|
|
14
|
+
sys.stdout.flush()
|
|
15
|
+
time.sleep(0.1)
|
colrs/style_3.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# style_3.py: Bouncing Dots
|
|
2
|
+
import time
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
def run(duration, text, color):
|
|
6
|
+
"""Displays a bouncing dots animation."""
|
|
7
|
+
start_time = time.time()
|
|
8
|
+
|
|
9
|
+
while (time.time() - start_time) < duration:
|
|
10
|
+
for i in range(4):
|
|
11
|
+
dots = '.' * i + ' ' * (3 - i)
|
|
12
|
+
sys.stdout.write(f'\r<{color}>{text}{dots}</>')
|
|
13
|
+
sys.stdout.flush()
|
|
14
|
+
time.sleep(0.15)
|
colrs/style_4.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# style_4.py: Dual-Side Progress Bar
|
|
2
|
+
import time
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
def run(duration, text, color):
|
|
6
|
+
"""Displays a progress bar that fills from both ends."""
|
|
7
|
+
length = 40
|
|
8
|
+
start_time = time.time()
|
|
9
|
+
|
|
10
|
+
while (time.time() - start_time) < duration:
|
|
11
|
+
progress = (time.time() - start_time) / duration
|
|
12
|
+
filled_len = int(length * progress / 2)
|
|
13
|
+
|
|
14
|
+
filled = '█' * filled_len
|
|
15
|
+
empty = ' ' * (length - 2 * filled_len)
|
|
16
|
+
|
|
17
|
+
sys.stdout.write(f'\r<{color}>{text} [{filled}{empty}{filled}]</>')
|
|
18
|
+
sys.stdout.flush()
|
|
19
|
+
time.sleep(0.05)
|
colrs/style_5.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# style_5.py: Scanner Effect
|
|
2
|
+
import time
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
def run(duration, text, color):
|
|
6
|
+
"""Displays a 'Knight Rider' style scanner."""
|
|
7
|
+
length = 20
|
|
8
|
+
start_time = time.time()
|
|
9
|
+
|
|
10
|
+
while (time.time() - start_time) < duration:
|
|
11
|
+
# Ping-pong effect for the scanner position
|
|
12
|
+
pos = int((time.time() * 10) % (length * 2 - 2))
|
|
13
|
+
if pos >= length:
|
|
14
|
+
pos = (length * 2 - 2) - pos
|
|
15
|
+
|
|
16
|
+
bar = ['─'] * length
|
|
17
|
+
bar[pos] = '█'
|
|
18
|
+
|
|
19
|
+
sys.stdout.write(f'\r<{color}>{text} [{"".join(bar)}]</>')
|
|
20
|
+
sys.stdout.flush()
|
|
21
|
+
time.sleep(0.03)
|
colrs/style_6.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# style_6.py: Clock Spinner
|
|
2
|
+
import time
|
|
3
|
+
import sys
|
|
4
|
+
import itertools
|
|
5
|
+
|
|
6
|
+
def run(duration, text, color):
|
|
7
|
+
"""Displays a spinning clock-hand animation."""
|
|
8
|
+
clock_chars = ['🕛', '🕐', '🕑', '🕒', '🕓', '🕔', '🕕', '🕖', '🕗', '🕘', '🕙', '🕚']
|
|
9
|
+
spinner = itertools.cycle(clock_chars)
|
|
10
|
+
start_time = time.time()
|
|
11
|
+
|
|
12
|
+
while (time.time() - start_time) < duration:
|
|
13
|
+
sys.stdout.write(f'\r<{color}>{text} {next(spinner)}</>')
|
|
14
|
+
sys.stdout.flush()
|
|
15
|
+
time.sleep(0.1)
|
colrs/style_7.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# style_7.py: Gradient Wave
|
|
2
|
+
import time
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
def run(duration, text, color):
|
|
6
|
+
"""Displays a wave of characters with changing intensity."""
|
|
7
|
+
chars = " ▂▃▄▅▆▇█▇▆▅▄▃▂ "
|
|
8
|
+
start_time = time.time()
|
|
9
|
+
|
|
10
|
+
while (time.time() - start_time) < duration:
|
|
11
|
+
offset = int(time.time() * 10) % len(chars)
|
|
12
|
+
wave = "".join([chars[(i + offset) % len(chars)] for i in range(15)])
|
|
13
|
+
|
|
14
|
+
sys.stdout.write(f'\r<{color}>{text} {wave}</>')
|
|
15
|
+
sys.stdout.flush()
|
|
16
|
+
time.sleep(0.05)
|
colrs/style_8.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# style_8.py: Arrow Flow
|
|
2
|
+
import time
|
|
3
|
+
import sys
|
|
4
|
+
import itertools
|
|
5
|
+
|
|
6
|
+
def run(duration, text, color):
|
|
7
|
+
"""Displays arrows moving to the right."""
|
|
8
|
+
arrows = itertools.cycle(['> ', '>> ', '>>>', ' >>', ' >'])
|
|
9
|
+
start_time = time.time()
|
|
10
|
+
|
|
11
|
+
while (time.time() - start_time) < duration:
|
|
12
|
+
sys.stdout.write(f'\r<{color}>{text} {next(arrows)}</>')
|
|
13
|
+
sys.stdout.flush()
|
|
14
|
+
time.sleep(0.15)
|
colrs/style_9.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# style_9.py: Random Blocks
|
|
2
|
+
import time
|
|
3
|
+
import sys
|
|
4
|
+
import random
|
|
5
|
+
|
|
6
|
+
def run(duration, text, color):
|
|
7
|
+
"""Fills a bar with random blocks."""
|
|
8
|
+
length = 25
|
|
9
|
+
blocks = [' '] * length
|
|
10
|
+
start_time = time.time()
|
|
11
|
+
|
|
12
|
+
while ' ' in blocks:
|
|
13
|
+
pos = random.randint(0, length - 1)
|
|
14
|
+
blocks[pos] = '█'
|
|
15
|
+
sys.stdout.write(f'\r<{color}>{text} [{"".join(blocks)}]</>')
|
|
16
|
+
sys.stdout.flush()
|
|
17
|
+
time.sleep(duration / (length * 1.5)) # Slow down filling
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: colrs
|
|
3
|
+
Version: 0.1.3
|
|
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
|
+
# colrs 🎨
|
|
36
|
+
|
|
37
|
+
**A radically simple Python library for coloring your terminal output.**
|
|
38
|
+
|
|
39
|
+
[](https://opensource.org/licenses/MIT)
|
|
40
|
+
|
|
41
|
+
`colrs` takes a different approach to terminal coloring. Instead of wrapping your print statements in special functions, you activate it once, and your standard `print` and `input` functions become color-aware.
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Philosophy
|
|
46
|
+
|
|
47
|
+
The core idea is **absolute simplicity**. No new function names to remember for printing. Just activate the magic and write your code as you normally would, but with added superpowers.
|
|
48
|
+
|
|
49
|
+
- **Activate:** `act()`
|
|
50
|
+
- **Use `print` and `input` normally:** Add colors with tags or keyword arguments.
|
|
51
|
+
- **Deactivate:** `unact()`
|
|
52
|
+
- **Show Animations:** `loading()`
|
|
53
|
+
|
|
54
|
+
This is the core public API, designed for simplicity and power.
|
|
55
|
+
|
|
56
|
+
## Installation
|
|
57
|
+
|
|
58
|
+
To install the library:
|
|
59
|
+
```bash
|
|
60
|
+
pip install colrs
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## How to Use
|
|
64
|
+
|
|
65
|
+
The usage is designed to be as intuitive as possible. You import `act` and `unact`, and wrap the code you want to be color-aware.
|
|
66
|
+
|
|
67
|
+
### Basic Example
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from colrs import act, unact
|
|
71
|
+
|
|
72
|
+
# This print is normal
|
|
73
|
+
print("This is default terminal text.")
|
|
74
|
+
|
|
75
|
+
# Activate the color patching
|
|
76
|
+
act()
|
|
77
|
+
|
|
78
|
+
# Now, print() and input() are super-powered!
|
|
79
|
+
print("This is a <green>green text</> using inline tags.")
|
|
80
|
+
print("This is red.", color="red")
|
|
81
|
+
print("This is blue on a yellow background.", color="blue", bg_color="yellow")
|
|
82
|
+
|
|
83
|
+
name = input("What's your name? ", color="cyan", inp_color="magenta")
|
|
84
|
+
print(f"Hello, {name}!")
|
|
85
|
+
|
|
86
|
+
# It's good practice to deactivate when you're done
|
|
87
|
+
unact()
|
|
88
|
+
|
|
89
|
+
print("And we're back to normal.")
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Using `print()` with `act()`
|
|
93
|
+
|
|
94
|
+
Once `act()` is called, `print()` can accept two new keyword arguments: `color` and `bg_color`.
|
|
95
|
+
|
|
96
|
+
More powerfully, you can use inline tags for fine-grained control.
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
act()
|
|
100
|
+
|
|
101
|
+
# Simple tags
|
|
102
|
+
print("<red>This will be red.</red>") # The closing tag is optional
|
|
103
|
+
|
|
104
|
+
# Nested tags
|
|
105
|
+
print("<yellow>This is yellow with <blue>blue text</blue> inside.</yellow>")
|
|
106
|
+
|
|
107
|
+
# Background colors
|
|
108
|
+
print("<white,bg_red> White text on a red background. </>") # </> resets all
|
|
109
|
+
|
|
110
|
+
unact()
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Using `input()` with `act()`
|
|
114
|
+
|
|
115
|
+
The patched `input()` can color three things separately:
|
|
116
|
+
1. The prompt text (`color` and `bg_color` arguments, or tags).
|
|
117
|
+
2. The text the user types (`inp_color` argument).
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
act()
|
|
121
|
+
|
|
122
|
+
# The prompt will be yellow, and the user's typing will be cyan
|
|
123
|
+
username = input("Enter username: ", color="yellow", inp_color="cyan")
|
|
124
|
+
|
|
125
|
+
# You can also use tags in the prompt
|
|
126
|
+
password = input("<red>Enter password:</red> ", inp_color="red")
|
|
127
|
+
|
|
128
|
+
unact()
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Why `colrs`?
|
|
132
|
+
|
|
133
|
+
If you want a coloring library that "just works" in the background without forcing you to change your coding habits, `colrs` is for you. It's designed for scripts and applications where you want to enable colors globally with minimal code changes.
|
|
134
|
+
|
|
135
|
+
## License
|
|
136
|
+
|
|
137
|
+
This project is licensed under the MIT License.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
colrs/__init__.py,sha256=JVgweaBpNX1eeN9sGAVs1qBiLRCJWvwd8AqD_uIoTl4,444
|
|
2
|
+
colrs/animations.py,sha256=-JykPxzW2ZopX5S60xJ3xwiD-r1zUU5cd7NDaI9ytWY,1846
|
|
3
|
+
colrs/core.py,sha256=ja3WtyBLR0K7zEkCxS4kmk4SAuDGvJ1DdSXlf7-24P0,3966
|
|
4
|
+
colrs/magic.py,sha256=40l1Z-cw8hWZUUxwXZc2m-p0cgo2wrKnIEkD40teErU,1853
|
|
5
|
+
colrs/style_1.py,sha256=U8C5YaI5BqhHhMZ-bzKaH236wCHKLoy-AGdNiK9GJB8,762
|
|
6
|
+
colrs/style_10.py,sha256=UhzxQkdRZ35S29MulshYHY5bbhCCsUMK6_rjczWwXws,451
|
|
7
|
+
colrs/style_2.py,sha256=gxq-ST1lHzhGBljZ-tKgfi1u9rpBFUU6MWFSFCAVuoY,436
|
|
8
|
+
colrs/style_3.py,sha256=XRkkxrqq8lC7-ZXDoMrQx3r4h7xjDPQ6GK9D7EqoQD4,415
|
|
9
|
+
colrs/style_4.py,sha256=jh_ILLkSBPeAjQPXupdcUzOnOylOtcMuK-GB8HHz6oY,601
|
|
10
|
+
colrs/style_5.py,sha256=L8nE8E-1xLIk0SQHDTKRnTq6kXR8liDKpBJdKiAIq5Q,611
|
|
11
|
+
colrs/style_6.py,sha256=6Mp0xfDCWKDmvaIdstOmvRPmZa-udd56OYtX-nMlogo,520
|
|
12
|
+
colrs/style_7.py,sha256=iwDn_1xrIFUax40jYANvzwZaeqcQxQdeYjwqjYHsC1Q,546
|
|
13
|
+
colrs/style_8.py,sha256=ErC2rvDCOy9Gx7vikjN5D2ceKjIYkpNwcrHDfMC50H4,419
|
|
14
|
+
colrs/style_9.py,sha256=BN_zxeXMbwRKb2Ss--sZjGrD69wCBibf97hYRmX3JL0,489
|
|
15
|
+
colrs-0.1.3.dist-info/METADATA,sha256=Ufi7sU3GjXbs9nW8d3rVkj8SnGD6T9k8l4PuF4k85qI,4233
|
|
16
|
+
colrs-0.1.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
17
|
+
colrs-0.1.3.dist-info/top_level.txt,sha256=xhWGbU8PW3TReGdsuLGMnYtmNwUcZkQz0JQWPAzezp4,6
|
|
18
|
+
colrs-0.1.3.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
colrs
|