Skip to main content

A small lib to ease the coloring of your Terminal text logs with ANSI colors

Project description

Colorido

Colors for Terminal without weird code.

Description

Colorido is a small Python 3.x lib to speed up the text coloring throughout your Python projects. You ever can make your logs prettier. ;)

You don't need to install any dependency to use colorido. In a nutshell, just import the color module from the colorido package and call the functions in a print context to start coloring your strings.

Installation

Install it with pip by running:

pip install colorido

Usage

To use the colorido abilities, import the color module in your code and just call the function with the color you want to print. See how in the example below:

from colorido import color

print('This is the color ' + color.red('red') + '.')

Coloring

You can choose the color you want among the eight available color options. The supported options are:

Text color Function
Black black(str)
Blue blue(str)
Cyan cyan(str)
Green green(str)
Magenta magenta(str)
Red red(str)
White white(str)
Yellow yellow(str)

ℹ️ Note: the visual colors may vary according with the configuration of your Terminal or system.

Basic examples

Below we have some examples of colorido's general usage.

Example 1:

from colorido import color

text = color.green('BR') + color.yellow('AZ') + color.blue('IL')
print('Come to visit %s.' % text)

Example 2:

from colorido import color

print(f'sudo {color.red("rm -rf /")}')

Example 3:

from colorido import color

print(
    'Is zebra {black} with {white} stripes or {white} with {black} stripes?'.format(
        black=color.black('BLACK'),
        white=color.white('WHITE'),
    )
)

Styling

Colorido also support text styling. The styles modify the heavy of the text. The supported styles are:

  • Dim text
  • Normal text
  • Bold text

You can style your text by passing an extra optional style parameter to the color functions. For example, to get a bold red text, you can do:

Example 4:

from colorido import color

print(color.red('STOP', style='bold'), 'deploys at friday!')

You can also omit the style keyword and pass the style parameter just like a positional parameter.

Example 5:

from colorido import color

print(color.magenta('Dimmed', 'dim'), 'texts are calm.')

Colorido supports three types of text styling.

Text style Parameter
Dim 'd' or 'dim'
Normal 'n' or 'normal' (default)
Bold 'b' or 'bold'

If you don't want to color your text, you can use the font() function to skip the text coloring. For this, provide the desired style parameter just like you do in the coloring functions. See how:

Example 6:

from colorido import color

print(
    '{I} {love} {linux}.'.format(
        I=color.font('I', 'bold'),
        love=color.red('<3', 'bold'),
        linux=color.font('Linux', 'dim'),
    )
)

Background color

New in version 1.0.0!

You can also color the background of your logs! Just provide a bg parameter to any color function with the name of the color you want.

Example 7:

from colorido import color

print(
    'The sun rules the {day} and the moon rules the {night}.'.format(
        day=color.yellow('day', bg='white'),
        night=color.blue('night', bg='black'),
    )
)

The available background colors are the same eight available in the foreground text colors. Below you have a list with the color options:

Background color Parameter
Black 'black'
Blue 'blue'
Cyan 'cyan'
Green 'green'
Magenta 'magenta'
Red 'red'
White 'white'
Yellow 'yellow'

If you want to use just the background color, with no foreground text color, you can call again the font() function, providing the bg parameter. For example:

Example 8:

from colorido import color

print(
    'If your {code} have many {bugs}, you propably need more {coffee}.'.format(
        code=color.font('code', bg='blue'),
        bugs=color.font('bugs', bg='red'),
        coffee=color.font('coffee', bg='black'),
    )
)

You can also style your text while you choose your background color, just like we have done in styling section. See an example:

Example 9:

from colorido import color

print(
    'The {white} {light} can split in a beautiful {ra}{i}{n}{b}{o}{w}.'.format(
        # We can style and also background our text with font() function
        white=color.font('white', 'bold', bg='white'),
        light=color.font('light', 'bold', bg='black'),
        ra=color.red('ra'),
        i=color.yellow('i'),
        n=color.green('n'),
        b=color.cyan('b'),
        o=color.blue('o'),
        w=color.magenta('w'),
    )
)

That's all folks! Bugs, questions or coffees, feel free to reach me in my e-mail.

Who is this lib for?

Colorido is addressed to anyone who wants a simple lib to print colored texts in the screen without a hundred of things to learn. You just need to import the module and call the functions you want to.

Colorido doesn't match programmers that want a full-featured lib. It just returns colored texts to be printed in the screen. No things more. If this is not your vibe, consider search for other python libraries (like colorama, colored or PyColor).

License

This lib is a free software and is distributed under the MIT 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 Distribution

colorido-1.0.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

colorido-1.0.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file colorido-1.0.0.tar.gz.

File metadata

  • Download URL: colorido-1.0.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for colorido-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4285733bd0a170f05933737206e28768470c3e1517d4a1e0079471e68a9b3cc7
MD5 326e40914a51e5e81f5443a8cd4dae5d
BLAKE2b-256 2b9a6d18a6c7685896329cdd1ab5272fd1e58d1cc026a8ccefc289489b8f91c1

See more details on using hashes here.

File details

Details for the file colorido-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: colorido-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for colorido-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 96106213bea94ce1a9f3511335bff5d46f86eae104204a28a371b80d6f124dbf
MD5 c2b43b7c5c96fae05a4d0b4192578b32
BLAKE2b-256 3f77377cc83d4952a3f455a06ce0a06070a1c569a6bf16a7c1812e9f236f935e

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