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
This is a repository for collecting global custom management extensions for the Django Framework.

Django Extensions Django Extensions is a collection of custom extensions for the Django Framework. Getting Started The easiest way to figure out what

Django Extensions 6k Jan 03, 2023
Kubernetes shell: An integrated shell for working with the Kubernetes

kube-shell Kube-shell: An integrated shell for working with the Kubernetes CLI Under the hood kube-shell still calls kubectl. Kube-shell aims to provi

CloudNative Labs 2.2k Jan 08, 2023
PyDropper - pick colors everywhere

PyDropper - pick colors everywhere Downloads Settings PyDropper is an eyedropper

Herman Brunberg 2 Jan 04, 2022
Baseline is a cross-platform library and command-line utility that creates file-oriented baselines of your systems.

Baselining, on steroids! Baseline is a cross-platform library and command-line utility that creates file-oriented baselines of your systems. The proje

Nelson 4 Dec 09, 2022
A command line tool to query source code from your current Python env

wxc wxc (pronounced "which") allows you to inspect source code in your Python environment from the command line. It is based on the inspect module fro

Clément Robert 13 Nov 08, 2022
A command-line tool to upload local files and pastebin pastes to your mega account, without signing in anywhere

A command-line tool to upload local files and pastebin pastes to your mega account, without signing in anywhere

ADI 4 Nov 17, 2022
A multipurpose discord bot with more than 220 commands

Welcome WM Bot A advanced bot with more than 220 commands to fit your needs Explore the commands » View Demo · Report Bug · Request Feature Table of C

Wasi Master 12 Dec 16, 2022
Lsp Plugin for working with Python virtual environments

py_lsp.nvim What is py_lsp? py_lsp.nvim is a neovim plugin that helps with using the lsp feature for python development. It tackles the problem about

Patrick Haller 55 Dec 27, 2022
Tool for HackMyVM platform

HMV-cli It is a tool for the HackMyVM platform. With this tool you will be able to see the machines you have pending, filter by difficulty, download d

bitc0de 11 Sep 19, 2022
keep your machine's shell history synchronize

SyncShell Yet another tool for laziness Keep your machine's shell history synchronize Get SyncShell Currently, SyncShell is just available on PyPi and

Masoud Ghorbani 53 Dec 12, 2022
Tools hacking termux in the name ant-attack

Hello friends, I am ama.player0000. Web developer, software, Android command line (termux). (1)=Well, ant-attack tool is a tool to attack sites and disable them. (2)=You can use those CCTV servers, s

༺AMA.PLAYER༻ 1 Dec 17, 2021
A terminal application for managing images and artifacts in Azure Container Registry.

acr-browser acr-browser is a terminal-based user interface for managing container images and artifacts in Azure Container Registry. 🚀 This project ow

Sam Dobson 5 Jul 30, 2022
Terminal with builtin ortholinear keyboard and touch screen as a home automation interface.

OLKB-Terminal Terminal with builtin ortholinear keyboard and touch screen as a home automation interface. Features Step and STLs available for non-com

Jeff Eberl 50 Oct 07, 2022
An awesome Python wrapper for an awesome Docker CLI!

An awesome Python wrapper for an awesome Docker CLI!

Gabriel de Marmiesse 303 Jan 03, 2023
A minimal todo list for your terminal.

todo A minimal todo list for your terminal. Installation Run the following command. pip install git+https://github.com/piero-vic/todo.git Usage todo

Piero Lescano 7 Aug 08, 2022
A minimal and ridiculously good looking command-line-interface toolkit.

Pyceo Pyceo is a Python package for creating beautiful, composable, and ridiculously good looking command-line-user-interfaces without having to write

Juan-Pablo Scaletti 21 Mar 25, 2022
Basic python tools to generate shellcode runner in vba

vba_bin_runner Basic python tools to generate shellcode runner in vba. The stub use ZwAllocateVirtualMemory to allocate memory, RtlMoveMemory to write

4 Aug 24, 2021
Play Wordle Bot - Wordle Bot written in python

Wordle Bot A Bot written in python with a CL Interface to guess adn solve Wordle

Prashant 1 Feb 25, 2022
Stream comments, submissions from subreddits and users across reddit right in your terminal

reddit_from_terminal stream comments, submissions from subreddits and users across reddit right in your terminal Alert! : Can't watch media contents(p

Pritam Dhara 2 Dec 30, 2021
🐍The nx-python plugin allows users to create a basic python application using nx commands.

🐍 NxPy: Nx Python plugin This project was generated using Nx. The nx-python plugin allows users to create a basic python application using nx command

StandUP Communications 74 Aug 31, 2022