Print 'text color' and 'text format' on Term with Python

Overview

term-printer

Print 'text color' and 'text format' on Term with Python

※ It may not work depending on the OS and shell used.

PIP

$ pip install term-printer

import

from term_printer import Color, Color256, ColorRGB, StdText, cprint

If you want to override bultin print function

from term_printer import Color, Color256, ColorRGB, StdText, cprint as print

Usage

1. Attrs print

Applies to all characters.

You can specify Format, Color, Color256, and ColorRGB.

Able to specify more than one.

source

from term_printer import Color, Color256, ColorRGB, Format, cprint

# default
cprint("this is a default pen")

# bold
cprint("this is a bold pen", attrs=[Format.BOLD])

# italic
cprint("this is a italic pen", attrs=[Format.ITALIC])

# red color
cprint("this is a red pen", attrs=[Color.RED])

# bright red color
cprint("this is a bright red pen", attrs=[Color.BRIGHT_RED])

# background magenta color
cprint("this is a bg magenta pen", attrs=[Color.BG_MAGENTA])

# background bright magenta color
cprint("this is a bg bright magenta pen", attrs=[Color.BG_BRIGHT_MAGENTA])

# magenta color & italic
cprint("this is a magenta italic pen", attrs=[Color.MAGENTA, Format.ITALIC])

# bold & italic
cprint("this is a bold italic pen", attrs=[Format.BOLD, Format.ITALIC])

# cyan color & bold & italic
cprint("this is a cyan bold italic pen", attrs=[Color.CYAN, Format.BOLD, Format.ITALIC])

# 8-bit color 154
cprint("this is a 8-bit 154 pen", attrs=[Color256(154)])

# 8-bit bg color 154 and magenta color
cprint("this is a bg 8-bit 154 pen", attrs=[Color256(154, is_bg=True), Color.MAGENTA])

# rgb(100, 255, 255) color
cprint("this is a rgb(100, 255, 255) pen", attrs=[ColorRGB(100, 255, 255)])

# bg rgb(100, 255, 255) color and black color
cprint(
    "this is a bg rgb(100, 255, 255) pen",
    attrs=[ColorRGB(100, 255, 255, is_bg=True), Color.BLACK],
)

result

2. StdText print

source

from term_printer import Color, Format, StdText, cprint

# default
cprint("this is a default pen")

# bold
cprint(f"this is a {StdText('bold', Format.BOLD)} pen")

# italic
cprint(f"this is a {StdText('italic', Format.ITALIC)} pen")

# reverse
cprint(f"this is a {StdText('reverse', Format.REVERSE)} pen")

# red color
cprint(f"this is a {StdText('red', Color.RED)} pen")

# background magenta color
cprint(f"this is a {StdText('bg magenta', Color.BG_MAGENTA)} pen")

# magenta color & italic
cprint(f"this is a {StdText('magenta', Color.MAGENTA)} {StdText('italic', Format.ITALIC)} pen")

# bold & italic
cprint(f"this is a {StdText('bold', Format.BOLD)} {StdText('italic', Format.ITALIC)} pen")

# cyan color & bold & italic
cprint(f"this is a {StdText('cyan', Color.CYAN)} {StdText('bold', Format.BOLD)} {StdText('italic', Format.ITALIC)} pen")

result

Color

class Color(Enum)

Enum class.

Example

from term_printer import Color

Color.RED  # RED foreground color
Color.BG_RED  # RED background color

Color.BLUE  # BLUE foreground color
Color.BG_BLUE  # BLUE background color

source

Definition is 3-bit and 4-bit colors

Color256

class Color256(n: int, is_bg: bool = False)
  • First argument takes int (0 - 255).

  • Second argument takes bool (default: False).
    False: change foreground color
    True: change background color

Example

from term_printer import Color256

Color256(9)  # RED foreground color
Color256(9, True)  # RED background color

Color256(12)  # BLUE foreground color
Color256(12, True)  # BLUE background color

Definition is 8-bit 256 colors

ColorRGB

class ColorRGB(r: int, g: int, b: int, is_bg: bool = False)
  • Three arguments takes int (0 - 255).

  • Fourth argument takes bool (default: False).
    False: change foreground color
    True: change background color

Example

from term_printer import ColorRGB

ColorRGB(255, 0, 0)  # RED foreground color
ColorRGB(255, 0, 0, True)  # RED background color

ColorRGB(0, 0, 255)  # BLUE foreground color
ColorRGB(0, 0, 255, True)  # BLUE background color

Format

class Format(Enum):
    BOLD = 1
    FAINT = 2
    ITALIC = 3
    UNDERLINE = 4
    BLINK = 5
    FAST_BLINK = 6
    REVERSE = 7
    CONCEAL = 8
    STRIKE = 9

Enum class.

Example

from term_printer import Format

Format.BOLD  # BOLD font
Format.FAINT  # FAINT font
Format.ITALIC  # ITALIC font
Format.UNDERLINE  # UNDERLINE font

Definition is SGR

You might also like...
A new mini-batch framework for optimal transport in deep generative models, deep domain adaptation, approximate Bayesian computation, color transfer, and gradient flow.

BoMb-OT Python3 implementation of the papers On Transportation of Mini-batches: A Hierarchical Approach and Improving Mini-batch Optimal Transport via

A simple single-color identicon generator

Identicons What are identicons? Setup: git clone https://github.com/vjdad4m/identicons.git cd identicons pip3 install -r requirements.txt chmod +x

The goal of this program was to find the most common color in my living room.

The goal of this program was to find the most common color in my living room. I found a dataset online with colors names and their corr

A lighweight screen color picker tool
A lighweight screen color picker tool

tkpick A lighweigt screen color picker tool Availability Only GNU/Linux 🐧 Installing Install via pip (No auto-update): [sudo] pip install tkpick Usa

Coursework project for DIP class. The goal is to use vision to guide the Dashgo robot through two traffic cones in bright color.

Coursework project for DIP class. The goal is to use vision to guide the Dashgo robot through two traffic cones in bright color.

It is a Blender Tool which can convert the Object Data Attributes in face corner to the UVs or Vertex Color.

Blender_ObjectDataAttributesConvertTool It is a Blender Tool which can convert the Object Data Attributes in face corner to the UVs or Vertex Color. D

App and Python library for parsing, writing, and validation of the STAND013 file format.

python-stand013 python-stand013 is a Python app and library for parsing, writing, and validation of the STAND013 file format. Features The following i

This python module allows to extract data from the RAW-file-format produces by devices from Thermo Fisher Scientific.

fisher_py This Python module allows access to Thermo Orbitrap raw mass spectrometer files. Using this library makes it possible to automate the analys

A python script that fetches the grades of a student from a WAEC result in pdf format.

About waec-result-analyzer A python script that fetches the grades of a student from a WAEC result in pdf format. Built for federal government college

Releases(v1.1)
Owner
ななといつ
GCP / Docker / Python / PHP / Java / Rust / JS / TS / Laravel / Django / Flask / Vue / LINEBot / Jailbreak Tweak Dev
ななといつ
TB Set color display - Add-on for Blender to set multiple objects and material Display Color at once.

TB_Set_color_display Add-on for Blender with operations to transfer name between object, data, materials and action names Set groups of object's or ma

null 1 Jun 1, 2022
This module extends twarc to allow you to print out tweets as text for easy testing on the command line

twarc-text This module extends twarc to allow you to print out tweets as text for easy testing on the command line. Maybe it's useful for spot checkin

Documenting the Now 2 Oct 12, 2021
A simple python script that print the Mandelbrot set for every power of the formal formula.

Python Mandelbrot A simple python script that print the Mandelbrot set for every power of the formal formula.

Paride Giunta 2 Apr 15, 2022
Python wrapper to different clients to determine how a particular term is used.

Python wrapper to different clients to determine how a particular term is used.

Chris Mungall 3 Oct 24, 2022
Render to print for blender 2.9+

render_to_print_blender_addon ** render2print: Blender AddOn for Blender 2.90.0+ ** Calculates camera parameters to allow printing a rendered image to

null 5 Nov 19, 2021
PyLaboratory 0 Feb 7, 2022
Configure request params such as text, color, size etc. And then download the image

Configure request params such as text, color, size etc. And then download the image

null 6 Aug 18, 2022
Convert text with ANSI color codes to HTML or to LaTeX.

Convert text with ANSI color codes to HTML or to LaTeX.

PyContribs 326 Dec 28, 2022
A Tandy Color Computer 1, 2, and 3 assembler written in Python

CoCo Assembler and File Utility Table of Contents What is it? Requirements License Installing Assembler Assembler Usage Input File Format Print Symbol

Craig Thomas 16 Nov 3, 2022
Scientific color maps and standardization tools

Scicomap is a package that provides scientific color maps and tools to standardize your favourite color maps if you don't like the built-in ones. Scicomap currently provides sequential, bi-sequential, diverging, circular, qualitative and miscellaneous color maps. You can easily draw examples, compare the rendering, see how colorblind people will perceive the color maps. I will illustrate the scicomap capabilities below.

Thomas Bury 14 Nov 30, 2022