Colored text output in Python using ANSI escape sequences.
Project description
styled-str
StyledStr is a module for creating strings styled with ANSI escape sequences. The motivation for writing this package was that many existing string-styling modules do not implement logical string behavior, like properly formatting the string, indexing, containment, all of which are useless if they don't ignore the styling.
StyledStr ignores styling and acts on just its content for the following operations:
For an example StyledStr s = StyledStr('Hello!', fg='red', style='italic')
- length, e.g. `len(s) => 6`
- formatting, e.g. `f'{s:.3}' => 'Hel'`
- indexing, e.g. `s[1] => 'e'`
- iteration, e.g. `for c in s: => H, e, l, l, o, !`
- reversed, e.g. `for c in reversed(s): => !, o, l, l, e, H`
- containment, e.g. only characters of "Hello!" are True for `c in s`
We would like to have a strings with the same content viewed as distinct though, and so StyledStr includes styling for the following operations:
For example StyledStrs a = StyledStr('Hello!', fg='red'); b = StyledStr('Hello!', bg='blue')
- equality, e.g. `a == b => False`
- comparison, e.g. `a < b => True`
- hashing, e.g. `hash(a)` not necessarily `hash(b)`
Installation
Install using pip (Python3):
pip3 install styled-str
Usage
Import the module and create a string with your desired styles:
from styledstr import Styled
s = Styled('Hello World!', fg='cyan', bg='white', style=['bold', 'underlined'])
# Print it out
print(s)
# Use it in a larger string
print("He said, '" + str(s) + "'")
# Format it worry-free!
print(f'Title: {s:>20}')
Project details
Release history Release notifications | RSS feed
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
Hashes for styled_str-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c553a3d033a5de8a4aae45e8ea886fbe70d8cf19e8f9e2436009d8a3633d3289 |
|
MD5 | d8b9ceed10fb5f19574c74f659384e1f |
|
BLAKE2b-256 | 78d75a959d94f4d0c343ec29a77ac287049e0106df622c1116dedbad184c2b3e |