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 hashes)

Uploaded Source

Built Distribution

PyTermUtils-0.0.0-py3-none-any.whl (5.6 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