Skip to main content

A package for formatted console output using ANSI escape codes - colors AND formatting.

Project description

DESCRIPTION

This script allows you to set the foreground, and background colors of your Console output as well as setting a few styles. The script uses ANSI Escape Codes for colors black, red, green, yellow, blue, magenta, cyan, & white. It also uses the ANSI Escape Codes for styles bold and underline.

OS COMPATIBILITY

This library seamlessly takes into account Windows machines that are not configured to support ANSI escape codes. When your script runs, the library attempts to enable this feature for this session. If it fails to do so, then it switches to printing with default behavior.

HOW TO REFERENCE

  1. install the library
    pip install formatted_console_output
  1. At the top of your main script add the following import statement:
    from formatted_console_output import ForegroundColor, BackgroundColor, TextFormat, output_formatted_message as print

CODE COMPATIBILITY/OVERLOADING

You do not have to alias the method import as "print" but that makes it more natural for you to code against and allows you to leverage everything else about the print() method. The script passes on all extra keyword arguments that are normally used in a print() call. Anyone referencing this library that tries to use the print() method as normal would still get default white on black with no format and normal behavior otherwise.

HOW TO USE IN CODE

The enumerators that define these colors/formats are:

  • ForegroundColor [BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE]
  • BackgroundColor [BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE]
  • TextFormat [BOLD, UNDERLINE, NONE]

The added keyword arguments are:

  • fg_color (default is ForegroundColor.WHITE)
  • bg_color (default is BackgroundColor.BLACK)
  • format (default is TextFormat.NONE)

In the following example we're printing a message to console with blue text on a yellow background in bold style. I also threw in some standard keyword arguments to show that:

print(
    f"Archiving files and reporting against them in '{dir_path}'",
    fg_color=ForegroundColor.BLUE,
    bg_color=BackgroundColor.YELLOW,
    format=TextFormat.BOLD,
    sep="  -  ",
    end="\n\n"
)

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

formatted_console_output-0.1.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

formatted_console_output-0.1.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file formatted_console_output-0.1.0.tar.gz.

File metadata

File hashes

Hashes for formatted_console_output-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ac00032be23a6249c5451b9a4d9d1ec546f0c05ecdc95e397d72e4c9fcfce0d9
MD5 c7987ebe3b9ddf0b803120527d060c9e
BLAKE2b-256 00c11f5d08c8213ad4be7b949f527e75e6859126cf478c8bf53e652066d01586

See more details on using hashes here.

File details

Details for the file formatted_console_output-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for formatted_console_output-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 16f110498be97df2ab0cfb5c003707271a652537b5d04a47e8db04b632da979f
MD5 fa199708e687ef46db21819377366ffd
BLAKE2b-256 bd341edbe8f0a1d4fd96b97ba3d39244db09c466211646c7508fb70566f415aa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page