Skip to main content

A module to help add colour in the terminal using batch colour codes.

Project description

colourise_output

PyPI - Python Version PyPI - Implementation PyPI - Wheel PyPI - Version PyPI - Downloads PyPI - License Execution status GitHub Workflow Status (with event) GitHub repo size GitHub Repo stars GitHub commit activity (branch) GitHub last commit (branch)

Static Badge

Description

This is a module that allows you the change the colour of the terminal using the batch colour syntax. It works on all known platforms.

Table of Content

  1. colourise_output
  2. Description
  3. Table of Content
  4. Installation
    1. Using pip
    2. Using python
  5. Usage
    1. Importing
    2. Initialising
    3. Calling the test_colours function
      1. Epilepsy warning
    4. Changing the colour
      1. Displaying text and the colour
      2. Only changing the colour
  6. Available colours
  7. Change the initialisation content
    1. Changing the forbidden characters
    2. Changing the description
    3. Changing both
  8. Author
  9. Version

Installation

Using pip

pip install -U colorama
pip install -U colourise-output

Using python

Under windows:

py -m pip install -U colorama
py -m pip install -U colourise-output

Under Linux/Mac OS:

python3 -m pip install -U colorama
python3 -m pip install -U colourise-output

Usage

Importing

import colourise_output as co

Initialising

The generic class is: ColouriseOutput() The generic loading function is: init_ressources(self) The output is: None

COI = co.ColouriseOutput()
COI.init_ressources()

Calling the test_colours function

The generic function is:

test_colours(self, delay:int=0)

The output is: None

COI.test_colours()

Calling this function will result in the function displaying all the available colours as well as their colour code (what you use to call them).

Epilepsy warning

Warning: Avoid this function if you are epileptic or set the delay to 1

COI.test_colours(1)

Changing the colour

The generic function to ask a question is:

display(self, colour:str, attributes:tuple=(), text:str="")

The outputs of this function is: None The terminal will display the next lines in the desired colour.

Displaying text and the colour

COI.display("0A", (), "Hello World !\n")

The text "Hello World" will be displayed in green (A) on a black background (0).

Only changing the colour

answer = AQI.ask_question("How old are you?", "uint")
ADD_S = ""
if answer > 1:
    ADD_S = "s"
print(f"You are {answer} year{ADD_S} old !")

Available colours

Here is the windows colour pallet and how to use it:

Windows colour pallet

  • 0: Black
  • 1: Blue
  • 2: Green
  • 3: Aqua
  • 4: Red
  • 5: Purple
  • 6: Yellow
  • 7: White
  • 8: Gray
  • 9: Light Blue
  • A: Light Green
  • B: Light Aqua
  • C: Light Red
  • D: Light Purple
  • E: Light Yellow
  • F: Bright White

Using the Windows colour pallet

Change the initialisation content

When initialising the class it is possible to change the forbidden characters and/or the descriptions of the available types.

changing the forbidden characters

import ask_question as aq
illegal_characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \\t\\n\\r\\x0b\\x0c"
illegal_characters = illegal_characters.replace("0123456789","")
AQI = aq.AskQuestion(dict(), illegal_characters)

This initialisation has changed the characters that will be allowed for the number conversion in the 'int' and 'float' options.

Changing the descriptions

import ask_question as aq
human_type = {
    "int":"whole number (-1, 0, 1, 2, 3, etc...)",
    "float":"floating number (-1.2, 0.1, 1.2, etc...)",
    "uint":"whole positive number (0, 1, 2, etc...)",
    "ufloat":"whole positive floating number (0.1, 1.2, etc ...)",
    "num":"numeric (numbers from 0 onwards)",
    "alnum":"alphanumeric (only numbers and the alphabet)",
    "isalpha":"alphabet (from a to z and A to Z)",
    "char":"alphabet (from a to z and A to Z)",
    "ascii":"ascii Table",
    "str":"string (any character you can type)",
    "version":"version (numbers seperated by '.' characters)",
    "ver":"version (numbers seperated by '.' characters)",
    "bool":"boolean (yes/True/1 or no/False/0 answer type)",
}
AQI = aq.AskQuestion(human_type)

This initialisation has changed the descriptions for the types. When the user will enter a wrong answer, the description displayed for the type you were expecting will be taken from the human_type dictionnary you have entered.

Changing both

import ask_question as aq
illegal_characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \\t\\n\\r\\x0b\\x0c"
illegal_characters = illegal_characters.replace("0123456789","")
human_type = {
    "int":"whole number (-1, 0, 1, 2, 3, etc...)",
    "float":"floating number (-1.2, 0.1, 1.2, etc...)",
    "uint":"whole positive number (0, 1, 2, etc...)",
    "ufloat":"whole positive floating number (0.1, 1.2, etc ...)",
    "num":"numeric (numbers from 0 onwards)",
    "alnum":"alphanumeric (only numbers and the alphabet)",
    "isalpha":"alphabet (from a to z and A to Z)",
    "char":"alphabet (from a to z and A to Z)",
    "ascii":"ascii Table",
    "str":"string (any character you can type)",
    "version":"version (numbers seperated by '.' characters)",
    "ver":"version (numbers seperated by '.' characters)",
    "bool":"boolean (yes/True/1 or no/False/0 answer type)",
}
AQI = aq.AskQuestion(human_type)

You have now impacted the int and float typing as well as the 'type' descriptions.

Author

This module was written by (c) Henry Letellier Attributions are appreciated.

Quick way (I assume you have already initialised the class):

print(f"AskQuestion is written by {AQI.author}")

Version

The current version is 1.0.0

An easy way to display the version is:

import ask_question as aq
print(f"Version : {aq.__Version__}")

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

colourise_output-1.1.6.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

colourise_output-1.1.6-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file colourise_output-1.1.6.tar.gz.

File metadata

  • Download URL: colourise_output-1.1.6.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for colourise_output-1.1.6.tar.gz
Algorithm Hash digest
SHA256 7a87bceaee4540b51f377317edb88e974d9baa46257111a029e702cc377c0739
MD5 8bfd844ed2dbc724e3b1a9e2a7c200db
BLAKE2b-256 23c534edff1f6347d6ccf7270f1a0442d9c6a8ed29c4a3a0de36d1ef8093f4ba

See more details on using hashes here.

File details

Details for the file colourise_output-1.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for colourise_output-1.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 3b768306f28a8dd0484a8d515bc2cf7b16bf8fafbac769bad9af3869d8f67b95
MD5 737cb0eeb60bbe69960779eb8041b0e3
BLAKE2b-256 24c5c4329d48992258b61bc0a31bf9514e368e36f43b4f560770672b6bef5ca0

See more details on using hashes here.

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