execution
All the code used to record code execution.
TermageNamespace
A simple namespace for exec globals, exposed as termage
.
You can use all below methods by referencing the termage
object
in termage-run code, which you don't have to import.
You usually want to hide these lines, as they are generally for styling purposes.
Source code in termage/execution.py
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 |
|
fit(widget)
Fits the output terminal around the given widget.
Source code in termage/execution.py
65 66 67 68 |
|
resize(width, height)
Resizes the output terminal to the given dimensions.
Source code in termage/execution.py
70 71 72 73 |
|
terminal()
property
Returns the current terminal object.
Source code in termage/execution.py
59 60 61 62 63 |
|
execute(code=None, file=None, highlight=False, *, exec_globals=EXEC_GLOBALS)
Executes the given code under a custom context.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code |
str | None
|
The Python code to execute. |
None
|
file |
Path | None
|
A file that will be opened, and its contents will
be added to the executed code before the |
None
|
highlight |
bool
|
If set, the combined code will only be highlighted using
PyTermGUI's |
False
|
exec_globals |
dict[str, Any]
|
The dictionary that will be passed to |
EXEC_GLOBALS
|
Source code in termage/execution.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
|
format_codeblock(block)
Formats a codeblock into display and executed lines.
Source code in termage/execution.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|
patched_stdout_recorder(width, height)
Records everything written to stdout, even built is print.
It does so by monkeypathing sys.stdout.write
to a custom function,
which first writes to a custom Terminal
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
width |
int | None
|
The width of the terminal used for the recording. |
required |
height |
int | None
|
The height of the terminal used for the recording. |
required |
Returns:
Type | Description |
---|---|
Generator[ptg.Recorder, None, None]
|
The recorder object, with all the data written to it. |
Source code in termage/execution.py
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 |
|
set_colors(foreground, background)
Sets the colors that will be used by the terminal.
Source code in termage/execution.py
185 186 187 188 189 190 191 192 |
|
termage(code='', include=None, width=None, height=None, title='', chrome=True, foreground=None, background=None, highlight_only=False, save_as=None)
A generalized wrapper for Termage functionality.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code |
str
|
The code that will be run to generate the file. |
''
|
include |
str | Path | None
|
A path to a Python file that will be included before |
None
|
width |
int | None
|
The output terminal's width. |
None
|
height |
int | None
|
The output terminal's height. |
None
|
title |
str
|
The output terminal's window title. Has no effect when |
''
|
chrome |
bool
|
Shows or hides the window decorations. |
True
|
foreground |
str | None
|
Sets the default foreground (text) style of the output. Only applies to unstyled text. |
None
|
background |
str | None
|
Sets the output terminal's background color. |
None
|
highlight_only |
bool
|
If set, the given code is not run, rather given to the
|
False
|
save_as |
str | Path | None
|
If set, the export will be written to this filepath. The export will be returned regardless of this setting. |
None
|
Returns:
Type | Description |
---|---|
str
|
The exported SVG file. |
Source code in termage/execution.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
|