ANSICON Python Wrapper

1.89.0 · active · verified Fri Apr 17

The `ansicon` Python library provides a wrapper to load Jason Hood's ANSICON utility, enabling ANSI escape sequences for colored text in the Windows command prompt. It is currently at version 1.89.0, with releases typically mirroring new versions of the underlying ANSICON C utility.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to load ANSICON and print colored text using ANSI escape sequences. It includes a check for successful loading, which is crucial for this library.

import ansicon
import os

# ansicon.load() attempts to find and load ANSICON.exe.
# It returns True on success and False on failure.
# For a real application, always check the return value.
if ansicon.load():
    print("ANSICON loaded successfully. Colors should work in your Windows terminal.")
    # Example ANSI escape sequences
    print('\033[91mThis is red text\033[0m')
    print('\033[92mThis is green text\033[0m')
    print('\033[94mThis is blue text\033[0m')
    print('\033[1mThis is bold text\033[0m')
else:
    print("Failed to load ANSICON. Colors might not work.")
    if os.name == 'nt':
        print("On Windows, ensure ANSICON.exe is in your PATH or script's directory.")
    else:
        print("Not on Windows; ANSICON is not applicable. Modern terminals usually support ANSI natively.")

view raw JSON →