Skip to content
This repository has been archived by the owner on Mar 12, 2023. It is now read-only.
/ terminalcolorpy Public archive

simple package to print colored messages using ASCI to the terminal

License

Notifications You must be signed in to change notification settings

ammarsys/terminalcolorpy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

terminalcolorpy

A lightweight, dependency-free package to colorize your terminal text.

Overview

This is a package that utilizes ANSI escape sequences to colorize your stdout, terminal, printed messages and what not. The key-features include,

  • Fully tested with pytest
  • Fully documented & type-hinted
  • Dependency-free

Installation

The required Python version for this module is 3.10 or above

# Linux/MacOS
python3 -m pip install terminalcolorpy

# Windows
py -m pip install terminalcolorpy

Usage

The package consists of a few functions which are explained down below. In case your terminal (which is common with Windows) doesn't display the color at all, please run the following code,

import os

os.system('')

# your code onwards




->  Flip text to characters that are upsidedown version of that letter.



prainbow(text: str) -> str:

->  Returns text in colors of the rainbow (RGB 1-255, not CSPRNG).



blink(message: str, length: float = 1, new_message: str = " ") -> None:

->  Print the message then replace it with a new message.


    Beware, this function is **blocking** because of the print statement. If you need to run this function
    synchronously, please refer to the accepted answer of this S/O question,
    https://stackoverflow.com/questions/54685210/calling-sync-functions-from-async-function

    Args:
        message (str): message to be printed
        length (float): how long should the message stay
        new_message (str): message to be displayed after the timer expires (default is nothing)



printcolor(colored_kwargs: dict = None, **kwargs) -> None:

->  Implements a shortcut for using the builtin function print with this modules colored function.

    It works on any terminals that support ASCII codes, includes but not limited to:
    To use this in a Windows terminal, simply make an empty system call which enables colors in the terminal:
    
    Args:
        colored_kwargs (dict): keyword arguments for this modules colored function
        **kwargs: keyword arguments for the builtin print function



def colored(
    text: str,
    color: list | tuple | str,
    highlight: list | tuple | str | None = None,
    markup: list | tuple | None = None,
) -> str:
->  Parse color arguments and return the applied version to the text.

    Args:
        text (str): text to parse
        color (Union[list, tuple, str]): color for the text, accepts RGB, hex (str) and English words
        highlight ([list, tuple, str]): highlight for the text, accepts RGB, hex (str) and English words
        markup ([list, tuple]): markup from _Colors.color_dict