Skip to main content

A library for handling ANSI codes

Project description

AnsiLib

AnsiLib is a Python module for handling text style and color shortcuts from ANSI escape codes.

Author: Bora Boyacıoğlu

Installation

To install AnsiLib, use pip:

pip install ansilib

If you are running Python 3.7 or below, you also need to install typing_extensions, which comes as a dependency.

Usage

import AnsiLib as al

You can use the quick styles and colors to simply format your text.

print(al.s("This text is bold."))
print(al.r("This text is red."))
print(al.u(al.b("This text is underlined and blue.")))

Also you can reach all of the colors using al.c class.

print(al.c.t.r("This text is red."))
print(al.c.b.c("This text has cyan background."))
print(al.c.t.g_("This text is bright green."))

To define styles, use al.style() function.

sty1 = al.style('bold', 'r', 'kb1')
print(sty1("This text is bold, red and has a background color of bright black."))

Get the complete list of styles and colors with al.available().

print(al.available())

Create an RGB color using al.color() function.

my_color = al.color(56, 12, 74)
sty2 = al.style('x', 'italic', my_color)
print(sty2("This text is italic, crossed and has an RGB color of (56, 12, 74)."))

Finally, you can use the AnsiLib's prints() function to print a styled text.

al.prints("This text is bold, red and has a background color of bright black.", s=['bold', 'r', 'kb1'])

The prints() function also supports inline style syntax for quick styling:

al.prints("$[r]This text is red", "$[b,u]This text is blue and underlined")

It is also possible to use the short form for single-character styles:

al.prints("$rThis text is red")

Inline syntax takes priority per value, the optional s= parameter still applies an overall style.

Contributions

I welcome contributions and suggestions to the AnsiLib Python library! Contact me about the details.

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

ansilib-1.1.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

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

ansilib-1.1.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file ansilib-1.1.0.tar.gz.

File metadata

  • Download URL: ansilib-1.1.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.12

File hashes

Hashes for ansilib-1.1.0.tar.gz
Algorithm Hash digest
SHA256 b17dae3259005e72ba83e78edf6ce865cb8d0b15dd670d3fc1e99dda86c8a85a
MD5 4a9d70156281bc77e8cf8b90d2a52d4e
BLAKE2b-256 7ee2b42dd5fc10101eff9cf1e10108eefff7eb17958f41ee71b0dca343db2610

See more details on using hashes here.

File details

Details for the file ansilib-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: ansilib-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.12

File hashes

Hashes for ansilib-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a437091a75353972ac2d2e6ed548979e743a7333eb14bb77e149a76e9e79b19f
MD5 6f80ea42723c03f86ab5ae1734010cc1
BLAKE2b-256 0835ec96d776133dc31edc7043d6107fb98135c54c1c585a8ca50769d88c689f

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