enrich
Project description
enrich
Enriched extends rich library functionality with a set of changes that were not accepted to rich itself.
Console with redirect support
Our Console class adds one additional option to rich.Console in order to
redirect sys.stdout
and sys.stderr
streams using a FileProxy.
from enrich.console import Console
import sys
console = Console(
redirect=True, # <-- not supported by rich.cosole.Console
record=True)
sys.write("foo")
# this assert would have passed without redirect=True
assert console.export_text() == "foo"
Console with implicit soft wrapping
If you want to produce fluid terminal output, one where the client terminal decides where to wrap the text instead of the application, you can now tell the Console constructor the soft_wrap preference.
from enrich.console import Console
import sys
console = Console(soft_wrap=True)
console.print(...) # no longer need to pass soft_wrap to each print
Console.print can also deal with ANSI escapes
Extends Rich Console to detect if original text already had ANSI escapes and decodes it before processing it. This solves the case where printing output captured from other processes that contained ANSI escapes would brake. upstream-404
Soft-wrapping logger
Rich logger assumes that you always have a fixed width console and it does wrap logged output according to it. Our alternative logger does exactly the opposite: it ignores the columns of the current console and prints output using a Console with soft wrapping enabled.
The result are logged lines that can be displayed on any terminal or web page as they will allow the client to decide when to perform the wrapping.
import logging
from enrich.logging import RichHandler
FORMAT = "%(message)s"
logging.basicConfig(
level="NOTSET", format=FORMAT, datefmt="[%X]", handlers=[RichHandler()]
)
log = logging.getLogger("rich")
log.info("Text that we do not want pre-wrapped by logger: %s", 100 * "x")
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
File details
Details for the file enrich-1.2.2.tar.gz
.
File metadata
- Download URL: enrich-1.2.2.tar.gz
- Upload date:
- Size: 15.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf7e35b3bf7d981fd8b133a95592149e0a20ef896f339cca8699bf5f68d8c908 |
|
MD5 | 1429cd06e8b99ae75740d4e3359b7c4d |
|
BLAKE2b-256 | 82e7d89b6a38dbdb934e7394b6d09e46e84d837a7ee738a0fd43f59d9251f372 |
Provenance
File details
Details for the file enrich-1.2.2-py3-none-any.whl
.
File metadata
- Download URL: enrich-1.2.2-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe91e8b60219e80cc708f0be4ad81a74126f7901449694b555af60218fc2294c |
|
MD5 | d4ba71a4a67336c0ac69d2ba47ed3c6d |
|
BLAKE2b-256 | 9410def300f57e14db2c1369066416c1458257945ef8287fdefee55c30c769b0 |