Skip to main content

ANSIEnum: Python + ANSI = easy!

Project description

ANSIEnum: Python + ANSI = easy!

Q) Want a simple way to put ANSI escape codes in your project?

A) Yes? So did I! Here is my solution...

Description

Allows inline adding of ANSI escape codes for color and cursor manipulation.

Features

  • SGR properties for setting text FG/BG color (incl BRight) plus effects (these can also be added together):
    • FG_*
    • FG_BR_*
    • BG_*
    • BG_BR_*
    • UL_, ITAL_, STRIKE_, INVERT_and BLINK_ control
  • CSI properties for clearing screen:
    • ERASE_DISP_*
    • ERASE_LINE_*
  • CSI functions for cursor control (complete list [below](#Cursor functions)):
    • cursor_*

Note: Complete property (upper case) names are available from the enum with dir(ANSI)

Installation

$ pip install ANSIEnum

Usage

from ansienum import ANSI

# Simple text color with f-strings:
print(f"{ANSI.FG_RED}Red text!{ANSI.RESET}")

# Codes of the same type can be added:
my_color = ANSI.FG_RED + ANSI.BG_BLUE
print(f"{my_color}Red on blue text!{ANSI.RESET}")

# Move cursor:
print(f"{ANSI.cursor_up(2)}Moved text")

Cursor functions

ANSI.cursor_at(n, m)
ANSI.cursor_up(n)
ANSI.cursor_down(n)
ANSI.cursor_right(n)
ANSI.cursor_left(n)
ANSI.cursor_next_line(n)
ANSI.cursor_prev_line(n)
ANSI.cursor_horiz_abs(n)

Contributing

If you are reading this and want to contribute, please feel free to create an issue. Note that it is a work in progress and things probably will change, but I intend to keep backward compatibility where possible.

License

This project is under an MIT license

(c) 2021 Paul Taylor   @paulyt

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

ANSIEnum-0.2.3.tar.gz (71.0 kB view details)

Uploaded Source

Built Distribution

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

ANSIEnum-0.2.3-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file ANSIEnum-0.2.3.tar.gz.

File metadata

  • Download URL: ANSIEnum-0.2.3.tar.gz
  • Upload date:
  • Size: 71.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.2

File hashes

Hashes for ANSIEnum-0.2.3.tar.gz
Algorithm Hash digest
SHA256 9f6f4fa861fbc2324d09e491df3788712031ee248af22be6a7df6465edb42f6d
MD5 8d82df78e2e4e4c735a133996f38384d
BLAKE2b-256 9404b89168b6a0f1e139b06f9bd6f81e49fb9965e03e9c741f06b19d334efa60

See more details on using hashes here.

File details

Details for the file ANSIEnum-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: ANSIEnum-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.2

File hashes

Hashes for ANSIEnum-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6830d143bf956e754f33cdb9aaf3c72396ab51152748cd5309c92b877b69fe4f
MD5 f6d0bd5c864007597d187e987dea320b
BLAKE2b-256 58c454c0914225d5d07e6468fb9f818a0c921a16bc15c9a46fa846e50b54e6ff

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