Skip to main content

A Python package designed to enhance code readability and CLI experience.

Project description

ansiplus

Pepy Total Downlods PyPI - Python Version GitHub repo size PyPI - License PyPI - Version

A Python package designed to enhance code readability and CLI experience.

ansiplus-v2_1-preview

Usage

[!WARNING] Not all terminals work perfectly with ANSI codes. Ideally you should use xterm-256color.

[!NOTE] Terminal themes can change colors, e.g. magenta might show up as yellow, but it is still using the magenta ANSI code.

Prerequisites

  • Python version >=3.10
  • A terminal emulator that accepts ANSI codes
  • A terminal emulator that uses xterm-256color

[!NOTE] ANSi codes are not limited to xterm-256color, but they may still be limited to all features this package provides.

Tested Terminals on Linux

Terminal ($TERM)

  • Konsole (xterm-256color) - no missing features
  • Xterm (xterm) - no missing features
  • Alacritty (alacritty) - blinking text does not work
  • Kitty (xterm-kitty) - blinking text does not work

Colors

This package introduces the ability to print colors via name, id, and rgb with a single function:

>>> from ansiplus import print_color
>>> print_color("my colored text", color=(100, 200, 255), bgcolor=198)
'my colored text'
>>> print_color("red text", color="red")

Colors may also be manually printed:

>>> from ansiplus.ansi.colors import Fore
>>> print(f"{Fore.GREEN}green text{Fore.RESET}")

Rainbow & Random Colors

Text can be colored to resemble a rainbow:

>>> from ansiplus import print_color
>>> print_color("this text is rainbow colored", "rainbow")
'this text is rainbow colored'
>>> print_color("each character will be a random color", "random")
'each character will be a random color'

[!WARNING] Using rainbow or random color option uses a lot of ANSI codes.

User Input

Along with colors, users can be prompted for input which can be colored:

>>> from ansiplus import input_color
>>> txt = input_color("example: ", color="blue")
>>> print(txt)
'my input'

Prompting input can also store history if you assign it to a variable:

>>> from ansiplus import NewPrompt
>>> ui = NewPrompt()
>>> ui.set_color("red")
>>> ui.set_prompt_color("green")
>>> ui.prompt("prompt class example: ")
>>> ui.history
['my text']
>>> ui.latest
'my text'
>>> ui.prompt("prompt class example 2: ", "yellow")
>>> ui.latest
'this text is yellow, but default is red'

Rainbow & Random Colors

Prompt foreground text can also be colored rainbow:

>>> from ansiplus import input_color
>>> input_color("this text is rainbow: ", prompt_color="rainbow")

Clearing Prompt Lines

After receiving user input, the line can be cleared:

from ansiplus import input_color
while True:
    input_color("forever input: ", clearline=True)

The above code sample will ask for input forever, after every input, the line will clear and the input will be prompted again on the same line.

Text Styles

This package includes several several styles that can be used:

>>> from ansiplus import print_style
>>> print_style("underline text", "underline")
'underline text'

Like colors, styles may also be used manually:

>>> from ansiplus.ansi.styles import BOLD, BOLD_RESET
>>> print(f"{BOLD}bold text{BOLD_RESET}")
'bold text'
>>>

More Functions

There are more ANSI codes featured beyond colors and styles, these could be viewed by using help(ansiplus) inside the python interpreter.

Developers

When building the package for testing, it is recommended to use python3 -m build.

Wheels

When building the package for testing, it is recommended to use python3 -m build.

PIP Virtual Environments

Virtual environments should be named ".venv" or ".env", as this is used in the ".gitignore" file.

Contributing

Contributions must not include:

  • breaking code
  • major changes
  • changes to the version number
  • wheel files or egg-info files
  • spaghetti code

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

ansiplus-3.0.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

ansiplus-3.0-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file ansiplus-3.0.tar.gz.

File metadata

  • Download URL: ansiplus-3.0.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.4

File hashes

Hashes for ansiplus-3.0.tar.gz
Algorithm Hash digest
SHA256 f0bb3402e261ed40fb7ff260b39577a0ccaaec76aa57f87fb9e538fbd792a012
MD5 c79f5573ae7601c6c82c73ee3f7df538
BLAKE2b-256 6dcc05fb7cfcea5f2919d9cfa1ec1e4588f6cd8317189ea3e5ccd385f112a97d

See more details on using hashes here.

File details

Details for the file ansiplus-3.0-py3-none-any.whl.

File metadata

  • Download URL: ansiplus-3.0-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.4

File hashes

Hashes for ansiplus-3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1ec4eaf69260c63b4438f1c7d05b0a85dec3607c20028f203f67257a36bdf062
MD5 4621e1b73abfa9f09aa3c3e1e0d20394
BLAKE2b-256 e435a632deb24fd45cd377e3a19e151e5a120c48005197a288a2cb33a8b7341f

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