Skip to main content

A library for creating a terminal user interface

Project description

Colorlib

A library designed for making working with terminal user interfaces easier

Features

Colorlib can

  • Handle colors for you
  • Generate boxes
  • Manipulate text alignment
  • And more

Key features

Colors

Colorlibis designed to make coloring elements a bit easier. You can color logos, ansi art or whatever you'd like and print that out to a terminal. Here's a demo

import src

logo = """
  ██████  ▄▄▄       ███▄ ▄███▓ ██▓███   ██▓    ▓█████    ▄▄▄█████▓▓█████ ▒██   ██▒▄▄▄█████▓
▒██    ▒ ▒████▄    ▓██▒▀█▀ ██▒▓██░  ██▒▓██▒    ▓█   ▀    ▓  ██▒ ▓▒▓█   ▀ ▒▒ █ █ ▒░▓  ██▒ ▓▒
░ ▓██▄   ▒██  ▀█▄  ▓██    ▓██░▓██░ ██▓▒▒██░    ▒███      ▒ ▓██░ ▒░▒███   ░░  █   ░▒ ▓██░ ▒░
  ▒   ██▒░██▄▄▄▄██ ▒██    ▒██ ▒██▄█▓▒ ▒▒██░    ▒▓█  ▄    ░ ▓██▓ ░ ▒▓█  ▄  ░ █ █ ▒ ░ ▓██▓ ░ 
▒██████▒▒ ▓█   ▓██▒▒██▒   ░██▒▒██▒ ░  ░░██████▒░▒████▒     ▒██▒ ░ ░▒████▒▒██▒ ▒██▒  ▒██▒ ░ 
▒ ▒▓▒ ▒ ░ ▒▒   ▓▒█░░ ▒░   ░  ░▒▓▒░ ░  ░░ ▒░▓  ░░░ ▒░ ░     ▒ ░░   ░░ ▒░ ░▒▒ ░ ░▓ ░  ▒ ░░   
░ ░▒  ░ ░  ▒   ▒▒ ░░  ░      ░░▒ ░     ░ ░ ▒  ░ ░ ░  ░       ░     ░ ░  ░░░   ░▒ ░    ░    
░  ░  ░    ░   ▒   ░      ░   ░░         ░ ░      ░        ░         ░    ░    ░    ░      
      ░        ░  ░       ░                ░  ░   ░  ░               ░  ░ ░    ░           
"""

print(src.coloring.colorize_with_gradient(logo, (2, 45, 189), (189, 2, 99), 45).to_ansi_escape_sequences())

img.png

You can also make radial gradients, like this

import src

logo = """
  ██████  ▄▄▄       ███▄ ▄███▓ ██▓███   ██▓    ▓█████    ▄▄▄█████▓▓█████ ▒██   ██▒▄▄▄█████▓
▒██    ▒ ▒████▄    ▓██▒▀█▀ ██▒▓██░  ██▒▓██▒    ▓█   ▀    ▓  ██▒ ▓▒▓█   ▀ ▒▒ █ █ ▒░▓  ██▒ ▓▒
░ ▓██▄   ▒██  ▀█▄  ▓██    ▓██░▓██░ ██▓▒▒██░    ▒███      ▒ ▓██░ ▒░▒███   ░░  █   ░▒ ▓██░ ▒░
  ▒   ██▒░██▄▄▄▄██ ▒██    ▒██ ▒██▄█▓▒ ▒▒██░    ▒▓█  ▄    ░ ▓██▓ ░ ▒▓█  ▄  ░ █ █ ▒ ░ ▓██▓ ░ 
▒██████▒▒ ▓█   ▓██▒▒██▒   ░██▒▒██▒ ░  ░░██████▒░▒████▒     ▒██▒ ░ ░▒████▒▒██▒ ▒██▒  ▒██▒ ░ 
▒ ▒▓▒ ▒ ░ ▒▒   ▓▒█░░ ▒░   ░  ░▒▓▒░ ░  ░░ ▒░▓  ░░░ ▒░ ░     ▒ ░░   ░░ ▒░ ░▒▒ ░ ░▓ ░  ▒ ░░   
░ ░▒  ░ ░  ▒   ▒▒ ░░  ░      ░░▒ ░     ░ ░ ▒  ░ ░ ░  ░       ░     ░ ░  ░░░   ░▒ ░    ░    
░  ░  ░    ░   ▒   ░      ░   ░░         ░ ░      ░        ░         ░    ░    ░    ░      
      ░        ░  ░       ░                ░  ░   ░  ░               ░  ░ ░    ░           
"""

print(src.coloring.colorize_with_circle_gradient(logo, (2, 45, 189), (189, 2, 99), 60, 0.4,
                                                 0.2).to_ansi_escape_sequences())

img.png

Box generation

Colorlib can generate boxes for you, for text you input. An example:

from src import colorlib

logo = """This text is multiline
I can type whatever I want and the box will fit it
This is a nice library"""

print(src.colorlib.boxes.generate_text_box(logo, src.colorlib.boxes.BoxTypes.rounded.value))

img.png

You can also change the box layout, see BoxType in boxes.py

Manipulate text alignment

Colorlib can also help you align text, here's an example

import src

logo = """This text is centered
It is centered because I want it to be
Very nice, will fit whatever"""

print(src.text_manipulation.center_text_in_itself(logo))

img.png

You can also right align text:

import src

logo = """This text is right aligned
Just because, no particular reason
Nice weather outside today, isn't it?"""

print(src.text_manipulation.right_align_text(logo))

img.png

There are many more features, the api is pretty self explanatory.

Support

You can show your support by leaving a star on this repo, which would help me out a lot! Also, if you find any bugs, don't hesitate to open up an issue for it.

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

tui-colorlib-1.0.4.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

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

tui_colorlib-1.0.4-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file tui-colorlib-1.0.4.tar.gz.

File metadata

  • Download URL: tui-colorlib-1.0.4.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for tui-colorlib-1.0.4.tar.gz
Algorithm Hash digest
SHA256 a63610386458c0544c587262daaf701a8dd04b11438bb33452e89a759d9b45e8
MD5 73ec34f1843f05fc92058a5350c98102
BLAKE2b-256 67fc85f2def1f2bdc290b4b486734f2e566eea8540528b0c875668b64d09e881

See more details on using hashes here.

File details

Details for the file tui_colorlib-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: tui_colorlib-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for tui_colorlib-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1df2f9094f135b74f26c3bf8c88f6600cb8678f24b76013f0d32a786badf6672
MD5 5163b49ba2e736528fa4e0a19e31b7e0
BLAKE2b-256 07df5ae53757e7364c5b322c983110e4cc768b3604599650ae8ad425264e51a4

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