Skip to main content

Terminal Formatting for Humans

Project description

TextFormat

TextFormat is a lightweight Python module for ANSI text formatting, customizable word art, and table rendering in CLI applications.

Features

  • ANSI Colors & Styles – Easily format text using intuitive color mappings.
  • Customizable Word Art – Generate banners with adjustable characters and widths.
  • Table Formatting – Display structured data in a clean, readable format.

Installation

Install via PyPI:

pip install textfmt

Usage

Basic Text Formatting

from textformat import TextFormat

print(TextFormat.style("Hello, World!", TextFormat.BOLD, TextFormat.COLORS["blue"]))

Custom Word Art Banner

from textformat.word_art import WordArt

print(WordArt.banner("TEXTFORMAT", char="*", width=40))

Table Rendering

from textformat.table import TableFormatter

headers = ["Feature", "Color", "Effect"]
data = [
    ["Bold", "White", "Strong emphasis"],
    ["Underline", "Blue", "Text decoration"],
    ["Warning", "Yellow", "Cautionary message"],
]

print(TableFormatter.generate(headers, data))

File Download Progress Bars

from textformat.progress import Color, DownloadProgressBar
from pathlib import Path
def download_with_progress(url: str, output_path: Path, download_color, complete_color):
    response = requests.get(url, stream=True)
    total = int(response.headers.get('content-length', 0))

    if response.status_code != 200:
        raise Exception(f"Failed to download from {url}. HTTP status: {response.status_code}")

    progress = DownloadProgressBar(total, prefix=output_path.name, 
                           download_color=download_color, complete_color=complete_color)
    with open(output_path, "wb") as f:
        for chunk in response.iter_content(chunk_size=8192):
            if chunk:
                f.write(chunk)
                progress.update(progress.downloaded + len(chunk))
    print()
    download_with_progress('https://huggingface.co/sharktide/recyclebot0/resolve/main/tf_model.h5', Path("tf_model.h5"), Colors.CYAN, Colors.GREEN)

License

MIT License – Free to use and modify.

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

textfmt-0.2.1.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

textfmt-0.2.1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file textfmt-0.2.1.tar.gz.

File metadata

  • Download URL: textfmt-0.2.1.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.5

File hashes

Hashes for textfmt-0.2.1.tar.gz
Algorithm Hash digest
SHA256 69cb9b32257e8dad487cb971dca825f90ead954382575808b429a05ae68b5247
MD5 87552eacb15612597b2197c43b58ba70
BLAKE2b-256 bf9b1e7bec956944e569c79b7f55d72689b7f57b1541513beaf74c6c82e79b9b

See more details on using hashes here.

File details

Details for the file textfmt-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: textfmt-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.5

File hashes

Hashes for textfmt-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e2d68a089a8d9b9d34423a93702efe38ff2c3113673e652d270fefaf5140b34a
MD5 d7f123b8788040d1aae9dee48abf4d10
BLAKE2b-256 5ad199584a76ae8a0f169612be0f491d3b0a6366be4227aa9123c4001ef826a8

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