Skip to main content

ANSI escape code formatter

Project description

afmt

This module provides an easy way to format text in CLI environment. It is designed for use in f-strings but regular string formatting with format method is also supported.

The module takes care of stripping ANSI escape sequences from piped output and puts the sequences only if they're supported by the output device.

Setup

$ pip install afmt

Usage and examples

from afmt import Formatter

f = Formatter()

# You can use inline styling
print(f'{f:bold}bold text{f:e}')

# You can define specs outside of an f-string
warning = 'bold bg(yellow) fg(black) italic'
error = 'bold bg(red) fg(white) underline'
print(f'{f:{warning}}Warning: you shouldn\'t do it{f:e}')
print(f'{f:{error}}Error: you can\'t do it{f:e}')

# You can define custom styles in the formatter instance
f.add_style('important', 'b fg(red)')
print(f'{f:important}important text{f:e}')

# Or you can pass a dict of styles in the initializer 
f = Formatter(styles={
  'important': 'bold fg(255,0,0)',
  'unimporant': 'faint'
})
print(f'{f:important}important text{f:e}')
print(f'{f:unimportant}not so important text{f:e}')

# Move cursor to 4th row and 6th column and print text in reverse video mode 
print(f'{f:reverse goto(4,6)}hello, world{f:e}')

# Make text bold and underlined and unset bold in the middle
print(f'{f:bold italic}hello,{f:!bold} world{f:e}')

asciicast

Development status

This module is in the early stage of development. More features are coming hopefully soon.

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

afmt-0.0.4.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

afmt-0.0.4-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file afmt-0.0.4.tar.gz.

File metadata

  • Download URL: afmt-0.0.4.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for afmt-0.0.4.tar.gz
Algorithm Hash digest
SHA256 312ffe1a298801a0fe763037ee92d5452edaf87ef2ee8c2814aa45074bfb008d
MD5 b0a5576bab6dddcc2334104a4610cb5b
BLAKE2b-256 8f2c62ece8bdb3dd205fa2607b088506b3ecfbaa2b828db4f8ce215e937496e9

See more details on using hashes here.

File details

Details for the file afmt-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: afmt-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for afmt-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 18885a7173ac2624e8e6c206e130fb6c8dbd9365c33a24fd8091f0fd660e97f2
MD5 1a8ae379e6a9d8e18cceb5a3d8d78aba
BLAKE2b-256 25d8ba8701c1f5db7dc97c22195cbc0652e400e38552e31aa43806fdf4191fe8

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