Koloro - colorful terminal text in Python
Project description
K o l o r o
Koloro - colorful terminal text in Python
Usage
Install with pip:
pip install koloro
import koloro
print(koloro.red(f"Error: something was wrong in {koloro.cyan('main.py')}"))
The following environment variables can be used to disable color output globally:
-
Disable settings:
NO_COLOR(assigning something toNO_COLORdisables color output regardless of the value)TERM=dumb
-
Enable settings:
FORCE_COLOR(assigning something toFORCE_COLORenables color output regardless of the value)
Moreover, the enabled variable can also be used to toggle color output on and off:
import koloro
# color output on
koloro.enabled = True
print(koloro.cyan("foo")) # -> "\u001b[36mfoo\u001b[39m"
# color output off
koloro.enabled = False
print(koloro.cyan("foo")) # -> "foo"
Stripping ANSI codes function is also provided:
import koloro
print(koloro.cyan("foo")) # -> "\u001b[36mfoo\u001b[39m"
print(koloro.strip_ansi(koloro.cyan("foo"))) # -> "foo"
There is also functions for ANSI 256 colors output:
import koloro
# code number 12 from https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
print(koloro.ansi256(12)('foo')) # -> "\u001b[38;5;12mfoo\u001b[0m"
import koloro
# code number 12 from https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
print(koloro.ansi256Bg(12)(koloro.black('foo'))) # -> "\u001b[48;5;12mfoo\u001b[0m"
API Reference
Below functions require one argument txt.
Modifiers
resetbolddimitalicunderlineinversehiddenstrikethrough
Colors
blackredgreenyellowbluemagentacyanwhite
Background colors
bgBlackbgRedbgGreenbgYellowbgBluebgMagentabgCyanbgWhite
Bright colors
greybrightRedbrightGreenbrightYellowbrightBluebrightMagentabrightCyanbrightWhite
Bright background colors
bgGreybgBrightRedbgBrightGreenbgBrightYellowbgBrightBluebgBrightMagentabgBrightCyanbgBrightWhite
ANSI 256 colors
-
ansi256-
Arguments:
n(int) - color code from ANSI 256
-
Returns:
- a function who argument is the text to display color output
-
-
ansi256Bg-
Arguments:
n(int) - color code from ANSI 256
-
Returns:
- a function who argument is the text to display color output
-
-
strip_ansi-
Arguments:
string(str) - ANSI colored string
-
Returns:
- a string which no ANSI codes
-
License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file koloro-0.1.4-py3-none-any.whl.
File metadata
- Download URL: koloro-0.1.4-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.7.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f33f4de6e76c99e3fa1134d76d12665e94d073ba7b2311d146e3e87c7d3f94e0
|
|
| MD5 |
3bc9cdbdf2fd3399b568889271d40006
|
|
| BLAKE2b-256 |
5a043986aba22f341b8b13b1ef2f1610c5d9bc0260c6f9f45fbbfdbcda84fbb4
|