prettifiers
This module provides some methods to prettify things.
The main export here is prettify
. It uses pytermgui.parser.tim
, and all of its
markup magic to create prettier representations of whatever is given.
prettify(target, indent=2, force_markup=False, expand_all=False, parse=True)
Prettifies any Python object.
This uses a set of pre-defined aliases for the styling, and as such is fully customizable.
The aliases are:
- str
: Applied to all strings, so long as they do not contain TIM code.
- int
: Applied to all integers and booleans. The latter are included as they
subclass int.
- type
: Applied to all types.
- none
: Applied to NoneType. Note that when using pytermgui.pretty
, a
single None
return value will not be printed, only when part of a more
complex structure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
Any
|
The object to prettify. Can be any type. |
required |
indent |
int
|
The indentation used for multi-line objects, like containers. When
set to 0, these will be collapsed. By default, container types with
|
2
|
force_markup |
bool
|
When this is set every ANSI-sequence string will be turned into markup and syntax highlighted. |
False
|
expand_all |
bool
|
When set, objects that would normally be force-collapsed are also going to be expanded. |
False
|
parse |
bool
|
If not set, the return value will be a plain markup string, not yet parsed. |
True
|
Returns:
Type | Description |
---|---|
str
|
A pretty string of the given target. |
Source code in pytermgui/prettifiers.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 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 87 88 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 |
|