Skip to main content

ANSI escape code library for Python

Project description

Pansi is a clean and simple ANSI escape code library for Python.

https://github.com/technige/pansi/raw/master/art/hello-world.png

General usage

Pansi provides an object called ansi through which all escape codes can be selected. This object exposes the codes as both attributes (e.g. ansi.red) and items (e.g. ansi["red"]).

This object can therefore be used in several different ways, but the simplest is through the string format method. Here, if the object is supplied as a simple named argument, all references need to be prefixed:

https://github.com/technige/pansi/raw/master/art/usage-long.png

Alternatively, passing the object with the ** operator removes the need for prefixes and thus makes the template string shorter. However, this does introduce a greater chance of clashing with other parameters, and doesn’t signal which parameters are which.

https://github.com/technige/pansi/raw/master/art/usage-short.png

Ultimately, it is a subjective choice between these two options.

Colours

For foreground text, the standard set of colours can be selected using the lower case name for normal brightness and the upper case name for high intensity. To select as the background colour instead, simply prefix with bg., e.g. bg.blue.

Colour

Foreground

Background

K0 Black

black

bg.black

R0 Red

red

bg.red

G0 Green

green

bg.green

Y0 Yellow

yellow

bg.yellow

B0 Blue

blue

bg.yellow

M0 Magenta

magenta

bg.magenta

C0 Cyan

cyan

bg.cyan

W0 White

white

bg.white

K1 Bright black

BLACK

bg.BLACK

R1 Bright red

RED

bg.RED

G1 Bright green

GREEN

bg.GREEN

Y1 Bright yellow

YELLOW

bg.YELLOW

B1 Bright blue

BLUE

bg.YELLOW

M1 Bright magenta

MAGENTA

bg.MAGENTA

C1 Bright cyan

CYAN

bg.CYAN

W1 Bright white

WHITE

bg.WHITE

Full 24-bit colour support is also available (on those terminals that support it) by using the rgb selector.

https://github.com/technige/pansi/raw/master/art/rgb-orange.png

Foreground and background colours can be inverted and then set back to normal using the rev and _rev tags respectively.

To reset foreground and background back to their defaults, use fg.reset and bg.reset.

Text Weight

  • weight.normal

  • weight.bold

  • weight.light

  • b (alias for weight.bold)

  • _b (alias for weight.normal)

Text Style

  • style.normal

  • style.italic

  • style.fraktur

  • i (alias for style.italic)

  • _i (alias for style.normal)

Text decoration

  • u (underline)

  • uu (double underline)

  • _u (no underline)

  • o (overline)

  • _o (no overline)

  • s (strike through)

  • _s (no strike through)

Blinking

  • blink (blink)

  • BLINK (blink fast)

  • _blink (no blink)

Hide & show

  • hide

  • show

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pansi-0.0.dev1.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

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

pansi-0.0.dev1-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file pansi-0.0.dev1.tar.gz.

File metadata

  • Download URL: pansi-0.0.dev1.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for pansi-0.0.dev1.tar.gz
Algorithm Hash digest
SHA256 01f83b1208369bbe16f40ee9f4c0dc6bb1dbd7361f7df5d86935a5dbdddadd4b
MD5 18e5a958d36e43cb311067492a65ed26
BLAKE2b-256 4910515c46e6674c6ca127524611bc0dfbbfd92162a7b680e6138f70ada24a4e

See more details on using hashes here.

File details

Details for the file pansi-0.0.dev1-py3-none-any.whl.

File metadata

  • Download URL: pansi-0.0.dev1-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for pansi-0.0.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 f8af7ef1fbe627844b6b9155b9d2eafa0c21c49e8dd60bb965ba963dc5cc268c
MD5 6205dce43de73ab413a45374f480bd2b
BLAKE2b-256 96728504265c8cfc2c485d2d77b37939d304c8de04c760d1788beb8110607fb7

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