Skip to main content

Simplistic python package to print colored and/or styled text with a user friendly API.

Project description

License: MIT PyPi versions

Raia

Simplistic python package to print colored and/or styled text with a user friendly API.

1. Introduction

raia is a simplistic python package that intends to provide a user friendly API for printing formatted text on the terminal. To do so, raia uses ANSI RGB codes (as many similar packages do). Truecolor ANSI support of the running terminal is assumed.

2. Installation

Using pip,

pip install raia

3. Usage

raia formats text through Formatter objects. All Formatter objects have two ways to format text:

  1. Used as a callable, i.e.
     form = raia.Formatter("""some initialization""")
     formatted_str = form ("raia Library")
     print(formatted_str)
    
  2. Using the fprint method that uses the builting print with the chosen formatting, i.e.
    form = raia.Formatter("""some initialization""")
    form.fprint("raia Library")
    

Both of these have the same output (printed "raia Library" with the formatting specified in """some initialization""").

The Formatter object is initialized by a string of the ANSI escape code for the chosen formating, e.g. for printing red text we would initialize with:

Red = raia.Formatter("\x1b[38;2;255;0;0m")

To bereft the user of having anything to do with such codes, raia provides the Style, Color, FullStyle subclasses of the Formatter class. With them, the user just has to specify the necessary information (e.g. for Color the amounts of RGB, see example below).

4. example.py

Below, you can see the code and output of the script example.py.

import raia

# Info
print("Package name: "+raia.__name__)
print("Version: " + raia.__version__)

# Default colors
print(raia.Red("Default 'Red' as foreground."))
print(raia.Blue_bg("Default 'Blue' as background."))

# Custom color
myColor = raia.Color(0, 150, 150)
print(myColor("Custom foreground color."))

# Custom background
myBackground = raia.Color(255, 0, 150, as_background=True)
myBackground.fprint('This is a custom background color.')

# Default style
print(raia.Strikethrough('This is a default style.'))

# Custom style
myStyle = raia.Style('underline', 'italic', 'bold')
myStyle.fprint('This is a custom style.')

# Custom Full-Style
myFullStyle = raia.FullStyle(foreground=raia.Violet, background=(
    0, 80, 180),                           style=myStyle)
myFullStyle.fprint('This is a custom fully styled text.')

# Default keys
print(raia.Green('Default color keys: \n'), raia.defaults.keys())
print(raia.Brown_bg('Available styles keys:\n'), raia.styles.keys())

Output:

image

Important Note: Not all styles work on all consoles.

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

raia-0.2.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

raia-0.2.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file raia-0.2.0.tar.gz.

File metadata

  • Download URL: raia-0.2.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for raia-0.2.0.tar.gz
Algorithm Hash digest
SHA256 262d25c8f04de7cc7159ca45627b90da61055e4e1f95d01e2f6d10fa12e5b5e1
MD5 06284bd72c1e4a2b8669d69efbfa011a
BLAKE2b-256 051ce64508f3c7ac1fbd4a1171962cd0ad5a8c7bf501baac3339db816f3476cf

See more details on using hashes here.

File details

Details for the file raia-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: raia-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for raia-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5666a563e76d136cbcd65ca4f917a03b4f366c2627b144703e474bc2d3cb89af
MD5 57689ee7e0836fe33376d6fbe7b2294c
BLAKE2b-256 ad582a3bab592864b981bd1a3dec306cb38cc92c44b895f0cdfa7afc393d2938

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page