Skip to main content

A lightweight, easy-to-use Python library for enhanced terminal output, combining string-friendly color styling with one-step ANSI image rendering.

Project description

🎨 cobra-color 🎨
Turn a Plain Terminal into an Expressive Visual Canvas

PyPI version Python codecov License

Tests Github stars

About

cobra-color is a lightweight, easy-to-use Python library for enhanced terminal output, combining string-friendly color styling with one-step ANSI image rendering.

  • Python: 3.9+

Features

  • 🚀 Strong compatibility with native Python strings: Keep familiar str workflows while preserving color/style through operations like concatenation and transformations.
  • 🚀 Full terminal rendering toolkit: Supports both styled text output and image-to-ANSI conversion across multiple modes (such as ascii, half-color, and gray).
  • 🚀 Lightweight and developer-friendly: Minimal core dependencies, optional render extras, and safe_print support for tqdm/rich-friendly console output.

Installation

Install from PyPI

This installs the core package with minimal dependencies.

pip install cobra-color

Install with Optional Dependencies

cobra.render module support.

pip install cobra-color[render]

Quick Start

  • Render a text in the terminal:

    from cobra_color import cstr, safe_print
    
    c_text_1 = cstr("Hello World!", fg="r", styles=["bold"])
    # Print directly from the terminal
    print(c_text_1)
    
    c_text_2 = cstr("Hello World!", fg=(255, 255, 255), styles=["udl", "bold"])
    # Alternatively, you can use safe_print() to automatically support progress bar modes like tqdm and rich.
    safe_print(c_text_2)
    
    # Merge `c_text_1` and `c_text_2` while preserving their colors and style formatting.
    c_text_3 = c_text_1 + c_text_2
    
    # You can continue to use str's proprietary functions and keep the existing colors and styles.
    c_text_1.upper()
    
  • Render an image in the terminal:

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

    from cobra_color.draw import fonttext_to_ansi, FontName, safe_print
    
    # Borderless grayscale font
    safe_print(fonttext_to_ansi(
        "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
  • (Optional) Pillow >= 9.0, < 11.0
  • (Optional) 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-1.3.11.tar.gz (30.8 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-1.3.11-py3-none-any.whl (32.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for cobra_color-1.3.11.tar.gz
Algorithm Hash digest
SHA256 bf20c67992036ecbc4b0294a181a453ad76c78273b9a18b8bef99a523f590f4a
MD5 5be7f6cf7980a32505fcc72a9a6a9d26
BLAKE2b-256 c5f5b174f3bf47e888c36597eb561bc9c8b6be6dd07d48829d14e37432490a57

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cobra_color-1.3.11-py3-none-any.whl
  • Upload date:
  • Size: 32.0 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-1.3.11-py3-none-any.whl
Algorithm Hash digest
SHA256 651015e1fe10e0cee057699f190cf14b3797452779eed20d6e30b76e4a9f5659
MD5 aead1a6726fdc09d74e96b46b8b4c57f
BLAKE2b-256 f58111621a6f120004e18e2e18769876273be0376bfff2566517a49f0aca0240

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