Skip to main content

A Python library for ANSI color formatting for terminal/console output

Project description

PyTermUtils


PyTermUtils is a Python library that allows you to easily print colored text to the console/terminal. It provides a simple way to enhance the visual appeal of terminal output by using different colors and styles.

Features


  • Print text in various colors
  • Apply different text styles (bold, underline, etc.)
  • Easy-to-use Package

Installation


You can install console via pip:

pip install console

Usage


Here are some examples of how to use console package in your project:

Basic Usage

from console import *

# Print text in bright red and Highlight in bright green (16 colors)
Console.Print16C("Bright Red", ConsoleColor.Bright_Red, 
                 ConsoleColor.Bright_Green, resetmode=ResetMode.ResetAll)

# Print text in Magenta and bold (256 colors)
Console.Print256C("Magenta", 90, textmode=TextMode.Bold)

# Print text in Magenta and Italic (rgb colors = 1,67,77,216)
Console.Printrgb("Red", (210, 0, 0), textmode=TextMode.Italic)

Available Colors


[!NOTE] Forground color -> Text color

Background color -> Highlight color

4 bits color (16 colors)

Sure! Here is a table for the 16 ANSI colors, which are often used in terminal applications for text coloring.

Color Name fg code bg code
Black 30 40
Red 31 41
Green 32 42
Yellow 33 43
Blue 34 44
Magenta 35 45
Cyan 36 46
White 37 47
Bright Black 90 100
Bright Red 91 101
Bright Green 92 102
Bright Yellow 93 103
Bright Blue 94 104
Bright Magenta 95 105
Bright Cyan 96 106
Bright White 97 107

To use these colors in a terminal, you use ANSI escape codes. The format for these codes is:

\e[<code>m or \033[<code>m

Click to see more about it

8 bits color (256 colors)

To use 8-bit colors in a terminal, the format of the escape code is:

\e[38;5;<color>m for foreground colors
\e[48;5;<color>m for background colors

16 bits colors img

24 bits color (True color) (8 bits each R-G-B)

24-bit color, also known as true color, allows for a much wider range of colors than 256-color ANSI. It uses 8 bits each for red, green, and blue components, allowing for 16,777,216 possible colors. This is particularly useful for applications requiring high color fidelity.

ANSI Code for 24-Bit Color To use 24-bit color in ANSI, you can use the following format:

Foreground Color: \033[38;2;R;G;Bm
Background Color: \033[48;2;R;G;Bm

Where R, G, and B are the red, green, and blue color values (0-255).

[!NOTE] All three(3) color mode of print have both foreground and background color.

Available Attributes


The following text styles are supported:

  • Bold
  • Dim
  • Italic
  • Underline
  • Blinking
  • Reverse
  • Hidden
  • Strikethrough

Example

Here is a more comprehensive example demonstrating the use of different colors and styles:

Contributing


Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License


This project is licensed under the MIT License. See the LICENSE file for details.

Contact


If you have any questions or suggestions, feel free to open an issue on GitHub.

References



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

pytermutils-0.0.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

PyTermUtils-0.0.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file pytermutils-0.0.0.tar.gz.

File metadata

  • Download URL: pytermutils-0.0.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for pytermutils-0.0.0.tar.gz
Algorithm Hash digest
SHA256 97643d0aa99493b47bde7458d933a5d6b855ff207a1a494143731098a3251e3a
MD5 2131decf81cc4770e4be5379394daa8e
BLAKE2b-256 b49a8be8749ebc58f77c0d483e7c560d89559de6a30b26c2c290b197b4402e3f

See more details on using hashes here.

File details

Details for the file PyTermUtils-0.0.0-py3-none-any.whl.

File metadata

  • Download URL: PyTermUtils-0.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for PyTermUtils-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3cea0baabcde1dd714accea6831e0f7d073464c2eecfe6fae05c8044ce200376
MD5 c407e0aaac27e74198b702bdc42d007d
BLAKE2b-256 7812ab563583283a76896371a7dab871bcd4b54a68c879b747a844a4f613eb1c

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