Skip to main content

Very simple Python library for color and formatting in terminal.

Project description

https://badge.fury.io/py/colored.png https://pypip.in/d/colored/badge.png https://pypip.in/license/colored/badge.png

colored

Very simple Python library for color and formatting in terminal.

example

The following colors works with most terminals and terminals emulators. ANSI/VT100 escape sequences can be used in every programming languages.

Set:

+-----+-------------+
|Code | Description |
+-----+-------------+
|  1  | bold        |
|  2  | dim         |
|  4  | underlined  |
|  5  | blink       |
|  7  | reverse     |
|  8  | hidden      |
+-------------------+

Reset:

+-----+-------------+
|Code | Description |
+-----+-------------+
|  0  | all         |
| 21  | bold        |
| 22  | dim         |
| 24  | underlined  |
| 25  | blink       |
| 27  | reverse     |
| 28  | hidden      |
+-----+-------------+

Foreground (text):

+-----+---------------+
|Code | Description   |
+-----+---------------+
| 39  | default       |
| 30  | black         |
| 31  | red           |
| 32  | green         |
| 33  | yellow        |
| 34  | blue          |
| 35  | magenta       |
| 36  | cyan          |
| 37  | light_gray    |
| 90  | dark_gray     |
| 91  | light_red     |
| 92  | light_green   |
| 93  | light_yellow  |
| 94  | light_blue    |
| 95  | light_magenta |
| 96  | light_cyan    |
| 97  | white         |
+-----+---------------+

Background:

+-----+---------------+
|Code | Description   |
+-----+---------------+
| 49  | default       |
| 40  | black         |
| 41  | red           |
| 42  | green         |
| 43  | yellow        |
| 44  | blue          |
| 45  | magenta       |
| 46  | cyan          |
| 47  | light_gray    |
| 100 | dark_gray     |
| 101 | light_red     |
| 102 | light_green   |
| 103 | light_yellow  |
| 104 | light_blue    |
| 105 | light_magenta |
| 106 | light_cyan    |
| 107 | white         |
+-----+---------------+

256 Colors Foreground (text):

256 fg colors

256 Colors Background:

256 bg colors

Installation

$ pip install colored

uninstall

$ pip uninstall colored

Usage Examples

How to use the module in your own python code:

Modules : colored.fg(), colored.fg256(), colored.bg(), colored.bg256(), colored.set(), colored.reset()

>>> import colored
>>>
>>> red = colored.fg(31)
>>> default = colored.fg(39)
>>> print ('%s Hello World !!! %s') % (red, default)
 Hello World !!!

or you car use description:

>>> green = colored.fg('green')
>>> default = colored.fg('default')
>>> print ('%s Hello World !!! %s') % (green, default)
 Hello World !!!

using format method:

>>> bold = colored.set('bold')
>>> print ('{0}{1} Hello World !!! {2}'.format(green, bold, default))
 Hello World !!!

print 256 colors:

>>> color = colored.fg256(165)
>>> color
'\x1b[38;5;165m'
>>> print color + 'Hello World !!!' + colored.reset(0)
Hello World !!!
>>> bg_color = colored.bg256(115)
>>> print color + bg_color + 'Hello World !!!' + colored.reset(0)
Hello World !!!

Screenshot:

example

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

colored-1.0.1.tar.gz (108.8 kB view details)

Uploaded Source

File details

Details for the file colored-1.0.1.tar.gz.

File metadata

  • Download URL: colored-1.0.1.tar.gz
  • Upload date:
  • Size: 108.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for colored-1.0.1.tar.gz
Algorithm Hash digest
SHA256 6a4da2eb55b48150ed3103ecb39c3145a7d864d6e6d6836f45dcf93867b93a0b
MD5 ef031ec408a09974b887c30a611f0579
BLAKE2b-256 cfdc6db0009d5937831ba66bf9d2fbbbeca91664e5f4fb4274a0d56af5acf3e4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page