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.1.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.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for formatted_console_output-0.1.1.tar.gz
Algorithm Hash digest
SHA256 af45e205c2a61f08b9ed30641b0ac9dd504b085cad781019d7a2ea085d5eef61
MD5 28022cf75b96868ca18540b2cbac7f9a
BLAKE2b-256 ae76bf12fbe8a3e4b29bc9caf7308ec81681d3f5d9e44ab6262e1cfc060c15ce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for formatted_console_output-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1155ba84519c627592bd24541453c45701d525ea8cf3b21b2607faf11ec1210b
MD5 bf890a0d948a82f2086e8c2c5bbfbf15
BLAKE2b-256 7e7c231df55d3d114bfeddfaa1ef735b1e0f83b3f92aef5248f74345b7a79c41

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