Skip to main content

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.

Metadata

Release files for afmt 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for afmt 0.0.5
File Size Uploaded
afmt-0.0.5.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for afmt 0.0.5
File Interpreter ABI Platform
afmt-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 9.8 kB

Release files / afmt-0.0.5.tar.gz

Download URL afmt-0.0.5.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
25585bbe199291a818e7e2082217dcb7e52a8127451c24afc80c971139bf5e39
BLAKE2b-256 checksum
How to use checksums
059ade8aa0efa397f3f1cb0a965f929cdd6855755176465b45f6bff2d4b3d80d
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / afmt-0.0.5-py3-none-any.whl

Download URL afmt-0.0.5-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
58755892581134fc4ed99d0f65c45d54cfc403e42bb22cbdc880a85315dcd8f3
BLAKE2b-256 checksum
How to use checksums
b2d86a50e1de2f727a5c214882e88a499a5d0b33a5149592583868529f8ed664
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page