Skip to main content

the simplest package to apply style and color in terminal

Project description

Stylecolor - 1.0.0

Stylecolor

stylecolor is the simplest package for coloring and/or styling text in the terminal.
stylecolor requires no other modules and is very lightweight and efficient.

Installation

No prerequisites are needed, only stylecolor.

pip install stylecolor

Description

stylecolor uses ANSI escape codes to function. It is therefore compatible with all other libraries that use ANSI codes.

Some terminals do not support ANSI escape codes, so you can disable styling with deactivate(). In this case, you will still be able to use the functions, but the various styles will no longer be applied.
Use reactivate() to reactivate the styling.

I recommend importing stylecolor as sc or st.
Additionally, if you are debugging, I suggest importing the rprint() function like this: from stylecolor import rprint()

Coloring

8 colors are available natively: black, red, green, yellow, blue, magenta, cyan, and white.
For each color, there are functions (e.g. stylecolor.red()), as well as constants (e.g. stylecolor.RED).
For other colors, use stylecolor.rgb() or stylecolor.hexa().

Simple Colors

import stylecolor as sc
print(sc.red('red text'))
print(sc.green('green text'))
print(sc.blue('blue text'))
# ...
# AND/OR
print(sc.RED + 'constant red text' + sc.RESET)
print(sc.GREEN + 'constant green text' + sc.RESET)
print(sc.BLUE + 'constant blue text' + sc.RESET)
# ...

output:

red text
green text
blue text
...

constant red text
constant green text
constant blue text
...

Light Colors

You can add the prefix l in front of the color to make it a light version.

import stylecolor as sc
print(sc.lred('light red'))
print(sc.lgreen('light green'))
print(sc.lblue('light blue'))
# ...
# AND/OR
print(sc.LRED + 'constant red text' + sc.RESET)
print(sc.LGREEN + 'constant green text' + sc.RESET)
print(sc.LBLUE + 'constant blue text' + sc.RESET)
# ...

output

light red
light green
light blue
...

constant light red
constant light green
constant light blue
...

Background Colors

You can add the prefix b in front of each color to set it as a background color.

import stylecolor as sc
print(sc.bred('red background'))
print(sc.bgreen('green background'))
print(sc.bblue('blue background'))
# ...
# AND/OR
print(sc.BRED + 'constant red background' + sc.RESET)
print(sc.BGREEN + 'constant green background' + sc.RESET)
print(sc.BBLUE + 'constant blue background' + sc.RESET)
# ...

output

red background
green background
blue background
...

constant red background
constant green background
constant blue background
...

NOTE
You can also add b in front of the light colors.

import stylecolor as sc
print(sc.blred('light red background'))
print(sc.blgreen('light green background'))
print(sc.blblue('light blue background'))
# ...
#AND/OR"
print(sc.LBRED + 'constant light red background' + sc.RESET)
print(sc.LBGREEN + 'constant light green background' + sc.RESET)
print(sc.LBBLUE + 'constant light blue background' + sc.RESET)
# ...

output

light red background
light green background
light blue background
...

constant light red background
constant light green background
constant light blue background
...

Custom Colors

The rgb() and hexa() functions allow you to apply custom colors.

import stylecolor as sc
print(sc.rgb('personalised rgb color', '+ other text', r=250, g=200, b=0))
print(sc.rgb('personalised tuple rgb color', '+ other text', rgb=(250, 200, 0)))
print(sc.hexa('personalised hexadecimal color', '+ other value', hexa='#FAC800'))
print(sc.hexa('personalised hexadecimal color', "without '#'", hexa='FAC800'))

output

personalised rgb color + other text
personalised tuple rgb color + other text
personalised hexadecimal color + other value
personalised hexadecimal color without '#'

Custom Background Colors

The brgb() and bhexa() functions allow you to apply custom background colors.

import stylecolor as sc
print(sc.brgb('personalised rgb color', '(background)', r=250, g=200, b=0))
print(sc.brgb('personalised tuple rgb color', '(background)', rgb=(250, 200, 0)))
print(sc.bhexa('personalised hexadecimal color', '(background)', hexa='#FAC800'))
print(sc.bhexa('personalised background hexadecimal color', "without '#'", hexa='FAC800'))

output

personalised rgb color (background)
personalised tuple rgb color (background)
personalised hexadecimal color (background)
personalised background hexadecimal color without '#'

Reset Colors

The functions stylecolor.rcolor() or stylecolor.RCOLOR and stylecolor.rbackground() or stylecolor.RBACKGROUND respectively remove the text color and the background color.

>>> text = "green text"
>>> stylecolor.rcolor(text)
>>> "green text" >>> text = "background green text"
>>> stylecolor.rbackground(text)
>>> "background green text"

Built-in Styles

Apply Styles

In addition to colors, many styles are available: bold, dim, italic, underline, blinking, reverse, hidden, and strikethrough.
Just like with colors, styles are accessible via functions (e.g. stylecolor.bold()) or constants (e.g. stylecolor.BOLD).

import stylecolor as sc
print(sc.bold('bold text'))
print(sc.italic('italic text'))
print(sc.underline('underline text'))
# ...
# AND/OR
print(sc.BOLD, 'constant bold text', sc.RESET, sep='')
print(sc.ITALIC, 'constant italic text', sc.RESET, sep='')
print(sc.UNDERLINE, 'constant underline text', sc.RESET, sep='')
# ...

output

bold text
italic text
underline text
...

constant bold text
constant italic text
underline text
...

Reset Styles

You can add the prefix r in front of each style to cancel it (including with constants).

>>> text = "bold text"
>>> stylecolor.rbold(text)
>>> "bold text"
>>> text = "underline text"
>>> stylecolor.runderline(text)
>>> "underline text"

Other Styles

It is possible, using the functions stylecolor.style() and stylecolor.styles(), to apply one or more styles to text.
You can use textual styles like red, bred, underline, or directly use ANSI codes like 31, 41, 4, for example.

import stylecolor as sc
def func():
    pass
print(sc.style('text1', func, 'other text', style='blue'))
print(sc.styles('unique object', 'white', 'bblack', 'underline'))

output

text1 <function func at 0x00000XXXXXXXXXX> other text
unique object

Composability

Most functions and constants are composable with each other.

import stylecolor as sc
print(sc.blue(sc.underline('blue underline text'), 'blue text only'), 'normal text')
print(sc.styles('blue underline text', 'blue', 'underline', 'italic'))
# fonctions with constants
print(sc.green(sc.UNDERLINE, 'combined green underline text', sc.RUNDERLINE, ' green text only', sep=''), 'normal text')

output

blue underline text blue text only normal text
blue underline italic text

combined green underline text green text only normal text

NOTE
Foreground colors are not composable with each other, just like background colors.

import stylecolor as sc
print(sc.blue(sc.green('colored text in blue and green which appears blue')))
print(sc.bblue(sc.bgreen('background colored text in blue and green which appears blue')))

output

colored text in blue and green which appears blue
background colored text in blue and green which appears blue

Debug Functions

The functions raw() and rprint() allow you to get the raw version of a styled text.

import stylecolor as sc
colored = sc.blue("raw blue text")
raw = sc.raw(colored) # return raw string
print(raw)
sc.rprint(colored)  # directly print raw result

\033[0;34mraw blue text\033[0m
\033[0;34mraw blue text\033[0m

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

stylecolor-1.0.0.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

stylecolor-1.0.0-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: stylecolor-1.0.0.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for stylecolor-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1a2f46ea60218eecb55b0162a0e0789cf49b4e6f6e7e254983d053d006456e98
MD5 c4d6bcc13afd0c70eb3b4c3e0d7b81dd
BLAKE2b-256 7355c6f5011414f85fa31db63a6c27d1034de3db8309dc99f492c2a5259eccdd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stylecolor-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for stylecolor-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1d0ff998c172f671964e415f9098429904630daad2507150d54922398be7e6a8
MD5 d994ed7e52b7569d75a0643849283e59
BLAKE2b-256 54ef4a78e2d2a615477b244643fd66d2aea2a7711795a2bf78d5a9cd2bb17717

See more details on using hashes here.

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