Simple Python Library to display text with color in Python Terminal

Overview

pyTextColor v1.0

Introduction

pyTextColor is a simple Python Library to display colorful outputs in Terminal, etc.

Note: Your Terminal or any software in which you are going to print a text should support the ANSI Escape Sequences or it may not work!

Install

To install this library, type pip install pyTextColor in the Terminal(command prompt)

Import

To import the library, use the following code:

import pyTextColor

Print Basic Colored Output

See the following program to print a colorful text in Python!

import pyTextColor  # Import the library

pytext = pyTextColor.pyTextColor()  # Create an object of the pyTextColor class

text = pytext.format_text(text="Hi!", color="white",
                          bgcolor="black")  # Format the text with the color/bgcolor of your choice

print(text)  # Print the text

The above program will give the output as:

Image 1

You can also change the style/color/background of the text!

Following is a list of all color names you can use for both background and text:

  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white

Note: You can also use HEX color values to color a text or background. Remember: HEX color values should have '#' before the main color value

Example Code:

import pyTextColor

pytext = pyTextColor.pyTextColor()

text = pytext.format_text(text="This text will be printed out in yellow color with red background", color="#ff0000",
                          bgcolor="#FFFF00")  # HEX values

print(text)  # Print the text

The output of the above code will be:

Image 2

Text Styles

There are many text styles you can use. Use the text_style parameter to change the text style. Example code:

import pyTextColor

pytext = pyTextColor.pyTextColor()

text = pytext.format_text(text="I am bold text", color="#ff0000",
                          bgcolor="#FFFF00", text_style="bold")  # bold text

print(text)  # Print the text

The output of the above program will be:

Image 3

There are many text styles you can use! See the list of available styles:

  • normal > for normal text
  • bold > for bold text
  • faint > for faint text
  • italic > for italic text
  • underline > for underlined text
  • blink > for blinking text
  • reverse > for reversed text. The color of the text will be changed to background color while the background color will be changed to text color
  • hidden > for hidden text
  • strikethrough > for strikethrough text

Print the documentation

To pretty print the documentation for this library, run the following code:

import pyTextColor

pytext = pyTextColor.pyTextColor()
pytext.pretty_print_help()  # Print the docs

The output will be:

Image 4

Parameters of the format_text() function

The format_text() function has many parameters such as:

  • text > The text you want
  • color > The color you want
  • bgcolor > The background color you want
  • text_style > The text style you want
  • bg_full_line > Set this to True if you want the background color to be printed on full line

Make output fully customised?

See the following program to make the output fully customized:

import pyTextColor

pytext = pyTextColor.pyTextColor()

color = pytext.color  # Color Function
style = pytext.style  # Style Function
bg = pytext.background  # Background Function
reset = pytext.reset  # Reset Function (To reset all styles/colors/etc.)

name = "Siddhesh"
age = 15
hobby = "programming"

text = f"""{bg("black")}{color("#ffffff")}Hi! I am {color("magenta")}{name}{color("#ffffff")}. I am {color("magenta")}{age}{color("#ffffff")} years old. My favourite hobby is {color("green")}{style("italic")}{hobby}{reset()}"""  # Make an f-string and edit the text

print(text)  # Print the output

The output will be:

Image 5

Remember to use the reset() function or the normal text will be printed out with styles when you print a text below the styled text.

Thank you!

Owner
Siddhesh Chavan
I am a 15 year old boy who loves coding!
Siddhesh Chavan
A CLI Password Manager made using Python and Postgresql database.

ManageMyPasswords (CLI Edition) A CLI Password Manager made using Python and Postgresql database. Quick Start Guide First Clone The Project git clone

Imira Randeniya 1 Sep 11, 2022
This is a simple Termo application in command line style

my-termo This is a simple Termo application in command line style. This app run a Linux crontab task every day to get a new word. Type termo in your t

Gustavo Soares 1 Feb 14, 2022
A simple CLI tool for converting logs from Poker Now games to other formats

🂡 Poker Now Log Converter 🂡 A command line utility for converting logs from Poker Now games to other formats. Introduction Poker Now is a free onlin

6 Dec 23, 2022
NudeNet wrapper made to provide a simple cli interface to the library

Nudenet Wrapper. Small warpper script for NudeNet Made to provide a small and easy to use cli interface with the library. You can indicate a single im

1 Oct 20, 2021
Themes for the kitty terminal emulator

Themes for the kitty terminal This is a collection of themes for the kitty terminal emulator. The themes were initially imported from dexpota/kitty-th

Kovid Goyal 190 Jan 05, 2023
A project designed to make taking notes easier than ever - by doing it all on command line

A project designed to make taking notes easier than ever - by doing it all on command line! Yes, all of your files are easily accessible through one command interface, and can be written to at any ti

1 Dec 10, 2021
A CLI minesweeper application written in 60 LoC python

This is a CLI minesweeper application written in 60 LoC python. You can use d row,column to dig and f row,column to flag/unflag

1 Dec 21, 2021
Python CLI for accessing CSCI320 PDM Database

p320_14 Python CLI for accessing CSCI320 PDM Database Authors: Aidan Mellin Dan Skigen Jacob Auger Kyle Baptiste Before running the application for th

Aidan Mellin 1 Nov 23, 2021
AML Command Transfer. A lightweight tool to transfer any command line to Azure Machine Learning Services

AML Command Transfer (ACT) ACT is a lightweight tool to transfer any command from the local machine to AML or ITP, both of which are Azure Machine Lea

Microsoft 11 Aug 10, 2022
Pynavt is a cli tool to create clean architecture app for you including Fastapi, bcrypt and jwt.

Pynavt _____ _ | __ \ | | | |__) | _ _ __ __ ___ _| |_ | ___/ | | | '_ \ / _` \ \ / /

Alejandro Castillo 1 Dec 13, 2021
Trans is a dependency-free CLI for Google Translate

Trans is a dependency-free CLI for Google Translate

11 Jan 04, 2022
A Python module and command line utility for working with web archive data using the WACZ format specification

py-wacz The py-wacz repository contains a Python module and command line utility for working with web archive data using the WACZ format specification

Webrecorder 14 Oct 24, 2022
Aurornis - The Command Line Program Test Helper

Aurornis - The Command Line Program Test Helper Aurornis is a small, yet powerful library designed to help testing command line programs. The name is

Jérôme Deuchnord 1 Mar 08, 2022
A helper program to play wordle

A helper program to play wordle

1 Jan 22, 2022
commandpack - A package of modules for working with commands, command packages, files with command packages.

commandpack Help the project financially: Donate: https://smartlegion.github.io/donate/ Yandex Money: https://yoomoney.ru/to/4100115206129186 PayPal:

4 Sep 04, 2021
open a remote repo locally quickly

A command line tool to peek a remote repo hosted on github or gitlab locally and view it in your favorite editor. The tool handles cleanup of the repo once you exit your editor.

Rahul Nair 44 Dec 16, 2022
Amazon Scraper: A command-line tool for scraping Amazon product data

Amazon Product Scraper: 2021 Description A command-line tool for scraping Amazon product data to CSV or JSON format(s). Requirements Python 3 pip3 Ins

49 Nov 15, 2021
command line interface to manage VALORANT skins

A PROPER RELEASE IS COMING SOON, IF YOU KNOW HOW TO USE PYTHON YOU CAN USE IT NOW! valorant skin manager command line interface simple command line in

colinh 131 Dec 25, 2022
Command-line tool to use LNURL with your LND instance

Sprint planner Sprint planner is a Python script for planning your Jira tasks based on your calendar availability. Installation Use the package manage

Djuri Baars 6 Jan 14, 2022
A dec-bin converter uses 2's complement.

2's Complement Dec-Bin Converter A dec-bin converter uses 2's complement. Visit my Medium Post. What is 2's complement? Two's complement is the most c

Khaw Chi Hun (Jacky) 9 Mar 01, 2022