Skip to main content

Module that decorates your console

Project description

clrfterm

Module that decorates your console



Description

clrfterm makes it easy to work with ANSI escape sequences that decorate your console. ANSI escape sequences are a standard for in-band signaling to control cursor location, color, font styling, and other options on video text terminals and terminal emulators. Certain sequences of bytes, most starting with an ASCII escape character and a bracket character, are embedded into text. The terminal interprets these sequences as commands, rather than text to display verbatim.

Installation

  • Tested on CPython 3.7, 3.8, 3.9 and PyPy 3.7.10
  • No requirements other than the standard library.
pip install clrfterm

Usage

Colored Output
from clrflterm import (
    Styles,
    Foreground,
    Backgrounds,
    rprint,
    reset,
)


print(Foreground.RED + "Red foreground text")
print(Backgrounds.WHITE + "White backgrounds text")
print(Styles.UNDERLINE + "Underlined text")
reset()
print("Back to normal text")

rprint("Auto reset", foreground=Foreground.GREEN)
print("Normal text")
Available formatting constants are:
Foregrounds: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE.
Backgrounds: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE.
Styles: BOLD, UNDERLINE, RESET

reset the function resets the foreground, background. It must be called upon exiting the program.

Fluent interface

In software engineering, a fluent interface is an object-oriented API whose design relies extensively on method chaining.

clrfterm has a MessageBuilder class that implements the Fluent interface

from clrfterm import (
    MessageBuilder,
    Foreground
)

message = (
    MessageBuilder()
        .set_foreground(Foreground.RED)
        .set_reset(True)
)
print(message.set_text("Hello"))

Windows

The Windows Console did not support ANSI escape sequences, nor did Microsoft provide any method to enable them. But In 2016, Microsoft released the Windows 10 version 1511 update which unexpectedly implemented support for ANSI escape sequences, over two decades after the debut of Windows NT.

clrfterm can enable ANSI escape sequences in CMD.

from clrflterm import (
    enable_ansi,
    Foreground,
    reset,
)


enable_ansi()
print(Foreground.RED + "Hello")
reset()

License

This module is licensed under the terms of the MIT license. Name by @xterdd

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

clrfterm-1.0.1.tar.gz (4.4 kB view hashes)

Uploaded Source

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