...
 
Commits (8)
19-11-2016
Version 1.3.3
[Updated] - Updated to make HEX codes case-insensitive #2
[Added] - Added a `stylize()` convenience method #3
02-11-2016
Version 1.3.2
[Updated] - Merge back and fore colors names
20-09-2016
Version 1.3.1
......
......@@ -57,7 +57,7 @@ Attributes:
| 25 | res_blink |
| 27 | res_reverse |
| 28 | res_hidden |
+------------------------+
+------------------------+
256 Foreground and Background Colors - Full Chart:
......@@ -84,8 +84,8 @@ Attributes:
| 14 | light_cyan |
| 15 | white |
| 16 | grey_0 |
| 17 | navy_blue |
| 18 | dark_blue |
| 17 | navy_blue |
| 18 | dark_blue |
| 19 | blue_3a |
| 20 | blue_3b |
| 21 | blue_1 |
......@@ -364,20 +364,20 @@ How to use the module in your own python code:
>>> from colored import fg, bg, attr
>>>
>>> print ('%s Hello World !!! %s' % (fg(1), attr(0)))
Hello World !!!
>>>
Hello World !!!
>>>
>>> print ('%s%s Hello World !!! %s' % (fg(1), bg(15), attr(0)))
Hello World !!!
Hello World !!!
Use description:
.. code-block:: bash
>>> print ('%s%s Hello World !!! %s' % (fg('white'), bg('yellow'), attr('reset')))
Hello World !!!
>>>
Hello World !!!
>>>
>>> print ('%s%s Hello World !!! %s' % (fg('orchid'), attr('bold'), attr('reset')))
Hello World !!!
Hello World !!!
>>>
>>> color = bg('indian_red_1a') + fg('white')
>>> reset = attr('reset')
......@@ -388,11 +388,29 @@ Or use HEX code:
.. code-block:: bash
>>> color = fg('#c0c0c0') + bg('#00005f')
>>> color = fg('#C0C0C0') + bg('#00005f')
>>> res = attr('reset')
>>> print (color + "Hello World !!!" + res)
Hello World !!!
Or the convenient `stylize(text, *styles)` wrapper to save some keystrokes:
.. code-block:: bash
>>> import colored
>>> from colored import stylize
>>> print(stylize("This is green.", colored.fg("green")))
This is green.
>>> print("This is not.")
This is not.
>>> angry = colored.fg("red") + colored.attr("bold")
>>> print(stylize("This is angry text.", angry))
This is angry text.
>>> print(stylize("This is VERY angry text.", angry, colored.attr("underlined")))
This is VERY angry text.
>>> print("But this is not.")
But this is not.
Use directly like `colorama <https://pypi.python.org/pypi/colorama>`_ but with more colors:
.. code-block:: bash
......@@ -426,7 +444,7 @@ Import colored module:
'\x1b[38;5;4m'
etc.
Screenshot:
......
......@@ -30,5 +30,5 @@ from .fore import *
from .back import *
from .style import *
__version_info__ = (1, 3, 2)
__version_info__ = (1, 3, 3)
__version__ = '{0}.{1}.{2}'.format(*__version_info__)
......@@ -46,7 +46,7 @@ class colored(object):
self.color = color
if str(color).startswith("#"):
self.HEX = HEX(color)
self.HEX = HEX(color.lower())
else:
self.HEX = ""
......@@ -384,3 +384,9 @@ def fg(color):
def bg(color):
"""alias for colored().background()"""
return colored(color).background()
def stylize(text, styles, reset=True):
"""conveniently styles your text as and resets ANSI codes at its end."""
terminator = attr("reset") if reset else ""
return "{}{}{}".format("".join(styles), text, terminator)
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""test foreground and background colors"""
import time
from colored import fg, bg, attr
def main():
colors = (
"#000000",
"#800000",
"#008000",
"#808000",
"#000080",
"#800080",
"#008080",
"#C0C0C0",
"#808080",
"#FF0000",
"#00FF00",
"#FFFF00",
"#0000FF",
"#FF00FF",
"#00FFFF",
"#FFFFFF",
"#000000",
"#00005F",
"#000087",
"#0000AF",
"#0000D7",
"#0000FF",
"#005F00",
"#005F5F",
"#005F87",
"#005FAF",
"#005FD7",
"#005FFF",
"#008700",
"#00875F",
"#008787",
"#0087AF",
"#0087D7",
"#0087FF",
"#00AF00",
"#00AF5F",
"#00AF87",
"#00AFAF",
"#00AFD7",
"#00AFFF",
"#00D700",
"#00D75F",
"#00D787",
"#00D7AF",
"#00D7D7",
"#00D7FF",
"#00FF00",
"#00FF5F",
"#00FF87",
"#00FFAF",
"#00FFD7",
"#00FFFF",
"#5F0000",
"#5F005F",
"#5F0087",
"#5F00AF",
"#5F00D7",
"#5F00FF",
"#5F5F00",
"#5F5F5F",
"#5F5F87",
"#5F5FAF",
"#5F5FD7",
"#5F5FFF",
"#5F8700",
"#5F875F",
"#5F8787",
"#5F87AF",
"#5F87D7",
"#5F87FF",
"#5FAF00",
"#5FAF5F",
"#5FAF87",
"#5FAFAF",
"#5FAFD7",
"#5FAFFF",
"#5FD700",
"#5FD75F",
"#5FD787",
"#5FD7AF",
"#5FD7D7",
"#5FD7FF",
"#5FFF00",
"#5FFF5F",
"#5FFF87",
"#5FFFAF",
"#5FFFD7",
"#5FFFFF",
"#870000",
"#87005F",
"#870087",
"#8700AF",
"#8700D7",
"#8700FF",
"#875F00",
"#875F5F",
"#875F87",
"#875FAF",
"#875FD7",
"#875FFF",
"#878700",
"#87875F",
"#878787",
"#8787AF",
"#8787D7",
"#8787FF",
"#87AF00",
"#87AF5F",
"#87AF87",
"#87AFAF",
"#87AFD7",
"#87AFFF",
"#87D700",
"#87D75F",
"#87D787",
"#87D7AF",
"#87D7D7",
"#87D7FF",
"#87FF00",
"#87FF5F",
"#87FF87",
"#87FFAF",
"#87FFD7",
"#87FFFF",
"#AF0000",
"#AF005F",
"#AF0087",
"#AF00AF",
"#AF00D7",
"#AF00FF",
"#AF5F00",
"#AF5F5F",
"#AF5F87",
"#AF5FAF",
"#AF5FD7",
"#AF5FFF",
"#AF8700",
"#AF875F",
"#AF8787",
"#AF87AF",
"#AF87D7",
"#AF87FF",
"#AFAF00",
"#AFAF5F",
"#AFAF87",
"#AFAFAF",
"#AFAFD7",
"#AFAFFF",
"#AFD700",
"#AFD75F",
"#AFD787",
"#AFD7AF",
"#AFD7D7",
"#AFD7FF",
"#AFFF00",
"#AFFF5F",
"#AFFF87",
"#AFFFAF",
"#AFFFD7",
"#AFFFFF",
"#D70000",
"#D7005F",
"#D70087",
"#D700AF",
"#D700D7",
"#D700FF",
"#D75F00",
"#D75F5F",
"#D75F87",
"#D75FAF",
"#D75FD7",
"#D75FFF",
"#D78700",
"#D7875F",
"#D78787",
"#D787AF",
"#D787D7",
"#D787FF",
"#D7AF00",
"#D7AF5F",
"#D7AF87",
"#D7AFAF",
"#D7AFD7",
"#D7AFFF",
"#D7D700",
"#D7D75F",
"#D7D787",
"#D7D7AF",
"#D7D7D7",
"#D7D7FF",
"#D7FF00",
"#D7FF5F",
"#D7FF87",
"#D7FFAF",
"#D7FFD7",
"#D7FFFF",
"#FF0000",
"#FF005F",
"#FF0087",
"#FF00AF",
"#FF00D7",
"#FF00FF",
"#FF5F00",
"#FF5F5F",
"#FF5F87",
"#FF5FAF",
"#FF5FD7",
"#FF5FFF",
"#FF8700",
"#FF875F",
"#FF8787",
"#FF87AF",
"#FF87D7",
"#FF87FF",
"#FFAF00",
"#FFAF5F",
"#FFAF87",
"#FFAFAF",
"#FFAFD7",
"#FFAFFF",
"#FFD700",
"#FFD75F",
"#FFD787",
"#FFD7AF",
"#FFD7D7",
"#FFD7FF",
"#FFFF00",
"#FFFF5F",
"#FFFF87",
"#FFFFAF",
"#FFFFD7",
"#FFFFFF",
"#080808",
"#121212",
"#1C1C1C",
"#262626",
"#303030",
"#3A3A3A",
"#444444",
"#4E4E4E",
"#585858",
"#626262",
"#6C6C6C",
"#767676",
"#808080",
"#8A8A8A",
"#949494",
"#9E9E9E",
"#A8A8A8",
"#b2b2b2",
"#bCbCbC",
"#C6C6C6",
"#D0D0D0",
"#DADADA",
"#E4E4E4",
"#EEEEEE"
)
for color in colors:
print(
"{}This text is colored: {}{}".format(
fg(color),
color,
attr("reset")))
print(
"{}This text is colored: {}{}".format(
bg(color),
color,
attr("reset")))
time.sleep(0.1)
if __name__ == "__main__":
main()