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}')
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file afmt-0.0.5.tar.gz.
File metadata
- Download URL: afmt-0.0.5.tar.gz
- Upload date:
- Size: 4.3 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
25585bbe199291a818e7e2082217dcb7e52a8127451c24afc80c971139bf5e39
|
|
| MD5 |
d0ea9b33bb0b1447ffc4e99328fc3037
|
|
| BLAKE2b-256 |
059ade8aa0efa397f3f1cb0a965f929cdd6855755176465b45f6bff2d4b3d80d
|
File details
Details for the file afmt-0.0.5-py3-none-any.whl.
File metadata
- Download URL: afmt-0.0.5-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58755892581134fc4ed99d0f65c45d54cfc403e42bb22cbdc880a85315dcd8f3
|
|
| MD5 |
d1bd49977be9a9bdb4af53196db920b3
|
|
| BLAKE2b-256 |
b2d86a50e1de2f727a5c214882e88a499a5d0b33a5149592583868529f8ed664
|