Skip to main content

A Python library for enhanced terminal display.

Project description

🐱‍👤 cobra-color 🐱‍👤

PyPI version Python Tests codecov License

Pull Requests Welcome Github stars

About

A lightweight Python library for enhanced terminal display: simple text color/style conventions and image-to-terminal rendering.

  • Python: 3.9+
  • Runtime deps: Pillow (>=9,<11), NumPy (>=1.21,<2)

Features

  • 🚀 Concise color/style names for terminal text.
  • 🚀 Image rendering in multiple modes: ASCII, color, half-color, gray, half-gray.
  • 🚀 Minimal dependencies and easy integration.

Installation

Stable (once published):

pip install cobra-color

Quick Start

  • Render a text in the terminal:

    from cobra_color import ctext, smart_print
    
    # Print directly from the terminal
    print(ctext("Hello World!", fg="r", styles=["bold"]))
    
    # Alternatively, you can use smart_print() to automatically support progress bar modes like tqdm and rich.
    smart_print(ctext("Hello World!", fg="r", styles=["bold"]))
    
  • Render an image in the terminal:

    from cobra_color.draw import fmt_image, smart_print
    
    # ASCII art
    smart_print(fmt_image("example.jpg", width=80, mode="ascii"))
    
    # Half-block color (recommended for truecolor terminals)
    smart_print(fmt_image("example.jpg", width=80, mode="half-color"))
    
  • Render some text with fonts in the terminal:

    from cobra_color.draw import fmt_font, FontName, smart_print
    
    # Borderless grayscale font
    smart_print(fmt_font("Hello World!", font=FontName.LLDISCO,, mode="half-gray", trim_border=True))
    

Image Modes

  • ascii: monochrome ASCII using a density charset.
  • color: colorized character fill.
  • half-color: half-block characters with color (higher density, good visual quality).
  • gray: grayscale characters.
  • half-gray: half-block grayscale.

Tip: For best results, use a TrueColor-capable terminal and a monospaced font.

Requirements

  • Python >= 3.9
  • Pillow >= 9.0, < 11
  • NumPy >= 1.21, < 2.0

License

See LICENSE in the repository.

Links

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

cobra_color-0.2.8.tar.gz (63.6 kB view details)

Uploaded Source

Built Distribution

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

cobra_color-0.2.8-py3-none-any.whl (63.9 kB view details)

Uploaded Python 3

File details

Details for the file cobra_color-0.2.8.tar.gz.

File metadata

  • Download URL: cobra_color-0.2.8.tar.gz
  • Upload date:
  • Size: 63.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for cobra_color-0.2.8.tar.gz
Algorithm Hash digest
SHA256 46fcbb1d52b14886557910e2f000723793c06f57a44f0af05e7f56cea0571adf
MD5 569636f56b878141f11bef243691118b
BLAKE2b-256 6d191d5e9955eb326a9d4e2e0801c24bec19321750da74e4d8fdd21fe6cdc751

See more details on using hashes here.

File details

Details for the file cobra_color-0.2.8-py3-none-any.whl.

File metadata

  • Download URL: cobra_color-0.2.8-py3-none-any.whl
  • Upload date:
  • Size: 63.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for cobra_color-0.2.8-py3-none-any.whl
Algorithm Hash digest
SHA256 2139b857aed303c358842d74696df0edfc44540ec45fc68cad48f766905fc45a
MD5 0b8cebcc15b25489b12acece4bd1d813
BLAKE2b-256 cfbee453c2be6fd3ed2a76706b3e846928bbcfeb73014d95c41889c7ad551651

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