• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/H19-Dec-2020-307289

.tox/packaging/lib/python3.8/site-packages/H19-Dec-2020-

src/H19-Dec-2020-466347

.gitignoreH A D19-Dec-20201.8 KiB130105

.pre-commit-config.yamlH A D19-Dec-20201.6 KiB6564

.yamllintH A D19-Dec-2020629 3734

LICENSEH A D19-Dec-20201 KiB2217

MANIFEST.inH A D19-Dec-202056 43

PKG-INFOH A D19-Dec-20204 KiB10383

README.mdH A D19-Dec-20202 KiB6748

mypy.iniH A D19-Dec-2020266 1211

pyproject.tomlH A D19-Dec-2020380 2016

setup.cfgH A D19-Dec-20202.1 KiB9780

setup.pyH A D19-Dec-2020386 1810

tox.iniH A D19-Dec-20201.6 KiB7973

README.md

1# enrich
2
3Enriched extends [rich](https://pypi.org/project/rich/) library functionality
4with a set of changes that were not accepted to rich itself.
5
6## Console with redirect support
7
8Our Console class adds one additional option to rich.Console in order to
9redirect `sys.stdout` and `sys.stderr` streams using a FileProxy.
10
11```python
12from enrich.console import Console
13import sys
14
15console = Console(
16    redirect=True,  # <-- not supported by rich.cosole.Console
17    record=True)
18sys.write("foo")
19
20# this assert would have passed without redirect=True
21assert console.export_text() == "foo"
22```
23
24## Console with implicit soft wrapping
25
26If you want to produce fluid terminal output, one where the client terminal
27decides where to wrap the text instead of the application, you can now
28tell the Console constructor the soft_wrap preference.
29
30```python
31from enrich.console import Console
32import sys
33
34console = Console(soft_wrap=True)
35console.print(...)  # no longer need to pass soft_wrap to each print
36```
37
38## Console.print can also deal with ANSI escapes
39
40Extends Rich Console to detect if original text already had ANSI escapes and
41decodes it before processing it. This solves the case where printing
42output captured from other processes that contained ANSI escapes would brake.
43[upstream-404](https://github.com/willmcgugan/rich/discussions/404)
44
45## Soft-wrapping logger
46
47Rich logger assumes that you always have a fixed width console and it does
48wrap logged output according to it. Our alternative logger does exactly the
49opposite: it ignores the columns of the current console and prints output
50using a Console with soft wrapping enabled.
51
52The result are logged lines that can be displayed on any terminal or web
53page as they will allow the client to decide when to perform the wrapping.
54
55```python
56import logging
57from enrich.logging import RichHandler
58
59FORMAT = "%(message)s"
60logging.basicConfig(
61    level="NOTSET", format=FORMAT, datefmt="[%X]", handlers=[RichHandler()]
62)
63
64log = logging.getLogger("rich")
65log.info("Text that we do not want pre-wrapped by logger: %s", 100 * "x")
66```
67