Skip to main content

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

Project 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.2.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.2-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for formatted_console_output-0.1.2.tar.gz
Algorithm Hash digest
SHA256 1004ec86a6e1bf439a69159cd25b78945c836746e5b0c5f84b389d11d8746732
MD5 f5ae4b43c2b31cc3d25924e6016a948f
BLAKE2b-256 8e4213f78180200eb4f90adf1de8c22bb1a812873143976901a6494f1d94013c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for formatted_console_output-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8340ae150faf8db053b8ae5ce28a41faacdd923d0219ff7a32e689f877679d0f
MD5 95f7c8ee1fd881ba10280c65ba2b0e72
BLAKE2b-256 6ae66ee28977f781685ad6d4a9e67db9965511cec7314c859a1014282f52ad34

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