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, 3.10 and PyPy 3.7.10
- No requirements other than the standard library.
pip install clrfterm
Usage
Colored Output
from clrfterm import (
Style,
Foreground,
Background,
rprint,
reset,
)
print(Foreground.RED + "Red foreground text")
print(Background.WHITE + "White backgrounds text")
print(Style.UNDERLINE + "Underlined text")
reset()
print("Back to normal text")
rprint("Auto reset", foreground=Foreground.GREEN)
print("Normal text")
Available formatting constants are:
Foreground: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET
Background: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET
Style: BOLD, UNDERLINE, RESET_ALL
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 Message, Phrase, PhraseStyle classes that implements the Fluent interface
from clrfterm import Foreground, Background, Style
from clrfterm.messages import Message, Phrase, PhraseStyle
style = (
PhraseStyle()
.set_foreground(Foreground.RED)
.set_background(Background.CYAN)
.set_style(Style.BOLD)
)
print(Message()
.add(Phrase()
.set_text('hello')
.set_style(style))
.add(Phrase()
.set_text('world')
.set_style(style))
)
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 clrfterm import (
enable_ansi,
Foreground,
reset
)
enable_ansi()
print(Foreground.RED + "Hello")
reset()
ProgressBar
A progress bar is a graphical control element used to visualize the progression of an extended computer operation, such as a download, file transfer, or installation.
from time import sleep
from clrfterm.progress import Bar
bar = Bar(50)
for i in range(50):
bar.next()
sleep(0.01)
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
File details
Details for the file clrfterm-1.1.0.tar.gz
.
File metadata
- Download URL: clrfterm-1.1.0.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.8.1 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eea261d2dbf25d55cb888cd1403d9e131733cd93165e5218a60d62ffb1bbd9ea |
|
MD5 | a8ce3282ac35055e5cf352acb92aede5 |
|
BLAKE2b-256 | 6eacb3e68449e197b544ffe48db6318c75d80a988ed26b71608b45c996bfbb98 |