Skip to main content

Small package made for using ANSI codes

Project description

copy (colorfulPython)

Library for outputting colorful text

Supports up to 16 foreground and 16 background colors


Color table

Table from Wikipedia


QuickStart

Use: pip install -i https://test.pypi.org/simple/ ansiColor to install the module.

Imports

import ansiColor
from ansiColor import colors # Imports class full of colors to choose from
from ansiColor import decorations # Imports class full of decorations
from ansiColor import cursor # Imports class for cursor movement

Testing the installation

import ansiColor
print( ansiColor.test() ) # This will print the project logo

Functions

color()

The color function is used to create colored strings.

Arguments:

  • String
  • Foreground color
  • Background color [Optional]

Example:

import ansiColor
from ansiColor import colors

print( ansiColor.color("Hello world!", colors.foreground.red) )

Returns string


colorNoReset()

The color function is used to create colored strings, does not set the color back to default (continues to color any future output).

Arguments:

  • String
  • Foreground color
  • Background color [Optional]

Example:

import ansiColor
from ansiColor import colors

print( ansiColor.colorNoReset("Hello world!", colors.foreground.red) )

Returns string


formatting()

Function used for formatting text.

Arguments:

  • String
  • Formatting type

Example:

import ansiColor
from ansiColor import decorations

print( ansiColor.formatting("Hello world!", decorations.bold) )

Returns string


formattingNoReset()

Function used for formatting text, does not set the color back to default (continues to decorate any future output).

Arguments:

  • String
  • Formatting type

Example:

import ansiColor
from ansiColor import decorations

print( ansiColor.formatting("Hello world!", decorations.bold) )

Returns string


reset()

Function used for resetting the color after using colorNoReset()

Arguments:

  • None

Example:

import ansiColor

print( ansiColor.reset() )

Returns string


test()

Function for testing the installation of the package, returns the project logo.

Arguments:

  • None

Example:

import ansiColor

print( ansiColor.test() )

Returns string


Codes

Colors

Foreground

colors.foreground.

red
black
green
yellow
blue
magenta
cyan
white
brightBlack
brightRed
brightGreen
brightYellow
brightBlue
brightMagenta
brightCyan
brightWhite

Background

colors.background.

red
black
green
yellow
blue
magenta
cyan
white
brightBlack
brightRed
brightGreen
brightYellow
brightBlue
brightMagenta
brightCyan
brightWhite

Decorations

decorations.

bold
underline
reverse

Cursor

cursor.

up
down
right
left

Exceptions

NotAColor

Exception for when the argument given is not an ANSI code.

Example of code that would trigger this Exception:

import ansiColor
from ansiColor import colors

print( ansiColor.color("Hello world!", "red") ) # This is an example of bad code, do not use this, it will not work.

correct code:

import ansiColor
from ansiColor import colors

print( ansiColor.color("Hello world!", colors.foreground.red) )

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

pylor-0.0.1.tar.gz (3.2 kB view hashes)

Uploaded Source

Built Distribution

pylor-0.0.1-py3-none-any.whl (3.9 kB view hashes)

Uploaded Python 3

Supported by

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