pretty
This module calls install()
on import, and defines print
as pprint
.
It allows setting up pretty print functionality in only one line.
Usage
>>> from pytermgui.pretty import print
PTGFormatter
Bases: BaseFormatter
An IPython formatter for PTG pretty printing.
Source code in pytermgui/pretty.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
|
__call__(value)
Pretty prints the given value, as well as a leading newline.
The newline is needed since IPython output is prepended with "Out[i]:", and it might mess alignments up.
Source code in pytermgui/pretty.py
164 165 166 167 168 169 170 171 172 173 174 175 176 |
|
__init__(**kwargs)
Initializes PTGFormatter, storing **kwargs.
Source code in pytermgui/pretty.py
157 158 159 160 161 162 |
|
install(indent=2, force_markup=False, expand_all=False)
Sets up pprint
to print all REPL output. IPython is also supported.
This function sets up a hook that will call pprint
after every interactive return.
The given arguments are passed directly to pprint
, so for more information
you can check out that function.
Usage is pretty simple:
>>> from pytermgui import pretty
>>> tim.setup_displayhook()
>>> # Any function output will now be prettified
...or alternatively, you can import print
from pytermgui.pretty
,
and have it automatically set up, and replace your namespace's print
function with tim.pprint
:
>>> from pytermgui.pretty import print
... # Under the hood, the above is called and `tim.pprint` is set
... # for the `print` name
>>> # Any function output will now be prettified
Parameters:
Name | Type | Description | Default |
---|---|---|---|
indent |
int
|
The indentation value used for multi-line objects. This is ignored when
the given object has a |
2
|
force_markup |
bool
|
Turn all ANSI-sequences into tim before pretty printing. |
False
|
expand_all |
bool
|
Force-expand containers, even when they would normally be collapsed. |
False
|
Source code in pytermgui/pretty.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
|
pprint(*items, indent=2, expand_all=False, force_markup=False, parse=True, **print_args)
A wrapper to pretty-print any object.
This essentially just calls prettify
on each given object, and passes the
**print_args
right through to print. Note that when the sep
print argument is
ommitted it is manually set to ", \n"
.
To customize any of the styles, see MarkupLanguage.prettify
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*items |
Any
|
The items to print. These are passed in the same way they would be into builtin print. |
()
|
indent |
int
|
The indentation value used for multi-line objects. This is ignored when
the given object has a |
2
|
force_markup |
bool
|
Turn all ANSI-sequences into markup before pretty printing. |
False
|
expand_all |
bool
|
Force-expand containers, even when they would normally be collapsed. |
False
|
**print_args |
Any
|
All arguments passed to builtin print. |
{}
|
Source code in pytermgui/pretty.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|