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
    
    c_text_1 = ctext("Hello World!", fg="r", styles=["bold"])
    # Print directly from the terminal
    print(c_text_1)
    
    c_text_2 = ctext("Hello World!", fg=(255, 255, 255), styles=["udl", "bold"])
    # Alternatively, you can use smart_print() to automatically support progress bar modes like tqdm and rich.
    smart_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, smart_print
    
    # ASCII art
    smart_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, smart_print
    
    # Borderless grayscale font
    smart_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
  • 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-1.0.0.tar.gz (25.3 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.0.0-py3-none-any.whl (26.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cobra_color-1.0.0.tar.gz
  • Upload date:
  • Size: 25.3 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.0.0.tar.gz
Algorithm Hash digest
SHA256 d23e001504f0f54c3fb9aafafa1bdc97f300928c570bb2b2757897e73fa954dc
MD5 717f964db60858441f17f45f1ac83fc6
BLAKE2b-256 4d41ee932ddcc97e2b5bb8f71be123ae81b73bfddf5b3fa6736689061941f904

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cobra_color-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 26.8 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.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 40081dfbc6eb9e92631a57436c98dc3f1af31055251c5c72c053283f853daec9
MD5 5f1120508f438b6400dfc6cf3c2a833e
BLAKE2b-256 a26137e30617bd9a636791e3274ccfbfb8893f389df5986b13d5be90d5ab08a5

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