Index
Welcome to the API reference for PyTermGUI, a Python TUI framework with mouse support, modular widget system, customizable and rapid terminal markup language and more!
animator = Animator()
module-attribute
The global Animator instance used by all of the library.
keys = Keys(_platform_keys, 'nt')
module-attribute
Instance storing platform specific key codes.
terminal = Terminal()
module-attribute
Terminal instance that should be used pretty much always.
ASCII
Bases: Frame
A frame made up of only ASCII characters.
Preview:
-----
| x |
-----
Source code in pytermgui/widgets/frames.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
ASCII_O
Bases: Frame
A frame made up of only ASCII characters, with X-s in the corners.
Preview:
o---o
| x |
o---o
Source code in pytermgui/widgets/frames.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
ASCII_X
Bases: Frame
A frame made up of only ASCII characters, with X-s in the corners.
Preview:
x---x
| # |
x---x
Source code in pytermgui/widgets/frames.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
AliasToken
dataclass
Bases: Token
A way to reference a set of tags from one central name.
Source code in pytermgui/markup/tokens.py
260 261 262 263 264 265 266 | |
Animator
The Animator class
This class maintains a list of animations (self._animations), stepping each of them forward as long as they return False. When they return False, the animation is removed from the tracked animations.
This stepping is done when step is called.
Source code in pytermgui/animations.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | |
is_active
property
Determines whether there are any active animations.
__contains__(item)
Returns whether the item is inside _animations.
Source code in pytermgui/animations.py
264 265 266 267 | |
__init__()
Initializes an animator.
Source code in pytermgui/animations.py
259 260 261 262 | |
animate_attr(**animation_args)
Creates and schedules an AttrAnimation.
All arguments are passed to the AttrAnimation constructor. direction, if
given as an integer, will be converted to a Direction before being passed.
Returns:
| Type | Description |
|---|---|
AttrAnimation
|
The created animation. |
Source code in pytermgui/animations.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
animate_float(**animation_args)
Creates and schedules an Animation.
All arguments are passed to the Animation constructor. direction, if
given as an integer, will be converted to a Direction before being passed.
Returns:
| Type | Description |
|---|---|
FloatAnimation
|
The created animation. |
Source code in pytermgui/animations.py
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | |
schedule(animation)
Starts an animation on the next step.
Source code in pytermgui/animations.py
283 284 285 286 | |
step(elapsed)
Steps the animation forward by the given elapsed time.
Source code in pytermgui/animations.py
275 276 277 278 279 280 281 | |
AnsiSyntaxError
dataclass
Bases: ParserSyntaxError
Raised when parsed ANSI text contains an error.
Source code in pytermgui/exceptions.py
90 91 92 93 | |
AttrAnimation
dataclass
Bases: Animation
Animates an attribute going from one value to another.
Source code in pytermgui/animations.py
189 190 191 192 193 194 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 244 245 246 | |
finish()
Deletes __ptg_animated__ flag, calls on_finish.
Source code in pytermgui/animations.py
242 243 244 245 246 | |
step(elapsed)
Steps forward in the attribute animation.
Source code in pytermgui/animations.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
Button
Bases: Widget
A simple Widget representing a mouse-clickable button
Source code in pytermgui/widgets/button.py
14 15 16 17 18 19 20 21 22 23 24 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 | |
__init__(label='Button', onclick=None, padding=0, centered=False, **attrs)
Initialize object
Source code in pytermgui/widgets/button.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
get_lines()
Get object lines
Source code in pytermgui/widgets/button.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
handle_key(key)
Handles a keypress
Source code in pytermgui/widgets/button.py
79 80 81 82 83 84 85 86 | |
handle_mouse(event)
Handles a mouse event
Source code in pytermgui/widgets/button.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
on_hover(_)
Sets highlight style when hovering.
Source code in pytermgui/widgets/button.py
48 49 50 51 52 | |
on_release(_)
Sets normal style when no longer hovering.
Source code in pytermgui/widgets/button.py
54 55 56 57 58 | |
CenteringPolicy
Bases: DefaultEnum
Policies to center Container according to.
Source code in pytermgui/enums.py
59 60 61 62 63 64 | |
Checkbox
Bases: Button
A simple checkbox
Source code in pytermgui/widgets/checkbox.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 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 | |
__init__(callback=None, checked=False, **attrs)
Initialize object
Source code in pytermgui/widgets/checkbox.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
toggle(*_, run_callback=True)
Toggle state
Source code in pytermgui/widgets/checkbox.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
ClearToken
dataclass
Bases: Token
A tag-clearer.
These tokens are prefixed by /, and followed by the name of the tag they target.
To reset color information in the current text, use the /fg and /bg special
tags. We cannot unset a specific color due to how the terminal works; all these do
is "reset" the current stroke color to the default of the terminal.
Additionally, there are some other special identifiers:
/: Clears all tags, including styles, colors, macros, links and more./!: Clears all currently applied macros./~: Clears all currently applied links.
Source code in pytermgui/markup/tokens.py
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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
targets(token)
Returns True if this token targets the one given as an argument.
Source code in pytermgui/markup/tokens.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
Collapsible
Bases: Container
A collapsible section of UI.
Source code in pytermgui/widgets/collapsible.py
16 17 18 19 20 21 22 23 24 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 | |
__init__(label, *items, keyboard=False, **attrs)
Initializes the widget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label for the trigger toggle. |
required |
*items
|
Any
|
The items that will be hidden when the object is collapsed. |
()
|
keyboard
|
bool
|
If set, the first character of the label will be used as
a |
False
|
Source code in pytermgui/widgets/collapsible.py
19 20 21 22 23 24 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 | |
collapse()
Collapses the dropdown.
Does nothing if already collapsed.
Returns:
| Type | Description |
|---|---|
Collapsible
|
This object. |
Source code in pytermgui/widgets/collapsible.py
84 85 86 87 88 89 90 91 92 93 94 95 96 | |
expand()
Expands the dropdown.
Does nothing if already expanded.
Returns:
| Type | Description |
|---|---|
Collapsible
|
This object. |
Source code in pytermgui/widgets/collapsible.py
98 99 100 101 102 103 104 105 106 107 108 109 110 | |
toggle()
Toggles expanded state.
Returns:
| Type | Description |
|---|---|
Collapsible
|
This object. |
Source code in pytermgui/widgets/collapsible.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
Color
dataclass
A terminal color.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The data contained within this color. |
required |
background
|
bool
|
Whether this color will represent a color. |
False
|
These colors are all formattable. There are currently 2 'spec' strings: - f"{my_color:tim}" -> Returns self.markup - f"{my_color:seq}" -> Returns self.sequence
They can thus be used in TIM strings:
>>> ptg.tim.parse("[{my_color:tim}]Hello")
'[<my_color.markup>]Hello'
And in normal, ANSI coded strings:
>>> "{my_color:seq}Hello"
'<my_color.sequence>Hello'
Source code in pytermgui/colors.py
132 133 134 135 136 137 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 183 184 185 186 187 188 189 190 191 192 193 194 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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | |
analogous
cached
property
blue
cached
property
Returns the red component of this color.
brightness
cached
property
Returns the perceived "brightness" of a color.
From https://stackoverflow.com/a/56678483
complement
cached
property
Returns the complement of this color.
contrast
cached
property
Returns a color (black or white) that complies with the W3C contrast ratio guidelines.
green
cached
property
Returns the red component of this color.
hex
cached
property
Returns CSS-like HEX representation of this color.
hls
cached
property
Returns the HLS (Hue, Lightness, Saturation) representation of this color.
hue
cached
property
Returns the hue component of this color.
lightness
cached
property
Returns the lightness component of this color.
luminance
cached
property
Returns this color's perceived luminance (brightness).
From https://stackoverflow.com/a/596243
markup
cached
property
Returns the TIM representation of this color.
name
property
Returns the reverse-parseable name of this color.
red
cached
property
Returns the red component of this color.
rgb
cached
property
Returns this color as a tuple of (red, green, blue) values.
saturation
cached
property
Returns the saturation component of this color.
sequence
property
Returns the ANSI sequence representation of the color.
tetradic
cached
property
triadic
cached
property
__call__(text, reset=True)
Colors the given string.
Source code in pytermgui/colors.py
493 494 495 496 497 498 499 500 | |
__format__(spec)
Formats the color by the given specification.
Source code in pytermgui/colors.py
165 166 167 168 169 170 171 172 173 174 | |
blend(other, alpha=0.5, localize=False)
Blends a color into another one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Color
|
The color to blend with. |
required |
alpha
|
float
|
How much the other color should influence the outcome. |
0.5
|
localize
|
bool
|
If set, the returned color will returned its localized version by running
|
False
|
Returns:
| Type | Description |
|---|---|
Color
|
A |
Source code in pytermgui/colors.py
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 | |
blend_complement(alpha=0.5)
Blends this color with its complement.
See Color.blend.
Source code in pytermgui/colors.py
450 451 452 453 454 455 456 | |
blend_contrast(alpha=0.5)
Blends this color with its contrast pair.
See Color.blend.
Source code in pytermgui/colors.py
458 459 460 461 462 463 464 | |
darken(alpha=0.5)
Darkens the color by blending it with black, using the alpha provided.
Source code in pytermgui/colors.py
466 467 468 469 | |
from_hls(hsl)
classmethod
Creates a color from the given HLS.
HLS stands for Hue, Lightness & Saturation. It is more commonly known as HSL,
but the colorsys library uses HLS instead so that's what we use too.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hsl
|
RGBTriplet
|
The HLS value to base the new color off of. |
required |
Source code in pytermgui/colors.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
from_rgb(rgb)
classmethod
Creates a color from the given RGB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rgb
|
RGBTriplet
|
The RGB value to base the new color off of. |
required |
Source code in pytermgui/colors.py
176 177 178 179 180 181 182 183 184 | |
get_default_background()
classmethod
Gets the terminal emulator's default foreground color.
Source code in pytermgui/colors.py
286 287 288 289 290 291 292 293 | |
get_default_foreground()
classmethod
Gets the terminal emulator's default foreground color.
Source code in pytermgui/colors.py
277 278 279 280 281 282 283 284 | |
get_localized()
Creates a terminal-capability local Color instance.
This method essentially allows for graceful degradation of colors in the terminal.
Source code in pytermgui/colors.py
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | |
hue_offset(offset)
Returns the color offset by the given hue.
Source code in pytermgui/colors.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | |
lighten(alpha=0.5)
Lightens the color by blending it with white, using the alpha provided.
Source code in pytermgui/colors.py
471 472 473 474 | |
parse(text, background=False, localize=True, use_cache=False)
classmethod
Uses str_to_color to parse some text into a Color.
Source code in pytermgui/colors.py
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 | |
ColorPicker
Bases: Container
A simple ColorPicker widget.
This is used to visualize xterm-255 colors. RGB colors are not included here, as it is probably easier to use a web-based picker for those anyways.
Source code in pytermgui/widgets/color_picker.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
selectables_length
property
Returns either the button count or 1.
__init__(show_output=True, **attrs)
Initializes a ColorPicker.
Attrs
show_output: Decides whether the output Container should be added. If not set, the widget will only display the PixelMatrix of colors.
Source code in pytermgui/widgets/color_picker.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
get_lines()
Updates self._output and gets widget lines.
Source code in pytermgui/widgets/color_picker.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
handle_mouse(event)
Handles mouse events.
On hover, the widget will display the currently hovered color and some testing text.
On click, it will add a _FadeInButton for the currently hovered color.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
MouseEvent
|
The event to handle. |
required |
Source code in pytermgui/widgets/color_picker.py
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 244 245 246 247 | |
ColorSystem
Bases: Enum
An enumeration of various terminal-supported colorsystems.
Source code in pytermgui/term.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
EIGHT_BIT = 1
class-attribute
instance-attribute
xterm 8-bit colors, 0-256.
NO_COLOR = -1
class-attribute
instance-attribute
No-color terminal. See https://no-color.org/.
STANDARD = 0
class-attribute
instance-attribute
Standard 3-bit colorsystem of the basic 16 colors.
TRUE = 2
class-attribute
instance-attribute
'True' color, a.k.a. 24-bit RGB colors.
__ge__(other)
Comparison: self >= other.
Source code in pytermgui/term.py
180 181 182 183 184 185 186 | |
__gt__(other)
Comparison: self > other.
Source code in pytermgui/term.py
188 189 190 191 192 193 194 | |
__le__(other)
Comparison: self <= other.
Source code in pytermgui/term.py
196 197 198 199 200 201 202 | |
__lt__(other)
Comparison: self < other.
Source code in pytermgui/term.py
204 205 206 207 208 209 210 | |
ColorToken
dataclass
Bases: Token
A color identifier.
It stores the markup that created it, as well as the pytermgui.colors.Color object
that it represents.
Source code in pytermgui/markup/tokens.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
Compositor
The class used to draw pytermgui.window_managers.manager.WindowManager state.
This class handles turning a list of windows into a drawable buffer (composite), and then drawing it onto the screen.
Calling its run method will start the drawing thread, which will draw the current
window states onto the screen. This routine targets framerate, though will likely
not match it perfectly.
Source code in pytermgui/window_manager/compositor.py
20 21 22 23 24 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 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 183 184 185 186 187 188 189 190 191 192 193 194 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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
framerate
property
writable
The framerate the draw loop runs at.
Note
This will likely not be matched very accurately, mostly undershooting the given target.
terminal
property
Returns the current global terminal.
__init__(windows, framerate)
Initializes the Compositor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
windows
|
list[Window]
|
A list of the windows to be drawn. |
required |
Source code in pytermgui/window_manager/compositor.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
capture(title, filename=None)
Captures the most-recently drawn buffer as filename.
See pytermgui.exporters.to_svg for more information.
Source code in pytermgui/window_manager/compositor.py
273 274 275 276 277 278 279 280 281 282 | |
clear_cache(window)
Clears the compositor's cache related to the given window.
Source code in pytermgui/window_manager/compositor.py
160 161 162 163 164 | |
composite()
Creates a composited buffer from the assigned windows.
Note that this is currently not used.
Source code in pytermgui/window_manager/compositor.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 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 | |
draw(force=False)
Writes composited screen to the terminal.
At the moment this uses full-screen rewrites. There is a compositing
implementation in composite, but it is currently not performant enough to use.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
force
|
bool
|
When set, new composited lines will not be checked against the previous ones, and everything will be redrawn. |
False
|
Source code in pytermgui/window_manager/compositor.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
redraw()
Force-redraws the buffer.
Source code in pytermgui/window_manager/compositor.py
268 269 270 271 | |
run()
Runs the compositor draw loop as a thread.
Source code in pytermgui/window_manager/compositor.py
166 167 168 169 170 | |
set_redraw()
Flags compositor for full redraw.
Note
At the moment the compositor will always redraw the entire screen.
Source code in pytermgui/window_manager/compositor.py
226 227 228 229 230 231 232 233 | |
stop()
Stops the compositor.
Source code in pytermgui/window_manager/compositor.py
172 173 174 175 | |
Container
Bases: ScrollableWidget
A widget that displays other widgets, stacked vertically.
Source code in pytermgui/widgets/containers.py
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 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 183 184 185 186 187 188 189 190 191 192 193 194 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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 | |
box
property
writable
content_dimensions
property
Gets the size (width, height) of the available content area.
selectables
property
Gets all selectable widgets and their inner indices.
This is used in order to have a constant reference to all selectable indices within this widget.
Returns:
| Type | Description |
|---|---|
list[tuple[Widget, int]]
|
A list of tuples containing a widget and an integer each. For each widget that is |
list[tuple[Widget, int]]
|
withing this one, it is added to this list as many times as it has selectables. Each |
list[tuple[Widget, int]]
|
of the integers correspond to a selectable_index within the widget. |
list[tuple[Widget, int]]
|
For example, a Container with a Button, InputField and an inner Container containing |
list[tuple[Widget, int]]
|
3 selectables might return something like this: |
list[tuple[Widget, int]]
|
``` |
list[tuple[Widget, int]]
|
[ (Button(...), 0), (InputField(...), 0), (Container(...), 0), (Container(...), 1), (Container(...), 2), |
list[tuple[Widget, int]]
|
] |
list[tuple[Widget, int]]
|
``` |
selectables_length
property
Gets the length of the selectables list.
Returns:
| Type | Description |
|---|---|
int
|
An integer equal to the length of |
selected
property
sidelength
property
Gets the length of left and right borders combined.
Returns:
| Type | Description |
|---|---|
int
|
An integer equal to the |
__add__(other)
Adds a new widget, then returns self.
This method is analogous to Container.__iadd__.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
object
|
Any widget instance, or data structure that can be turned
into a widget by |
required |
Returns:
| Type | Description |
|---|---|
Container
|
A reference to self. |
Source code in pytermgui/widgets/containers.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
__contains__(other)
Determines if self._widgets contains other widget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
object
|
Any widget-like. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
A boolean describing whether |
Source code in pytermgui/widgets/containers.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | |
__getitem__(sli)
Gets an item from self._widgets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sli
|
int | slice
|
Slice of the list. |
required |
Returns:
| Type | Description |
|---|---|
Widget | list[Widget]
|
The slice in the list. |
Source code in pytermgui/widgets/containers.py
281 282 283 284 285 286 287 288 289 290 291 | |
__iadd__(other)
Adds a new widget, then returns self.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
object
|
Any widget instance, or data structure that can be turned
into a widget by |
required |
Returns:
| Type | Description |
|---|---|
Container
|
A reference to self. |
Source code in pytermgui/widgets/containers.py
233 234 235 236 237 238 239 240 241 242 243 244 245 | |
__init__(*widgets, **attrs)
Initialize Container data
Source code in pytermgui/widgets/containers.py
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 | |
__iter__()
Gets an iterator of self._widgets.
Yields:
| Type | Description |
|---|---|
Widget
|
The next widget. |
Source code in pytermgui/widgets/containers.py
263 264 265 266 267 268 269 270 | |
__len__()
Gets the length of the widgets list.
Returns:
| Type | Description |
|---|---|
int
|
An integer describing len(self._widgets). |
Source code in pytermgui/widgets/containers.py
272 273 274 275 276 277 278 279 | |
__setitem__(index, value)
Sets an item in self._widgets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
The index to be set. |
required |
value
|
Any
|
The new widget at this index. |
required |
Source code in pytermgui/widgets/containers.py
293 294 295 296 297 298 299 300 301 | |
center(where=None, store=True)
Centers this object to the given axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
where
|
CenteringPolicy | None
|
A CenteringPolicy describing the place to center to |
None
|
store
|
bool
|
When set, this centering will be reapplied during every print, as well as when calling this method with no arguments. |
True
|
Returns:
| Type | Description |
|---|---|
Container
|
This Container. |
Source code in pytermgui/widgets/containers.py
731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 | |
debug()
Returns a string with identifiable information on this widget.
Returns:
| Type | Description |
|---|---|
str
|
A str in the form of a class construction. This string is in a form that |
str
|
could have been used to create this Container. |
Source code in pytermgui/widgets/containers.py
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 | |
execute_binding(key, ignore_any=False)
Executes a binding on self, and then on self._widgets.
If a widget.execute_binding call returns True this function will too. Note that on success the function returns immediately; no further widgets are checked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Any
|
The binding key. |
required |
ignore_any
|
bool
|
If set, |
False
|
Returns:
| Type | Description |
|---|---|
bool
|
True if any widget returned True, False otherwise. |
Source code in pytermgui/widgets/containers.py
859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 | |
get_change()
Determines whether widget lines changed since the last call to this function.
Source code in pytermgui/widgets/containers.py
219 220 221 222 223 224 225 226 227 228 229 230 231 | |
get_lines()
Gets all lines by spacing out inner widgets.
This method reflects & applies both width settings, as well as
the parent_align field.
Returns:
| Type | Description |
|---|---|
list[str]
|
A list of all lines that represent this Container. |
Source code in pytermgui/widgets/containers.py
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 | |
handle_key(key)
Handles a keypress, returns its success.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
A key str. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
A boolean showing whether the key was handled. |
Source code in pytermgui/widgets/containers.py
889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 | |
handle_mouse(event)
Handles mouse events.
This, like all mouse handlers should, calls super()'s implementation first,
to allow usage of on_{event}-type callbacks. After that, it tries to find
a target widget within itself to handle the event.
Each handler will return a boolean. This boolean is then used to figure out whether the targeted widget should be "sticky", i.e. a slider. Returning True will set that widget as the current mouse target, and all mouse events will be sent to it as long as it returns True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
MouseEvent
|
The event to handle. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether the parent of this widget should treat it as one to "stick" events |
bool
|
to, e.g. to keep sending mouse events to it. One can "unstick" a widget by |
bool
|
returning False in the handler. |
Source code in pytermgui/widgets/containers.py
772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 | |
lazy_add(other)
Adds other without running get_lines.
This is analogous to `self._add_widget(other, run_get_lines=False).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
object
|
The object to add. |
required |
Source code in pytermgui/widgets/containers.py
502 503 504 505 506 507 508 509 510 511 | |
move(diff_x, diff_y)
Moves the widget and its children by the given x and y changes.
Source code in pytermgui/widgets/containers.py
513 514 515 516 517 518 519 | |
pop(index=-1)
Pops widget from self._widgets.
Analogous to self._widgets.pop(index).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
The index to operate on. |
-1
|
Returns:
| Type | Description |
|---|---|
Widget
|
The widget that was popped off the list. |
Source code in pytermgui/widgets/containers.py
641 642 643 644 645 646 647 648 649 650 651 652 653 | |
print()
Prints this Container.
If the screen size has changed since last print call, the object
will be centered based on its centered_axis.
Source code in pytermgui/widgets/containers.py
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 | |
remove(other)
Remove widget from self._widgets
Analogous to self._widgets.remove(other).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Widget
|
The widget to remove. |
required |
Source code in pytermgui/widgets/containers.py
655 656 657 658 659 660 661 662 663 664 | |
select(index=None)
Selects inner subwidget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int | None
|
The index to select. |
None
|
Raises:
| Type | Description |
|---|---|
IndexError
|
The index provided was beyond len(self.selectables). |
Source code in pytermgui/widgets/containers.py
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 | |
serialize()
Serializes this Container, adding in serializations of all widgets.
See pytermgui.widgets.base.Widget.serialize for more info.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The dictionary containing all serialized data. |
Source code in pytermgui/widgets/containers.py
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 | |
set_recursive_depth(value)
Set depth for this Container and all its children.
All inner widgets will receive value+1 as their new depth.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
int
|
The new depth to use as the base depth. |
required |
Source code in pytermgui/widgets/containers.py
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 | |
set_widgets(new)
Sets new list in place of self._widgets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new
|
list[Widget]
|
The new widget list. |
required |
Source code in pytermgui/widgets/containers.py
613 614 615 616 617 618 619 620 621 622 | |
wipe()
Wipes the characters occupied by the object
Source code in pytermgui/widgets/containers.py
967 968 969 970 971 972 | |
ContextDict
Bases: TypedDict
A dictionary to hold context about a markup language's environment.
It has two sub-dicts:
- aliases
- macros
For information about what they do and contain, see the MarkupLanguage docs.
Source code in pytermgui/markup/parsing.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
CursorToken
dataclass
Bases: Token
A cursor location.
These can be used to move the terminal's cursor.
Source code in pytermgui/markup/tokens.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | |
DensePixelMatrix
Bases: PixelMatrix
A more dense (2x) PixelMatrix.
Due to each pixel only occupying 1/2 characters in height, accurately determining selected_pixel is impossible, thus the functionality does not exist here.
Source code in pytermgui/widgets/pixel_matrix.py
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 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
__init__(width, height, default='', **attrs)
Initializes DensePixelMatrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
int
|
The width of the matrix. |
required |
height
|
int
|
The height of the matrix. |
required |
default
|
str
|
The default color to use to initialize the matrix with. |
''
|
Source code in pytermgui/widgets/pixel_matrix.py
162 163 164 165 166 167 168 169 170 171 172 173 | |
build()
Builds the image pixels, using half-block characters.
Returns:
| Type | Description |
|---|---|
list[str]
|
The lines that this object will return, until a subsequent |
list[str]
|
These lines are stored in the |
Source code in pytermgui/widgets/pixel_matrix.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
handle_mouse(event)
As mentioned in the class documentation, mouse handling is disabled here.
Source code in pytermgui/widgets/pixel_matrix.py
175 176 177 178 | |
Double
Bases: Frame
A frame with a double outline.
Preview:
╔═══╗
║ x ║
╚═══╝
Source code in pytermgui/widgets/frames.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |
FancyReprWidget
Bases: Widget
A widget that wraps objects supporting the fancy_repr protocol.
Source code in pytermgui/widgets/fancy_repr.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
get_lines()
Builds fancy repr of target and returns it.
Source code in pytermgui/widgets/fancy_repr.py
25 26 27 28 29 30 31 32 33 34 35 36 37 | |
FileLoader
Bases: ABC
Base class for file loader objects.
These allow users to load pytermgui content from a specific filetype, with each filetype having their own loaders.
To use custom widgets with children of this class, you need to call FileLoader.register.
Source code in pytermgui/file_loaders.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |
serializer = serializer
instance-attribute
Object-specific serializer instance. In order to use a specific, already created
instance you need to pass it on FileLoader construction.
__enter__()
Starts context manager.
Source code in pytermgui/file_loaders.py
287 288 289 290 | |
__exit__(_, exception, __)
Ends context manager.
Source code in pytermgui/file_loaders.py
292 293 294 295 296 | |
__init__(serializer=None)
Initialize FileLoader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
serializer
|
Serializer | None
|
An optional |
None
|
Source code in pytermgui/file_loaders.py
274 275 276 277 278 279 280 281 282 283 284 285 | |
bind(name, method)
Binds a name to a method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the method, as referenced in the loaded files. |
required |
method
|
Callable[..., Any]
|
The callable to bind. |
required |
Source code in pytermgui/file_loaders.py
307 308 309 310 311 312 313 314 315 316 | |
load(data)
Loads data from a string or a file.
When an IO object is passed, its data is extracted as a string.
This string can then be passed to load_str.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | IO
|
Either a string or file stream to load data from. |
required |
Returns:
| Type | Description |
|---|---|
WidgetNamespace
|
A WidgetNamespace with the data loaded. |
Source code in pytermgui/file_loaders.py
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |
load_str(data)
Creates a WidgetNamespace from string data.
To parse the data, we use FileLoader.parse. To implement custom formats,
subclass FileLoader with your own parse implementation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str
|
The data to parse. |
required |
Returns:
| Type | Description |
|---|---|
WidgetNamespace
|
A WidgetNamespace created from the provided data. |
Source code in pytermgui/file_loaders.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 | |
parse(data)
abstractmethod
Parses string into a dictionary used by pytermgui.serializer.Serializer.
This dictionary follows the structure defined above.
Source code in pytermgui/file_loaders.py
267 268 269 270 271 272 | |
register(cls)
Registers a widget to the serializer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls
|
Type[Widget]
|
The widget type to register. |
required |
Source code in pytermgui/file_loaders.py
298 299 300 301 302 303 304 305 | |
FloatAnimation
dataclass
Bases: Animation
Transitions a floating point number from 0.0 to 1.0.
Note that this is just a wrapper over the base class, and provides no extra functionality.
Source code in pytermgui/animations.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
Frame
An object that wraps a frame around its parent.
It can be used by any widget in order to draw a 'box' around itself. It implements scrolling as well.
Source code in pytermgui/widgets/frames.py
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 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 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
bottom_size
cached
property
Returns the height of the bottom border.
left_size
cached
property
Returns the length of the left border character.
right_size
cached
property
Returns the length of the right border character.
top_size
cached
property
Returns the height of the top border.
__call__(lines)
Frames the given lines, handles scrolling when necessary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lines
|
list[str]
|
A list of lines to 'frame'. If there are too many
lines, they are clipped according to the parent's
|
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
Framed lines, clipped to the current scrolling settings. |
Source code in pytermgui/widgets/frames.py
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 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
__init__(parent)
Initializes Frame.
Source code in pytermgui/widgets/frames.py
47 48 49 50 51 52 53 54 | |
from_name(name)
staticmethod
Gets a builtin Frame type from its name.
Source code in pytermgui/widgets/frames.py
122 123 124 125 126 127 128 129 | |
Frameless
Bases: Frame
A frame that is not. No frame will be drawn around the object.
Preview:
x
Source code in pytermgui/widgets/frames.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | |
HEXColor
dataclass
Bases: RGBColor
An arbitrary, CSS-like HEX color.
Source code in pytermgui/colors.py
786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 | |
__post_init__()
Ensures data validity.
Source code in pytermgui/colors.py
792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 | |
HLinkToken
dataclass
Bases: Token
A terminal hyperlink.
See https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda.
Source code in pytermgui/markup/tokens.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | |
Heavy
Bases: Frame
A frame with a heavy outline.
Preview:
┏━━━┓
┃ x ┃
┗━━━┛
Source code in pytermgui/widgets/frames.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | |
Highlighter
Bases: Protocol
The protocol for highlighters.
Source code in pytermgui/highlighters.py
26 27 28 29 30 31 32 33 34 35 36 | |
__call__(text, cache=True)
Highlights the given text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to highlight. |
required |
cache
|
bool
|
If set (default), results will be stored, keyed by their respective inputs, and retrieved the next time the same key is given. |
True
|
Source code in pytermgui/highlighters.py
29 30 31 32 33 34 35 36 | |
HighlighterStyle
dataclass
A style that highlights the items given to it.
See pytermgui.highlighters for more information.
Source code in pytermgui/widgets/styles.py
121 122 123 124 125 126 127 128 129 130 131 132 133 | |
__call__(_, item)
Highlights the given string.
Source code in pytermgui/widgets/styles.py
130 131 132 133 | |
HorizontalAlignment
Bases: DefaultEnum
Policies to align widgets by.
These are applied by the parent object, and are relative to them.
Source code in pytermgui/enums.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
CENTER = 1
class-attribute
instance-attribute
Center widget in the available width.
LEFT = 0
class-attribute
instance-attribute
Align widget to the left edge.
RIGHT = 2
class-attribute
instance-attribute
Align widget to the right edge.
IndexedColor
dataclass
Bases: Color
A color representing an index into the xterm-256 color palette.
Source code in pytermgui/colors.py
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 | |
rgb
cached
property
Returns an RGB representation of this color.
sequence
property
Returns an ANSI sequence representing this color.
__fancy_repr__()
Yields a fancy looking string.
Source code in pytermgui/colors.py
540 541 542 543 544 545 546 547 | |
__post_init__()
Ensures data validity.
Source code in pytermgui/colors.py
527 528 529 530 531 532 533 534 535 536 537 538 | |
from_rgb(rgb)
classmethod
Constructs an IndexedColor from the closest matching option.
Source code in pytermgui/colors.py
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 | |
InputField
Bases: Widget
An element to display user input
Source code in pytermgui/widgets/input_field.py
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 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 183 184 185 186 187 188 189 190 191 192 193 194 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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 | |
selectables_length
property
Get length of selectables in object
selection
property
Returns the currently selected span of text.
value
property
Returns the internal value of this field.
__init__(value='', *, prompt='', tablength=4, multiline=False, cursor=None, **attrs)
Initialize object
Source code in pytermgui/widgets/input_field.py
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 | |
delete_back(count=1)
Deletes count characters from the cursor, backwards.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
count
|
int
|
How many characters should be deleted. |
1
|
Returns:
| Type | Description |
|---|---|
str
|
The deleted string. |
Source code in pytermgui/widgets/input_field.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
get_lines()
Builds the input field's lines.
Source code in pytermgui/widgets/input_field.py
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 | |
get_word_pos(direction)
Gets the column offset to the next word in the given direction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
direction
|
Literal[-1, 1]
|
Which direction we need to look for. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The column offset. |
Source code in pytermgui/widgets/input_field.py
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 | |
handle_action(action)
Handles some action.
This will be expanded in the future to allow using all behaviours with just their actions.
Source code in pytermgui/widgets/input_field.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
handle_key(key)
Adds text to the field, or moves the cursor.
Source code in pytermgui/widgets/input_field.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | |
handle_mouse(event)
Allows point-and-click selection.
Source code in pytermgui/widgets/input_field.py
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | |
insert_text(text)
Inserts text at the cursor location.
Source code in pytermgui/widgets/input_field.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
move_cursor(new, *, absolute=False)
Moves the cursor, then possible re-positions it to a valid location.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new
|
tuple[int, int]
|
The new set of (y, x) positions to use. |
required |
absolute
|
bool
|
If set, |
False
|
Source code in pytermgui/widgets/input_field.py
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 | |
update_selection(count, correct_zero_length=True)
Updates the selection state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
count
|
int
|
How many characters the cursor should change by. Negative for selecting leftward, positive for right. |
required |
correct_zero_length
|
bool
|
If set, when the selection length is 0 both the cursor and the selection length are manipulated to keep the original selection start while moving the selection in more of the way the user might expect. |
True
|
Source code in pytermgui/widgets/input_field.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
Inspector
Bases: Container
A widget to inspect any Python object.
Source code in pytermgui/inspector.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 | |
__init__(target=None, show_private=False, show_dunder=False, show_methods=False, show_full_doc=False, show_qualname=True, show_header=True, **attrs)
Initializes an inspector.
Note that most of the time, using inspect to do this is going to be more
useful.
Some styles of the inspector can be changed using the code.name,
code.file and code.keyword markup aliases. The rest of the
highlighting is done using pprint, with all of its respective colors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
show_private
|
bool
|
Whether |
False
|
show_dunder
|
bool
|
Whether |
False
|
show_methods
|
bool
|
Whether methods should be shown when encountering a class. |
False
|
show_full_doc
|
bool
|
If not set, docstrings are cut to only include their first line. |
False
|
show_qualname
|
bool
|
Show fully-qualified name, e.g. |
True
|
show_header
|
bool
|
If not set, the header containing the path to the object and its qualname will not be added. |
True
|
Source code in pytermgui/inspector.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 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 | |
debug()
Returns identifiable information used in repr.
Source code in pytermgui/inspector.py
474 475 476 477 478 479 480 | |
highlight(text)
staticmethod
Applies highlighting to a given string.
This highlight includes keywords, builtin types and more.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The string to highlight. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Unparsed markup. |
Source code in pytermgui/inspector.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 | |
inspect(target)
Inspects a given object, and sets self.target to it.
Returns:
| Type | Description |
|---|---|
Inspector
|
Self, with the new content based on the inspection. |
Source code in pytermgui/inspector.py
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 | |
JsonLoader
Bases: FileLoader
JSON specific loader subclass.
Source code in pytermgui/file_loaders.py
393 394 395 396 397 398 399 400 401 402 403 404 405 406 | |
parse(data)
Parse JSON str.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str
|
JSON formatted string. |
required |
Returns:
| Type | Description |
|---|---|
dict[Any, Any]
|
Loadable dictionary. |
Source code in pytermgui/file_loaders.py
396 397 398 399 400 401 402 403 404 405 406 | |
KeyboardButton
Bases: Button
A button with keyboard mnemonics in mind.
Shoutout to the HackerNews thread where this was originally suggested
https://news.ycombinator.com/item?id=30517299#30533444
Source code in pytermgui/widgets/keyboard_button.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 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 | |
__init__(label, onclick, index=0, bound=None)
Initializes a KeyboardButton.
For example, KeyboardButton("Help") will look like: "[ (H)elp ]", and
KeyboardButton("Test", index=1) will give "[ T(e)st ]"
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the button. |
required |
onclick
|
Callable[[Button], Any]
|
The callback to be executed when the button is activated. |
required |
index
|
int
|
The index of the label to use as the binding character. |
0
|
bound
|
str | None
|
The keybind that activates this button. Defaults to |
None
|
Source code in pytermgui/widgets/keyboard_button.py
22 23 24 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 | |
Keys
Class for easy access to key-codes.
The keys for CTRL_{ascii_letter}-s can be generated with the following code:
for i, letter in enumerate(ascii_lowercase):
key = f"CTRL_{letter.upper()}"
code = chr(i+1).encode('unicode_escape').decode('utf-8')
print(key, code)
Source code in pytermgui/input.py
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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
__getattr__(attr)
Gets attr from self._keys.
Source code in pytermgui/input.py
277 278 279 280 281 282 283 | |
__init__(platform_keys, platform)
Initialize Keys object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
platform_keys
|
dict[str, str]
|
A dictionary of platform-specific keys. |
required |
platform
|
str
|
The platform the program is running on. |
required |
Source code in pytermgui/input.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
get_name(key, default=None)
Gets canonical name of a key code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key to get the name of. |
required |
default
|
Optional[str]
|
The return value to substitute if no canonical name could be found. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The canonical name if one can be found, default otherwise. |
Source code in pytermgui/input.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |
items()
Returns items() of self._keys.
Source code in pytermgui/input.py
313 314 315 316 | |
keys()
Returns keys() of self._keys.
Source code in pytermgui/input.py
308 309 310 311 | |
values()
Returns values() of self._keys.
Source code in pytermgui/input.py
303 304 305 306 | |
Label
Bases: Widget
A Widget to display a string
By default, this widget uses pytermgui.widgets.styles.MARKUP. This
allows it to house markup text that is parsed before display, such as:
print("hello world")
import pytermgui as ptg
with ptg.alt_buffer():
root = ptg.Container(
ptg.Label("[italic 141 bold]This is some [green]fancy [white inverse]text!")
)
root.print()
ptg.getch()
Source code in pytermgui/widgets/base.py
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 | |
__init__(value='', style='', padding=0, non_first_padding=0, **attrs)
Initializes a Label.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The value of this string. Using the default value style
( |
''
|
style
|
str | StyleValue
|
A pre-set value for self.styles.value. |
''
|
padding
|
int
|
The number of space (" ") characters to prepend to every line after line breaking. |
0
|
non_first_padding
|
int
|
The number of space characters to prepend to every
non-first line of |
0
|
Source code in pytermgui/widgets/base.py
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 | |
get_lines()
Get lines representing this Label, breaking lines as necessary
Source code in pytermgui/widgets/base.py
774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 | |
Layout
Defines a layout of Widgets, used by WindowManager.
Internally, it keeps track of a list of Slot. This list is then turned into a list
of rows, all containing slots. This is done either when the current row has run out
of the terminal's width, or ROW_BREAK is encountered.
Source code in pytermgui/window_manager/layouts.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | |
terminal
property
Returns the current global terminal instance.
__getattr__(attr)
Gets a slot by its (slugified) name.
Source code in pytermgui/window_manager/layouts.py
382 383 384 385 386 387 388 389 390 391 392 | |
__len__()
Gets the slot count of this layout.
Source code in pytermgui/window_manager/layouts.py
191 192 193 194 | |
add_break(*, index=-1)
Adds ROW_BREAK to the given index.
This special slot is ignored for all intents and purposes, other than when breaking the slots into rows. In that context, when encountered, the current row is deemed completed, and the next slot will go into a new row list.
Source code in pytermgui/window_manager/layouts.py
338 339 340 341 342 343 344 345 346 | |
add_slot(name='Slot', *, slot=None, width=None, height=None, index=-1)
Adds a new slot to the layout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The snakeified name of the slot. A non-snake case name will cause issues when trying to retrieve the slot (see GH#147). |
'Slot'
|
slot
|
Slot | None
|
An already instantiated |
None
|
width
|
Dimension | int | float | None
|
The width for the new slot. See below for special types. |
None
|
height
|
Dimension | int | float | None
|
The height for the new slot. See below for special types. |
None
|
index
|
int
|
The index to add the new slot to. |
-1
|
Returns:
| Type | Description |
|---|---|
Slot
|
The just-added slot. |
When defining dimensions, either width or height, some special value
types can be given:
- Dimension: Passed directly to the new slot.
- None: An Auto dimension is created with no value.
- int: A Static dimension is created with the given value.
- float: A Relative dimension is created with the given value as its
scale. Its bound attribute will default to the relevant part of the
terminal's size.
Source code in pytermgui/window_manager/layouts.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | |
apply()
Applies the layout to each slot.
Source code in pytermgui/window_manager/layouts.py
368 369 370 371 372 373 374 375 376 377 378 379 380 | |
assign(widget, *, index=-1, apply=True)
Assigns a widget to the slot at the specified index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
widget
|
Widget
|
The widget to assign. |
required |
index
|
int
|
The target slot's index. |
-1
|
apply
|
bool
|
If set, |
True
|
Source code in pytermgui/window_manager/layouts.py
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | |
build_rows()
Builds a list of slot rows, breaking them & applying automatic dimensions.
Returns:
| Type | Description |
|---|---|
list[list[Slot]]
|
A list[list[Slot]], aka. a list of slot-rows. |
Source code in pytermgui/window_manager/layouts.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | |
Light
Bases: Frame
A frame with a light outline.
Preview:
┌───┐
│ x │
└───┘
Source code in pytermgui/widgets/frames.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
LineLengthError
Bases: Exception
Raised when a widget line is not the expected length.
Source code in pytermgui/exceptions.py
25 26 | |
MacroToken
dataclass
Bases: Token
A binding of a Python function to a markup name.
See the docs on information about syntax & semantics.
Source code in pytermgui/markup/tokens.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
MarkupFormatter
dataclass
A style that formats depth & item into the given markup on call.
Useful in Widget styles, such as:
import pytermgui as ptg
root = ptg.Container()
# Set border style to be reactive to the widget's depth
root.set_style("border", ptg.MarkupFactory("[35 @{depth}]{item}]")
Source code in pytermgui/widgets/styles.py
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 | |
__call__(depth, item)
StyleType: Format depth & item into given markup template
Source code in pytermgui/widgets/styles.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
__str__()
Returns repr, but with markup escaped.
Source code in pytermgui/widgets/styles.py
115 116 117 118 | |
MarkupLanguage
A relatively simple object that binds context to TIM parsing functions.
Most of the job this class has is to pass along a ContextDict to various
"lower level" functions, in order to maintain a sort of state. It also exposes
ways to modify this state, namely the alias and define methods.
Source code in pytermgui/markup/language.py
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 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 183 184 185 186 187 188 189 190 191 192 193 194 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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
aliases
property
Returns a copy of the aliases defined in context.
macros
property
Returns a copy of the macros defined in context.
alias(name, value, *, generate_unsetter=True)
Creates an alias from one custom name to a set of styles.
These can be used to store and reference a set of tags using only one name.
Aliases may reference other aliases, but only do this consciously, as it can become a hard to follow trail of sorrow very quickly!
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name this alias will be referenced by. |
required |
value
|
str
|
The markup value that the alias will represent. |
required |
generate_unsetter
|
bool
|
Disable generating clearer aliases. For example: will generate: |
True
|
Source code in pytermgui/markup/language.py
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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
alias_multiple(*, generate_unsetter=True, **items)
Runs MarkupLanguage.alias repeatedly for all arguments.
The same generate_unsetter value will be used for all calls.
You can use this in two forms:
-
Traditional keyword arguments:
lang.alias_multiple(my-tag1="bold", my-tag2="italic") -
Keyword argument unpacking:
my_aliases = {"my-tag1": "bold", "my-tag2": "italic"} lang.alias_multiple(**my_aliases)
Source code in pytermgui/markup/language.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
clear_cache()
Clears the internal cache.
Use this after re-defining aliases.
Source code in pytermgui/markup/language.py
93 94 95 96 97 98 99 | |
define(name, method)
Defines a markup macro.
Macros are essentially function bindings callable within markup. They can be very useful to represent changing data and simplify TIM code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name that will be used within TIM to call the macro. Must start with
a bang ( |
required |
method
|
MacroType
|
The function bound to the name given above. This function will take any number of strings as arguments, and return a terminal-ready (i.e. parsed) string. |
required |
Source code in pytermgui/markup/language.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
get_markup(text)
staticmethod
DEPRECATED: Convert ANSI text into markup.
This function does not use context, and thus is out of place here.
Source code in pytermgui/markup/language.py
257 258 259 260 261 262 263 264 | |
group_styles(text, tokenizer=tokenize_ansi)
Generate StyledText-s from some text, using our context.
See StyledText.group_styles for arguments.
Source code in pytermgui/markup/language.py
266 267 268 269 270 271 272 273 274 275 276 | |
parse(text, optimize=False, append_reset=True)
Parses some markup text.
This is a thin wrapper around markup.parsing.parse. The main additions of this wrapper are a caching system, as well as state management.
Ignoring caching, all calls to this function would be equivalent to:
def parse(self, *args, **kwargs) -> str:
kwargs["context"] = self.context
return parse(*args, **kwargs)
Source code in pytermgui/markup/language.py
194 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 244 245 246 247 248 249 250 251 252 253 254 | |
print(*args, **kwargs)
Parse all arguments and pass them through to print, along with kwargs.
Source code in pytermgui/markup/language.py
278 279 280 281 282 283 284 285 | |
MarkupSyntaxError
dataclass
Bases: ParserSyntaxError
Raised when parsed markup text contains an error.
Source code in pytermgui/exceptions.py
84 85 86 87 | |
MouseAction
Bases: Enum
An enumeration of all the polled mouse actions
Source code in pytermgui/ansi_interface.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 | |
HOVER = 'hover'
class-attribute
instance-attribute
Mouse moved without clicking.
LEFT_CLICK = 'left_click'
class-attribute
instance-attribute
Start of a left button action sequence.
LEFT_DRAG = 'left_drag'
class-attribute
instance-attribute
Mouse moved while left button was held down.
RELEASE = 'release'
class-attribute
instance-attribute
Mouse button released; end of any and all mouse action sequences.
RIGHT_CLICK = 'right_click'
class-attribute
instance-attribute
Start of a right button action sequence.
RIGHT_DRAG = 'right_drag'
class-attribute
instance-attribute
Mouse moved while right button was held down.
SCROLL_DOWN = 'scroll_down'
class-attribute
instance-attribute
Mouse wheel or touchpad scroll downwards.
SCROLL_UP = 'scroll_up'
class-attribute
instance-attribute
Mouse wheel or touchpad scroll upwards.
SHIFT_SCROLL_DOWN = 'shift_scroll_down'
class-attribute
instance-attribute
Mouse wheel or touchpad scroll downwards.
SHIFT_SCROLL_UP = 'shift_scroll_up'
class-attribute
instance-attribute
Mouse wheel or touchpad scroll upwards.
MouseEvent
dataclass
A class to represent events created by mouse actions.
Its first argument is a MouseAction describing what happened,
and its second argument is a tuple[int, int] describing where
it happened.
This class mostly exists for readability & typing reasons. It also implements the iterable protocol, so you can use the unpacking syntax, such as:
action, position = MouseEvent(...)
Source code in pytermgui/ansi_interface.py
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 | |
__iter__()
Start iteration
Source code in pytermgui/ansi_interface.py
450 451 452 453 | |
__next__()
Get next iteration item
Source code in pytermgui/ansi_interface.py
438 439 440 441 442 443 444 445 446 447 448 | |
__post_init__()
Initialize iteration counter
Source code in pytermgui/ansi_interface.py
433 434 435 436 | |
is_primary()
Returns True if event.action is one of the primary (left-button) actions.
Source code in pytermgui/ansi_interface.py
460 461 462 463 | |
is_scroll()
Returns True if event.action is one of the scrolling actions.
Source code in pytermgui/ansi_interface.py
455 456 457 458 | |
is_secondary()
Returns True if event.action is one of the secondary (secondary-button) actions.
Source code in pytermgui/ansi_interface.py
465 466 467 468 | |
Overflow
Bases: DefaultEnum
Overflow policies implemented by Container.
Source code in pytermgui/enums.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
AUTO = 9999
class-attribute
instance-attribute
NotImplemented
HIDE = 0
class-attribute
instance-attribute
Stop gathering lines once there is no room left.
RESIZE = 2
class-attribute
instance-attribute
Resize parent to fit with the new lines.
Note
When applied to a window, this prevents resizing its height using the bottom border.
SCROLL = 1
class-attribute
instance-attribute
Allow scrolling when there is too many lines.
Padded
Bases: Frame
A frame that pads its content by a single space on all sides.
Preview:
x
Source code in pytermgui/widgets/frames.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
Palette
dataclass
A harmonious color palette.
Running Palette.alias on a generated palette will create the following color
aliases:
Main colors
These are the colors used by the majority of the application. Primary should make up around 50% percent of an average screen's colors, while secondary and tertiary should use the remaining 50% together (25% each).
Accents should be used sparingly to highlight specific details.
Items: primary, secondary, tertiary, accent
Semantic colors
These colors are all meant to convey some meaning. They shouldn't be used in situation where that meaning, e.g. success, isn't clearly related. When not given as an argument, they are generated by blending some default green, yellow and red with the primary color.
Items: success, warning, error
Neutral colors
These are colors meant to be used as a background to the main group. All of them
are a blend of a default background color and one of the main colors: surface
is generated from primary, surface2 comes from secondary and so on.
Items: surface, surface2, surface3, surface4
Source code in pytermgui/palettes.py
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 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 183 184 185 186 187 188 189 190 191 192 193 194 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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 | |
__fancy_repr__()
Shows off the palette in a compact form.
Source code in pytermgui/palettes.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | |
__init__(*, primary, secondary=None, tertiary=None, accent=None, success=None, warning=None, error=None, surface=None, surface2=None, surface3=None, strategy=triadic)
Generates a color palette from the given primary color.
If any other color arguments are passed, they will be parsed as a color and used as-is. Otherwise, they will be derived from the primary.
See the class documentation for info on all arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strategy
|
PaletteGeneratorStrategy
|
A strategy that will be used to derive colors. |
triadic
|
Source code in pytermgui/palettes.py
130 131 132 133 134 135 136 137 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 | |
alias(lang=tim)
Sets up aliases for the given language.
Note that no unsetters will be generated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lang
|
MarkupLanguage
|
The language to run |
tim
|
Source code in pytermgui/palettes.py
295 296 297 298 299 300 301 302 303 304 305 | |
base_keys()
Returns the non-background, non-shade alias keys.
Source code in pytermgui/palettes.py
286 287 288 289 290 291 292 293 | |
print()
Shows off the palette in an extended form.
Source code in pytermgui/palettes.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 | |
regenerate(**kwargs)
Generates a new palette and replaces self.data with its data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
All key word args passed to the new Palette. See |
{}
|
Returns:
| Type | Description |
|---|---|
Palette
|
This palette, after regeneration. |
Source code in pytermgui/palettes.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
PixelMatrix
Bases: Widget
A matrix of pixels.
The way this object should be used is by accessing & modifying the underlying matrix. This can be done using the set & getitem syntacies:
from pytermgui import PixelMatrix
matrix = PixelMatrix(10, 10, default="white")
for y in matrix.rows:
for x in matrix.columns:
matrix[y, x] = "black"
The above snippet draws a black diagonal going from the top left to bottom right.
Each item of the rows should be a single PyTermGUI-parsable color
string. For more information about this, see
pytermgui.ansi_interface.Color.
Source code in pytermgui/widgets/pixel_matrix.py
19 20 21 22 23 24 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 146 147 148 149 150 151 | |
selected_pixel = None
instance-attribute
A tuple of the position & value (color) of the currently hovered pixel.
__getitem__(indices)
Gets a matrix item.
Source code in pytermgui/widgets/pixel_matrix.py
141 142 143 144 145 | |
__init__(width, height, default='background', **attrs)
Initializes a PixelMatrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
int
|
The amount of columns the matrix will have. |
required |
height
|
int
|
The amount of rows the matrix will have. |
required |
default
|
str
|
The default color to use to initialize the matrix with. |
'background'
|
Source code in pytermgui/widgets/pixel_matrix.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
__setitem__(indices, value)
Sets a matrix item.
Source code in pytermgui/widgets/pixel_matrix.py
147 148 149 150 151 | |
build()
Builds the image pixels.
Returns:
| Type | Description |
|---|---|
list[str]
|
The lines that this object will return, until a subsequent |
list[str]
|
These lines are stored in the |
Source code in pytermgui/widgets/pixel_matrix.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
from_matrix(matrix)
classmethod
Creates a PixelMatrix from the given matrix.
The given matrix should be a list of rows, each containing a number of cells. It is optimal for all rows to share the same amount of cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
list[list[str]]
|
The matrix to use. This is a list of lists of strings with each element representing a PyTermGUI-parseable color. |
required |
Returns:
| Type | Description |
|---|---|
PixelMatrix
|
A new type(self). |
Source code in pytermgui/widgets/pixel_matrix.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
get_lines()
Returns lines built by the build method.
Source code in pytermgui/widgets/pixel_matrix.py
112 113 114 115 | |
on_hover(event)
Sets selected_pixel to the current pixel.
Source code in pytermgui/widgets/pixel_matrix.py
101 102 103 104 105 106 107 108 109 110 | |
PlainToken
dataclass
Bases: Token
A plain piece of text.
These are the parts of data in-between markup tag groups.
Source code in pytermgui/markup/tokens.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
PseudoToken
dataclass
Bases: Token
A token that can modify it's context, but doesn't hold information of its own.
Source code in pytermgui/markup/tokens.py
136 137 138 139 140 141 142 143 144 | |
RGBColor
dataclass
Bases: Color
An arbitrary RGB color.
Source code in pytermgui/colors.py
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 | |
blue
property
Returns the blue component of this color.
green
property
Returns the green component of this color.
red
property
Returns the red component of this color.
sequence
property
Returns the ANSI sequence representing this color.
__fancy_repr__()
Yields a fancy looking string.
Source code in pytermgui/colors.py
737 738 739 740 741 742 743 744 745 746 747 | |
__post_init__()
Ensures data validity.
Source code in pytermgui/colors.py
725 726 727 728 729 730 731 732 733 734 735 | |
from_rgb(rgb)
classmethod
Returns an RGBColor from the given triplet.
Source code in pytermgui/colors.py
749 750 751 752 753 | |
Recorder
A class that records & exports terminal content.
Source code in pytermgui/term.py
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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
__init__()
Initializes the Recorder.
Source code in pytermgui/term.py
40 41 42 43 44 | |
export_html(prefix=None, inline_styles=False)
Exports current content as HTML.
For help on the arguments, see pytermgui.html.to_html.
Source code in pytermgui/term.py
62 63 64 65 66 67 68 69 70 71 72 | |
export_svg(prefix=None, inline_styles=False, title='PyTermGUI', chrome=True)
Exports current content as SVG.
For help on the arguments, see pytermgui.html.to_svg.
Source code in pytermgui/term.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
export_text()
Exports current content as plain text.
Source code in pytermgui/term.py
57 58 59 60 | |
save_html(filename=None, prefix=None, inline_styles=False)
Exports HTML content to the given file.
For help on the arguments, see pytermgui.exporters.to_html.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str | None
|
The file to save to. If the filename does not contain the '.html' extension it will be appended to the end. |
None
|
Source code in pytermgui/term.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
save_plain(filename)
Exports plain text content to the given file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The file to save to. |
required |
Source code in pytermgui/term.py
96 97 98 99 100 101 102 103 104 | |
save_svg(filename=None, prefix=None, chrome=True, inline_styles=False, title='PyTermGUI')
Exports SVG content to the given file.
For help on the arguments, see pytermgui.exporters.to_svg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str | None
|
The file to save to. If the filename does not contain the '.svg' extension it will be appended to the end. |
None
|
Source code in pytermgui/term.py
130 131 132 133 134 135 136 137 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 | |
write(data)
Writes to the recorder.
Source code in pytermgui/term.py
52 53 54 55 | |
RegexHighlighter
dataclass
A class to highlight strings using regular expressions.
This class must be provided with a list of styles. These styles are really just a
tuple of the markup alias name, and their associated RE patterns. If all aliases
in the instance use the same prefix, it can be given under the prefix key and
ommitted from the style names.
On construction, the instance will combine all of its patterns into a monster regex including named capturing groups. The general format is something like:
(?P<{name1}>{pattern1})|(?P<{name2}>{pattern2})|...
Calling this instance will then replace all matches, going in the order of definition, with style-injected versions. These follow the format:
[{prefix?}{name}]{content}[/{prefix}{name}]
Oddities to keep in mind: - Regex replace goes in the order of the defined groups, and is non-overlapping. Two groups cannot match the same text. - Because of how capturing groups work, everything within the patterns will be matched. To look for context around a match, look-around assertions can be used.
Source code in pytermgui/highlighters.py
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 146 147 | |
match_formatter = None
class-attribute
instance-attribute
A callable of (match, content) that gets called on every match.
Its return value will be used as the content that the already set highlighting will apply to. Useful to trim text, or apply other transformations before inserting it back.
pre_formatter = None
class-attribute
instance-attribute
A callable that formats the input string, before any highlighting is done to it.
prefix = ''
class-attribute
instance-attribute
Some string to insert before each style alias.
re_flags = 0
class-attribute
instance-attribute
All regex flags to apply when compiling the generated pattern, OR-d (|) together.
styles
instance-attribute
A list of tuples of (style_alias, pattern_str).
__call__(text, cache=True)
Highlights the given text, using the combined regex pattern.
Source code in pytermgui/highlighters.py
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 | |
__fancy_repr__()
Yields some fancy looking repr text.
Source code in pytermgui/highlighters.py
135 136 137 138 139 140 141 142 143 144 145 146 147 | |
__post_init__()
Combines all styles into one pattern.
Source code in pytermgui/highlighters.py
87 88 89 90 91 92 93 94 95 96 97 98 | |
Rounded
Bases: Frame
A frame with a light outline and rounded corners.
Preview:
╭───╮
│ x │
╰───╯
Source code in pytermgui/widgets/frames.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | |
ScrollableWidget
Bases: Widget
A widget with some scrolling helper methods.
This is not an implementation of the scrolling behaviour itself, just the user-facing API for it.
It provides a _scroll_offset attribute, which is an integer describing the current
scroll state offset from the top, as well as some methods to modify the state.
Source code in pytermgui/widgets/base.py
795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 | |
__init__(**attrs)
Initializes the scrollable widget.
Source code in pytermgui/widgets/base.py
804 805 806 807 808 809 810 | |
scroll(offset)
Scrolls to given offset, returns the new scroll_offset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
offset
|
int
|
The amount to scroll by. Positive offsets scroll down, negative up. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the scroll offset changed, False otherwise. |
Source code in pytermgui/widgets/base.py
812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 | |
scroll_end(end)
Scrolls to either top or bottom end of this object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
end
|
int
|
The offset to scroll to. 0 goes to the very top, -1 to the very bottom. |
required |
Returns:
| Type | Description |
|---|---|
int
|
True if the scroll offset changed, False otherwise. |
Source code in pytermgui/widgets/base.py
831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 | |
Serializer
A class to facilitate loading & dumping widgets.
By default it is only aware of pytermgui objects, however
if needed it can be made aware of custom widgets using
Serializer.register.
It can dump any widget type, but can only load ones it knows.
All styles (except for char styles) are converted to markup
during the dump process. This is done to make the end-result
more readable, as well as more universally usable. As a result,
all widgets use markup_style for their affected styles.
Source code in pytermgui/serialization.py
22 23 24 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 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 183 184 185 186 187 188 189 190 191 192 193 194 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 | |
__init__()
Sets up known widgets.
Source code in pytermgui/serialization.py
36 37 38 39 40 41 42 43 | |
bind(name, method)
Binds a name to a method.
These method callables are substituted into all fields that follow
the method:<method_name> syntax. If method_name is not bound,
an exception will be raised during loading.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the method, as referenced in the loaded files. |
required |
method
|
Callable[..., Any]
|
The callable to bind. |
required |
Source code in pytermgui/serialization.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
dump_to_dict(obj)
staticmethod
Dump widget to a dict.
This is an alias for obj.serialize.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Widget
|
The widget to dump. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
|
Source code in pytermgui/serialization.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
from_dict(data, widget_type=None)
Loads a widget from a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any]
|
The data to load from. |
required |
widget_type
|
str | None
|
Substitute for when data has no |
None
|
Returns:
| Type | Description |
|---|---|
Widget
|
A widget from the given data. |
Source code in pytermgui/serialization.py
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 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 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
from_file(file)
Loads widget from a file object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
IO[str]
|
An IO object. |
required |
Returns:
| Type | Description |
|---|---|
Widget
|
The loaded widget. |
Source code in pytermgui/serialization.py
198 199 200 201 202 203 204 205 206 207 208 | |
get_widgets()
staticmethod
Gets all widgets from the module.
Source code in pytermgui/serialization.py
45 46 47 48 49 50 51 52 53 54 55 56 57 | |
register(cls)
Makes object aware of a custom widget class, so it can be serialized.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls
|
Type[Widget]
|
The widget type to register. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
The object is not a type. |
Source code in pytermgui/serialization.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
register_box(name, box)
Registers a new Box type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the box. |
required |
box
|
Box
|
The box instance. |
required |
Source code in pytermgui/serialization.py
74 75 76 77 78 79 80 81 82 | |
to_file(obj, file, **json_args)
Dumps widget to a file object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Widget
|
The widget to dump. |
required |
file
|
IO[str]
|
The file object it gets written to. |
required |
**json_args
|
dict[str, Any]
|
Arguments passed to |
{}
|
Source code in pytermgui/serialization.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
SizePolicy
Bases: DefaultEnum
Values according to which Widget sizes are assigned.
Source code in pytermgui/enums.py
45 46 47 48 49 50 51 52 53 54 55 56 | |
FILL = 0
class-attribute
instance-attribute
Inner widget will take up as much width as possible.
RELATIVE = 2
class-attribute
instance-attribute
Inner widget will take up widget.relative_width * available space.
STATIC = 1
class-attribute
instance-attribute
Inner widget will take up an exact amount of width.
Slider
Bases: Widget
A Widget to display & configure scalable data.
By default, this Widget will act like a slider you might find in a
settings page, allowing percentage-based selection of magnitude.
Using WindowManager it can even be dragged around by the user using
the mouse.
Source code in pytermgui/widgets/slider.py
18 19 20 21 22 23 24 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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
locked
instance-attribute
Disallow mouse input, hide cursor and lock current state
value
property
writable
Returns the value of this Slider.
Returns:
| Type | Description |
|---|---|
float
|
A floating point number between 0.0 and 1.0. |
__init__(onchange=None, locked=False, **attrs)
Initializes a Slider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
onchange
|
Callable[[float], Any] | None
|
The callable called every time the value is updated. |
None
|
locked
|
bool
|
Whether this Slider should accept value changes. |
False
|
Source code in pytermgui/widgets/slider.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
get_lines()
Gets slider lines.
Source code in pytermgui/widgets/slider.py
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 152 153 154 155 156 157 158 159 160 161 162 163 | |
handle_key(key)
Moves the slider cursor.
Source code in pytermgui/widgets/slider.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
handle_mouse(event)
Moves the slider cursor.
Source code in pytermgui/widgets/slider.py
106 107 108 109 110 111 112 113 114 115 116 | |
Splitter
Bases: Container
A widget that displays other widgets, stacked horizontally.
Source code in pytermgui/widgets/containers.py
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 | |
content_dimensions
property
Returns the available area for widgets.
get_lines()
Join all widgets horizontally.
Source code in pytermgui/widgets/containers.py
1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 | |
StandardColor
dataclass
Bases: IndexedColor
A color in the xterm-16 palette.
Source code in pytermgui/colors.py
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 | |
name
property
Returns the markup-compatible name for this color.
rgb
cached
property
Returns an RGB representation of this color.
sequence
property
Returns an ANSI sequence representing this color.
from_ansi(code)
classmethod
Creates a standard color from the given ANSI code.
These codes have to be a digit ranging between 31 and 47.
Source code in pytermgui/colors.py
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 | |
from_rgb(rgb)
classmethod
Creates a color with the closest-matching xterm index, based on rgb.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rgb
|
RGBTriplet
|
The target color. |
required |
Source code in pytermgui/colors.py
643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 | |
StyleCall
dataclass
A callable object that simplifies calling style methods.
Instances of this class are created within the Widget._get_style
method, and this class should not be used outside of that context.
Source code in pytermgui/widgets/styles.py
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 | |
__call__(item)
DepthlessStyleType: Apply style method to item, using depth
Source code in pytermgui/widgets/styles.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
StyleManager
Bases: UserDict
An fancy dictionary to manage a Widget's styles.
Individual styles can be accessed two ways:
manager.styles.style_name == manager._get_style("style_name")
Same with setting:
widget.styles.style_name = ...
widget.set_style("style_name", ...)
The set and get methods remain for backwards compatibility reasons, but all
newly written code should use the dot syntax.
It is also possible to set styles as markup shorthands. For example:
widget.styles.border = "60 bold"
...is equivalent to:
widget.styles.border = "[60 bold]{item}"
Source code in pytermgui/widgets/styles.py
137 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 183 184 185 186 187 188 189 190 191 192 193 194 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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 | |
__call__(**styles)
Allows calling the manager and setting its styles.
For example:
>>> Button("Hello").styles(label="@60")
Source code in pytermgui/widgets/styles.py
326 327 328 329 330 331 332 333 334 335 336 337 338 | |
__getattr__(key)
Allows styles.dot_syntax.
Source code in pytermgui/widgets/styles.py
315 316 317 318 319 320 321 322 323 324 | |
__init__(parent=None, **base)
Initializes a StyleManager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent
|
Widget | Type[Widget] | None
|
The parent of this instance. It will be assigned in all
|
None
|
Source code in pytermgui/widgets/styles.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
__setattr__(key, value)
Sets an attribute.
It first looks if it can set inside self.data, and defaults back to self.dict.
Raises:
| Type | Description |
|---|---|
KeyError
|
The given key is not a defined attribute, and is not part of this object's style set. |
Source code in pytermgui/widgets/styles.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | |
__setitem__(key, value)
Sets an item in self.data.
If the item is a string, it will be expanded into a MarkupFormatter before
being converted into the StyleCall, using expand_shorthand.
Source code in pytermgui/widgets/styles.py
280 281 282 283 284 285 286 287 | |
branch(parent)
Branch off from the base style dictionary.
This method should be called during widget construction. It creates a new
StyleManager based on self, but with its data detached from the original.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent
|
Widget | Type[Widget]
|
The parent of the new instance. |
required |
Returns:
| Type | Description |
|---|---|
StyleManager
|
A new |
StyleManager
|
modified without touching the original instance. |
Source code in pytermgui/widgets/styles.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
expand_shorthand(shorthand)
staticmethod
Expands a shorthand string into a MarkupFormatter instance.
For example, all of these will expand into MarkupFormatter([60]{item}'):
- '60'
- '[60]'
- '[60]{item}'
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shorthand
|
str
|
The short version of markup to expand. |
required |
Returns:
| Type | Description |
|---|---|
MarkupFormatter
|
A |
Source code in pytermgui/widgets/styles.py
193 194 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 | |
merge(other, **styles)
classmethod
Creates a new manager that merges other with the passed in styles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
StyleManager
|
The style manager to base the new one from. |
required |
**styles
|
str
|
The additional styles the new instance should have. |
{}
|
Returns:
| Type | Description |
|---|---|
StyleManager
|
A new |
StyleManager
|
|
StyleManager
|
data between the |
StyleManager
|
reflected. |
Source code in pytermgui/widgets/styles.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
StyleToken
dataclass
Bases: Token
A terminal-style identifier.
Most terminals support a set of 9 styles:
- bold
- dim
- italic
- underline
- blink
- blink2
- inverse
- invisible
- strikethrough
This token will store the style it represents by its name in the value field. Note
that other, less widely supported styles may be available; for an up-to-date list,
run ptg -i pytermgui.markup.style_maps.STYLES.
```
Source code in pytermgui/markup/tokens.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
StyledText
dataclass
An ANSI style-infused string.
This is a sort of helper to handle ANSI texts in a more semantic manner. It keeps track of a sequence and a plain part.
Calling len() will return the length of the printable, non-ANSI part, and
indexing will return the characters at the given slice, but also include the
sequences that are applied to them.
To generate StyledText-s, it is recommended to use the StyledText.group_styles
classmethod.
Source code in pytermgui/markup/language.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 | |
background
cached
property
Returns the background color of this object.
blink
cached
property
Returns this text is blinking.
blink2
cached
property
Returns this text is alternate-blinking.
bold
cached
property
Returns this text is bold.
dim
cached
property
Returns this text is dimmed.
foreground
cached
property
Returns the foreground color of this object.
inverse
cached
property
Returns this text has its colors inversed.
italic
cached
property
Returns this text is italicized.
overline
cached
property
Returns this text is overlined.
strikethrough
cached
property
Returns this text is striked out.
underline
cached
property
Returns this text is underlined.
first_of(text)
classmethod
Returns the first element of cls.group_styles(text).
Source code in pytermgui/markup/language.py
481 482 483 484 485 486 487 488 | |
group_styles(text, tokenizer=tokenize_ansi, context=None)
staticmethod
Yields StyledTexts from an ANSI coded string.
A new StyledText will be created each time a non-plain token follows a plain token, thus all texts will represent a single (ANSI)PLAIN group of characters.
Source code in pytermgui/markup/language.py
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 | |
SupportsFancyRepr
Bases: Protocol
An object that supports the __fancy_repr__ dunder.
Source code in pytermgui/fancy_repr.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
__fancy_repr__()
Yields some fancy text.
Each value yielded can be one of two types. If a dictionary is yielded,
it will be assumed to have text and highlight fields. text will be
the string included in the repr, and highlight will be a boolean describing
whether the part should be highlighted. At the moment highlighting is done by
highlight_python, but this might be configurable once more highlighters are
available.
If a str is yielded, it is assumed to be a shorthand for:
{"text": <your_text>, "highlight": True}
Source code in pytermgui/fancy_repr.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
Terminal
A class to store & access data about a terminal.
Source code in pytermgui/term.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 | |
RESIZE = 0
class-attribute
instance-attribute
Event sent out when the terminal has been resized.
Arguments passed: - New size: tuple[int, int]
colorsystem
property
Gets the current terminal's supported color system.
displayhook_installed = False
class-attribute
instance-attribute
This is set to True when pretty.install is called.
forced_colorsystem
property
writable
Forces a color system type on this terminal.
height
property
Gets the current height of the terminal.
margins = [0, 0, 0, 0]
class-attribute
instance-attribute
Not quite sure what this does at the moment.
origin = (1, 1)
class-attribute
instance-attribute
Origin of the internal coordinate system.
pixel_size
property
DEPRECATED: Returns the terminal's pixel resolution.
Prefer terminal.resolution.
resolution
cached
property
Returns the terminal's pixel based resolution.
Only evaluated on demand.
width
property
Gets the current width of the terminal.
__fancy_repr__()
Returns a cool looking repr.
Source code in pytermgui/term.py
296 297 298 299 300 301 | |
__init__(stream=None, *, size=None)
Initialize Terminal class.
Source code in pytermgui/term.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
clear_stream()
Clears the terminal screen.
Attempts to truncate any buffered stream data (may work on Windows), then moves cursor to home position and clears the entire screen.
Source code in pytermgui/term.py
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 | |
flush()
Flushes self._stream.
Source code in pytermgui/term.py
629 630 631 632 | |
frame()
Notifies the emulator of the inner content being a single frame.
See https://gist.github.com/christianparpart/d8a62cc1ab659194337d73e399004036!
Source code in pytermgui/term.py
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 | |
is_interactive()
staticmethod
Determines whether shell is interactive.
A shell is interactive if it is run from python3 or python3 -i.
Source code in pytermgui/term.py
396 397 398 399 400 401 402 403 | |
isatty()
staticmethod
Returns whether sys.stdin is a tty.
Source code in pytermgui/term.py
494 495 496 497 498 | |
no_record()
Pauses recording for the duration of the context.
Source code in pytermgui/term.py
455 456 457 458 459 460 461 462 463 464 465 466 | |
print(*items, pos=None, sep=' ', end='\n', flush=True)
Prints items to the stream.
All arguments not mentioned here are analogous to print.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pos
|
tuple[int, int] | None
|
Terminal-character space position to write the data to, (x, y). |
None
|
Source code in pytermgui/term.py
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 | |
process_pending_resize()
Process pending resize event if one is queued.
Call this periodically from the main event loop.
:returns: True if a resize was processed.
Source code in pytermgui/term.py
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
record()
Records the terminal's stream.
Source code in pytermgui/term.py
441 442 443 444 445 446 447 448 449 450 451 452 453 | |
replay(recorder)
Replays a recording.
Source code in pytermgui/term.py
500 501 502 503 504 505 506 507 508 509 | |
subscribe(event, callback)
Subcribes a callback to be called when event occurs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
int
|
The terminal event that calls callback. |
required |
callback
|
Callable[..., Any]
|
The callable to be called. The signature of this callable is dependent on the event. See the documentation of the specific event for more information. |
required |
Source code in pytermgui/term.py
511 512 513 514 515 516 517 518 519 520 521 522 523 524 | |
write(data, pos=None, flush=False, slice_too_long=True)
Writes the given data to the terminal's stream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str
|
The data to write. |
required |
pos
|
tuple[int, int] | None
|
Terminal-character space position to write the data to, (x, y). |
None
|
flush
|
bool
|
If set, |
False
|
slice_too_long
|
bool
|
If set, lines that are outside of the terminal will be sliced to fit. Involves a sizable performance hit. |
True
|
Source code in pytermgui/term.py
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 | |
Toggle
Bases: Checkbox
A specialized checkbox showing either of two states
Source code in pytermgui/widgets/toggle.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
__init__(states, callback=None, **attrs)
Initialize object
Source code in pytermgui/widgets/toggle.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
Token
A piece of markup information.
All tokens must have at least a value field, and have markup and prettified_markup
properties derived from it in some manner.
They are meant to be immutable (frozen), and generated by some tokenization. They are also static representations of the data in its pre-parsed form.
Source code in pytermgui/markup/tokens.py
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 | |
markup
cached
property
Returns markup representing this token.
prettified_markup
cached
property
Returns syntax-highlighted markup representing this token.
is_alias()
Returns True if this token is an instance of AliasToken.
Source code in pytermgui/markup/tokens.py
92 93 94 95 | |
is_clear()
Returns True if this token is an instance of ClearToken.
Source code in pytermgui/markup/tokens.py
102 103 104 105 | |
is_color()
Returns True if this token is an instance of ColorToken.
Source code in pytermgui/markup/tokens.py
82 83 84 85 | |
is_cursor()
Returns True if this token is an instance of CursorToken.
Source code in pytermgui/markup/tokens.py
112 113 114 115 | |
is_hyperlink()
Returns True if this token is an instance of HLinkToken.
Source code in pytermgui/markup/tokens.py
107 108 109 110 | |
is_macro()
Returns True if this token is an instance of MacroToken.
Source code in pytermgui/markup/tokens.py
97 98 99 100 | |
is_plain()
Returns True if this token is an instance of PlainToken.
Source code in pytermgui/markup/tokens.py
72 73 74 75 | |
is_pseudo()
Returns True if this token is an instance of PseudoToken.
Source code in pytermgui/markup/tokens.py
77 78 79 80 | |
is_style()
Returns True if this token is an instance of StyleToken.
Source code in pytermgui/markup/tokens.py
87 88 89 90 | |
VerticalAlignment
Bases: DefaultEnum
Vertical alignment options for widgets.
Source code in pytermgui/enums.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
BOTTOM = 2
class-attribute
instance-attribute
Align widgets to the bottom.
CENTER = 1
class-attribute
instance-attribute
Align widgets in the center, with equal* padding on the top and bottom.
Note
When the available height is not divisible by 2, the extra line of padding is added to the bottom.
TOP = 0
class-attribute
instance-attribute
Align widgets to the top
Widget
The base of the Widget system
Source code in pytermgui/widgets/base.py
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 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 183 184 185 186 187 188 189 190 191 192 193 194 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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 | |
bindings
property
Gets a copy of the bindings internal dictionary.
Returns:
| Type | Description |
|---|---|
dict[str | Type[MouseEvent], tuple[BoundCallback, str]]
|
A copy of the internal bindings dictionary, such as: |
dict[str | Type[MouseEvent], tuple[BoundCallback, str]]
|
``` |
dict[str | Type[MouseEvent], tuple[BoundCallback, str]]
|
{ "": (star_callback, "This is a callback activated when '' is pressed.") |
dict[str | Type[MouseEvent], tuple[BoundCallback, str]]
|
} |
dict[str | Type[MouseEvent], tuple[BoundCallback, str]]
|
``` |
chars = type(self).chars.copy()
class-attribute
instance-attribute
Default characters for this class
id
property
writable
Gets this widget's id property
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The id string if one is present, None otherwise. |
is_selectable
property
Determines whether this widget has any selectables.
Returns:
| Type | Description |
|---|---|
bool
|
A boolean, representing |
keys = {}
class-attribute
instance-attribute
Groups of keys that are used in handle_key
parent_align = HorizontalAlignment.get_default()
class-attribute
instance-attribute
pytermgui.enums.HorizontalAlignment to align widget by
relative_width
property
writable
Sets this widget's relative width, and changes size_policy to RELATIVE.
The value is clamped to 1.0.
If a Container holds a width of 30, and it has a subwidget with a relative width of 0.5, it will be resized to 15.
Returns:
| Type | Description |
|---|---|
float | None
|
The current relative_width. |
selectables
property
selectables_length
property
Gets how many selectables this widget contains.
Returns:
| Type | Description |
|---|---|
int
|
An integer describing the amount of selectables in this widget. |
serialized = ['id', 'pos', 'depth', 'width', 'height', 'selected_index', 'selectables_length']
class-attribute
instance-attribute
Fields of widget that shall be serialized by pytermgui.serializer.Serializer
size_policy = SizePolicy.get_default()
class-attribute
instance-attribute
pytermgui.enums.SizePolicy to set widget's width according to
static_width
property
writable
Allows for a shorter way of setting a width, and SizePolicy.STATIC.
Returns:
| Type | Description |
|---|---|
int
|
None, as this is setter only. |
styles = type(self).styles.branch(self)
class-attribute
instance-attribute
Default styles for this class
terminal
property
Returns the current global terminal instance.
__fancy_repr__()
Yields the repr of this object, then a preview of it.
Source code in pytermgui/widgets/base.py
159 160 161 162 163 164 165 166 167 | |
__init__(**attrs)
Initialize object
Source code in pytermgui/widgets/base.py
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 | |
__iter__()
Return self for iteration
Source code in pytermgui/widgets/base.py
169 170 171 172 | |
__repr__()
Return repr string of this widget.
Returns:
| Type | Description |
|---|---|
str
|
Whatever this widget's |
Source code in pytermgui/widgets/base.py
150 151 152 153 154 155 156 157 | |
bind(key, action, description=None)
Binds an action to a keypress.
This function is only called by implementations above this layer. To use this
functionality use pytermgui.window_manager.WindowManager, or write your own
custom layer.
Special keys: - keys.ANY_KEY: Any and all keypresses execute this binding. - keys.MouseAction: Any and all mouse inputs execute this binding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key that the action will be bound to. |
required |
action
|
BoundCallback
|
The action executed when the key is pressed. |
required |
description
|
Optional[str]
|
An optional description for this binding. It is not really used anywhere, but you can provide a helper menu and display them. |
None
|
Source code in pytermgui/widgets/base.py
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 | |
contains(pos)
Determines whether widget contains pos.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pos
|
tuple[int, int]
|
Position to compare. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Boolean describing whether the position is inside this widget. |
Source code in pytermgui/widgets/base.py
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
copy()
Creates a deep copy of this widget
Source code in pytermgui/widgets/base.py
509 510 511 512 | |
debug()
Returns identifiable information about this widget.
This method is used to easily differentiate between widgets. By default, all widget's repr method is an alias to this. The signature of each widget is used to generate the return value.
Returns:
| Type | Description |
|---|---|
str
|
A string almost exactly matching the line of code that could have defined the widget. |
str
|
Example return: |
str
|
``` |
str
|
Container(Label(value="This is a label", padding=0), |
str
|
Button(label="This is a button", padding=0), **attrs) |
str
|
``` |
Source code in pytermgui/widgets/base.py
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 | |
execute_binding(key, ignore_any=False)
Executes a binding belonging to key, when present.
Use this method inside custom widget handle_keys methods, or to run a callback
without its corresponding key having been pressed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Any
|
Usually a string, indexing into the |
required |
ignore_any
|
bool
|
If set, |
False
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the binding was found, False otherwise. Bindings will always be executed if they are found. |
Source code in pytermgui/widgets/base.py
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 | |
get_change()
Determines whether widget lines changed since the last call to this function.
Source code in pytermgui/widgets/base.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
get_lines()
Gets lines representing this widget.
These lines have to be equal to the widget in length. All widgets must provide this method. Make sure to keep it performant, as it will be called very often, often multiple times per WindowManager frame.
Any longer actions should be done outside of this method, and only their result should be looked up here.
Returns:
| Type | Description |
|---|---|
list[str]
|
Nothing by default. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
As this method is required for all widgets, not having it defined will raise NotImplementedError. |
Source code in pytermgui/widgets/base.py
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 | |
handle_key(key)
Handles a mouse event, returning its success.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
String representation of input string.
The |
required |
Returns:
| Type | Description |
|---|---|
bool
|
A boolean describing whether the key was handled. |
Source code in pytermgui/widgets/base.py
434 435 436 437 438 439 440 441 442 443 444 445 446 | |
handle_mouse(event)
Tries to call the most specific mouse handler function available.
This function looks for a set of mouse action handlers. Each handler follows the format
on_{event_name}
For example, the handler triggered on MouseAction.LEFT_CLICK would be
on_left_click. If no handler is found nothing is done.
You can also define more general handlers, for example to group left & right
clicks you can use on_click, and to catch both up and down scroll you can use
on_scroll. General handlers are only used if they are the most specific ones,
i.e. there is no "specific" handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
MouseEvent
|
The event to handle. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether the parent of this widget should treat it as one to "stick" events |
bool
|
to, e.g. to keep sending mouse events to it. One can "unstick" a widget by |
bool
|
returning False in the handler. |
Source code in pytermgui/widgets/base.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 | |
move(diff_x, diff_y)
Moves the widget by the given x and y changes.
Source code in pytermgui/widgets/base.py
577 578 579 580 581 582 583 584 585 586 | |
print()
Prints this widget
Source code in pytermgui/widgets/base.py
664 665 666 667 668 | |
select(index=None)
Selects a part of this Widget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int | None
|
The index to select. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
This widget has no selectables, i.e. widget.is_selectable == False. |
Source code in pytermgui/widgets/base.py
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 | |
serialize()
Serializes a widget.
The fields looked at are defined Widget.serialized. Note that
this method is not very commonly used at the moment, so it might
not have full functionality in non-nuclear widgets.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary of widget attributes. The dictionary will always |
dict[str, Any]
|
have a |
dict[str, Any]
|
strings during serialization, so they can be loaded again in |
dict[str, Any]
|
their original form. |
dict[str, Any]
|
Example return: |
dict[str, Any]
|
``` { "type": "Label", "value": "[210 bold]I am a title", "parent_align": 0, ... } |
dict[str, Any]
|
``` |
Source code in pytermgui/widgets/base.py
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | |
unbind(key)
Unbinds the given key.
Source code in pytermgui/widgets/base.py
613 614 615 616 | |
WidgetChange
Bases: Enum
The type of change that happened within a widget.
Source code in pytermgui/enums.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
HEIGHT = _auto()
class-attribute
instance-attribute
The height of the widget changed, possibly involving LINES type changes.
LINES = _auto()
class-attribute
instance-attribute
The result of get_lines has changed, but size changes didn't happen.
SIZE = _auto()
class-attribute
instance-attribute
Both WIDTH and HEIGHT has changed.
WIDTH = _auto()
class-attribute
instance-attribute
The width of the widget changed, possibly involving LINES type changes.
WidgetNamespace
dataclass
Class to hold data on loaded namespace.
Source code in pytermgui/file_loaders.py
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 183 184 185 186 187 188 189 190 191 192 193 194 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 244 245 246 247 248 249 250 251 252 | |
__getattr__(attr)
Get widget by name from widget list.
Source code in pytermgui/file_loaders.py
246 247 248 249 250 251 252 | |
apply_config()
Apply self.config to current namespace.
Source code in pytermgui/file_loaders.py
239 240 241 242 243 244 | |
apply_to(widget)
Applies namespace config to the widget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
widget
|
Widget
|
The widget in question. |
required |
Source code in pytermgui/file_loaders.py
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 | |
from_config(data, loader)
classmethod
Creates a namespace from config data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[Any, Any]
|
A dictionary of config data. |
required |
loader
|
FileLoader
|
The |
required |
Returns:
| Type | Description |
|---|---|
WidgetNamespace
|
A new WidgetNamespace with the given config. |
Source code in pytermgui/file_loaders.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |
WidthExceededError
Bases: Exception
Raised when an element's width is larger than the screen.
Source code in pytermgui/exceptions.py
21 22 | |
Window
Bases: Container
A class representing a window.
Windows are essentially fancy pytermgui.widgets.Container-s. They build on top of them
to store and display various widgets, while allowing some custom functionality.
Source code in pytermgui/window_manager/window.py
17 18 19 20 21 22 23 24 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 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 183 184 185 186 187 188 189 190 191 192 193 194 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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
is_dirty = False
class-attribute
instance-attribute
Controls whether the window should be redrawn in the next frame.
is_modal = False
class-attribute
instance-attribute
Modal windows stay on top of every other window and block interactions with other windows.
is_noblur = False
class-attribute
instance-attribute
No-blur windows will always appear to stay in focus, even if they functionally don't.
is_noresize = False
class-attribute
instance-attribute
No-resize windows cannot be resized using the mouse.
is_persistent = False
class-attribute
instance-attribute
Persistent windows will be set noblur automatically, and remain clickable even through modals.
While the library core doesn't do this for various reasons, it also might be useful to disable some behaviour (e.g. closing) for persistent windows on an implementation level.
is_static = False
class-attribute
instance-attribute
Static windows cannot be moved using the mouse.
min_width
property
writable
Minimum width of the window.
If set to none, _auto_min_width will be calculated based on the maximum width of inner widgets.
This is accurate enough for general use, but tends to lean to the safer side, i.e. it often overshoots the 'real' minimum width possible.
If you find this to be the case, AND you can ensure that your window will not break, you may set this value manually.
Returns:
| Type | Description |
|---|---|
int | None
|
The calculated, or given minimum width of this object. |
rect
property
writable
Returns the tuple of positions that define this window.
Returns:
| Type | Description |
|---|---|
tuple[int, int, int, int]
|
A tuple of integers, in the order (left, top, right, bottom). |
title = ''
class-attribute
instance-attribute
Title shown in left-top corner.
__add__(other)
Calls self._add_widget(other) and returns self.
Source code in pytermgui/window_manager/window.py
166 167 168 169 170 | |
__iadd__(other)
Calls self._add_widget(other) and returns self.
Source code in pytermgui/window_manager/window.py
160 161 162 163 164 | |
__init__(*widgets, **attrs)
Initializes object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*widgets
|
Any
|
Widgets to add to this window after initilization. |
()
|
**attrs
|
Any
|
Attributes that are passed to the constructor. |
{}
|
Source code in pytermgui/window_manager/window.py
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 | |
blur()
Blurs (unfocuses) this window.
Source code in pytermgui/window_manager/window.py
217 218 219 220 221 222 223 224 225 226 | |
center(where=None, store=True)
Center window
Source code in pytermgui/window_manager/window.py
286 287 288 289 290 291 292 | |
clear_cache()
Clears manager compositor's cached blur state.
Source code in pytermgui/window_manager/window.py
228 229 230 231 232 | |
close(animate=True)
Instruct window manager to close object
Source code in pytermgui/window_manager/window.py
294 295 296 297 298 299 | |
contains(pos)
Determines whether widget contains pos.
This method uses window.rect to get the positions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pos
|
tuple[int, int]
|
Position to compare. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Boolean describing whether the position is inside this widget. |
Source code in pytermgui/window_manager/window.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
focus()
Focuses this window.
Source code in pytermgui/window_manager/window.py
208 209 210 211 212 213 214 215 | |
set_focus_styles(*, focused, blurred)
classmethod
Sets focused & blurred border & corner styles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
focused
|
tuple[StyleValue, StyleValue]
|
A tuple of border_focused, corner_focused styles. |
required |
blurred
|
tuple[StyleValue, StyleValue]
|
A tuple of border_blurred, corner_blurred styles. |
required |
Source code in pytermgui/window_manager/window.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
set_title(title, position=0, pad=True)
Sets the window's title.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
The string to set as the window title. |
required |
position
|
int
|
An integer indexing into ["left", "top", "right", "bottom"], determining where the title is applied. |
0
|
pad
|
bool
|
Whether there should be an extra space before and after the given title. defaults to True. |
True
|
Source code in pytermgui/window_manager/window.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
WindowManager
Bases: Widget
The manager of windows.
This class can be used, or even subclassed in order to create full-screen applications,
using the pytermgui.window_manager.window.Window class and the general Widget API.
Source code in pytermgui/window_manager/manager.py
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 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 183 184 185 186 187 188 189 190 191 192 193 194 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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 | |
focusing_actions = (MouseAction.LEFT_CLICK, MouseAction.RIGHT_CLICK)
class-attribute
instance-attribute
These mouse actions will focus the window they are acted upon.
__enter__()
Starts context manager.
Source code in pytermgui/window_manager/manager.py
108 109 110 111 | |
__exit__(_, exception, __)
Ends context manager.
Source code in pytermgui/window_manager/manager.py
113 114 115 116 117 118 119 120 121 122 123 124 | |
__iadd__(other)
Adds a window to the manager.
Source code in pytermgui/window_manager/manager.py
92 93 94 95 96 97 98 | |
__init__(*, layout_type=Layout, framerate=60, autorun=None)
Initialize the manager.
Source code in pytermgui/window_manager/manager.py
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 | |
__isub__(other)
Removes a window from the manager.
Source code in pytermgui/window_manager/manager.py
100 101 102 103 104 105 106 | |
__iter__()
Iterates this manager's windows.
Source code in pytermgui/window_manager/manager.py
126 127 128 129 | |
add(window, assign=True, animate=True)
Adds a window to the manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window
|
Window
|
The window to add. |
required |
assign
|
str | bool
|
The name of the slot the new window should be assigned to, or a boolean. If it is given a str, it is treated as the name of a slot. When given True, the next non-filled slot will be assigned, and when given False no assignment will be done. |
True
|
animate
|
bool
|
If set, an animation will be played on the window once it's added. |
True
|
Source code in pytermgui/window_manager/manager.py
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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
alert(*items, center=True, **attributes)
Creates a modal popup of the given elements and attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*items
|
Any
|
All widget-convertable objects passed as children of the new window. |
()
|
center
|
bool
|
If set, |
True
|
**attributes
|
Any
|
kwargs passed as the new window's attributes. |
{}
|
Source code in pytermgui/window_manager/manager.py
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 | |
clear_cache(window)
Clears the compositor's cache related to the given window.
Source code in pytermgui/window_manager/manager.py
160 161 162 163 | |
focus(window)
Focuses a window by moving it to the first index in _windows.
Source code in pytermgui/window_manager/manager.py
299 300 301 302 303 304 305 306 307 308 309 310 | |
focus_next(step=1)
Focuses the next window in focus order, looping to first at the end.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
int
|
The direction to step through windows. +1 for next, -1 for previous. |
1
|
Source code in pytermgui/window_manager/manager.py
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
get_lines()
Gets the empty list.
Source code in pytermgui/window_manager/manager.py
153 154 155 156 157 158 | |
handle_key(key)
Processes a keypress.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key to handle. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the given key could be processed, False otherwise. |
Source code in pytermgui/window_manager/manager.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | |
on_resize(size)
Correctly updates window positions & prints when terminal gets resized.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
tuple[int, int]
|
The new terminal size. |
required |
Source code in pytermgui/window_manager/manager.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
process_mouse(key)
Processes (potential) mouse input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Input to handle. |
required |
Source code in pytermgui/window_manager/manager.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 | |
remove(window, autostop=True, animate=True)
Removes a window from the manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window
|
Window
|
The window to remove. |
required |
autostop
|
bool
|
If set, the manager will be stopped if the length of its windows hits 0. |
True
|
Source code in pytermgui/window_manager/manager.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | |
run(mouse_events=None)
Starts the WindowManager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mouse_events
|
list[str] | None
|
A list of mouse event types to listen to. See
|
None
|
Returns:
| Type | Description |
|---|---|
None
|
The WindowManager's compositor instance. |
Source code in pytermgui/window_manager/manager.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
screenshot(title, filename='screenshot.svg')
Takes a screenshot of the current state.
See pytermgui.exporters.to_svg for more information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The name of the file. |
'screenshot.svg'
|
Source code in pytermgui/window_manager/manager.py
534 535 536 537 538 539 540 541 542 543 | |
show_positions()
Shows the positions of each Window's widgets.
Source code in pytermgui/window_manager/manager.py
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 | |
stop()
Stops the WindowManager and its compositor.
Source code in pytermgui/window_manager/manager.py
207 208 209 210 211 212 213 | |
toast(*items, offset=0, duration=300, delay=1000, **attributes)
Creates a Material UI-inspired toast window of the given elements and attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*items
|
Any
|
All widget-convertable objects passed as children of the new window. |
()
|
delay
|
int
|
The amount of time before the window will start animating out. |
1000
|
**attributes
|
Any
|
kwargs passed as the new window's attributes. |
{}
|
Source code in pytermgui/window_manager/manager.py
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 | |
YamlLoader
Bases: FileLoader
YAML specific loader subclass.
Source code in pytermgui/file_loaders.py
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | |
__init__(serializer=None)
Initialize object, check for installation of PyYAML.
Source code in pytermgui/file_loaders.py
412 413 414 415 416 417 418 419 420 | |
parse(data)
Parse YAML str.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str
|
YAML formatted string. |
required |
Returns:
| Type | Description |
|---|---|
dict[Any, Any]
|
Loadable dictionary. |
Source code in pytermgui/file_loaders.py
422 423 424 425 426 427 428 429 430 431 432 433 | |
analogous(base)
Colors that sit next to eachother on the colorwheel.
Note that the order of primary and secondary colors are swapped by this function. This is done so the colors, when laid out next to eachother, complete a gradient.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base
|
Color
|
The color used for derivations. |
required |
Source code in pytermgui/palettes.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
auto(data, **widget_args)
Creates a widget from specific data structures.
This conversion includes various widget classes, as well as some shorthands for more complex objects. This method is called implicitly whenever a non-widget is attempted to be added to a Widget.
You can read up on the syntacies for each builtin widget within the widget documentation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The structure to convert. See below for formats. |
required |
**widget_args
|
Any
|
Arguments passed straight to the widget constructor. |
{}
|
Returns:
| Type | Description |
|---|---|
Optional[Widget | list[Splitter]]
|
The widget or list of widgets created, or None if the passed structure could |
Optional[Widget | list[Splitter]]
|
not be converted. |
Example:
from pytermgui import Container
form = (
Container(id="form")
+ "[157 bold]This is a title"
+ ""
+ {"[72 italic]Label1": "[210]Button1"}
+ {"[72 italic]Label2": "[210]Button2"}
+ {"[72 italic]Label3": "[210]Button3"}
+ ""
+ ["Submit", lambda _, button, your_submit_handler(button.parent)]
)
Source code in pytermgui/__init__.py
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 | |
background(text, color, reset=True)
Sets the background color of the given text.
Note that the given color will be forced into background = True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to color. |
required |
color
|
str | Color
|
The color to use. See |
required |
reset
|
bool
|
Whether the return value should include a reset sequence at the end. |
True
|
Returns:
| Type | Description |
|---|---|
str
|
The colored text, including a reset if set. |
Source code in pytermgui/colors.py
952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 | |
blink(text, reset_style=True)
Returns text blinking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reset_style
|
Optional[bool]
|
Boolean that determines whether a reset character should be appended to the end of the string. |
True
|
Source code in pytermgui/ansi_interface.py
682 683 684 685 686 687 688 689 690 | |
bold(text, reset_style=True)
Returns text in bold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reset_style
|
Optional[bool]
|
Boolean that determines whether a reset character should be appended to the end of the string. |
True
|
Source code in pytermgui/ansi_interface.py
638 639 640 641 642 643 644 645 646 | |
break_line(line, limit, non_first_limit=None, fill=None)
Breaks a line into a list[str] with maximum limit length per line.
Uses wcwidth.wrap() for proper word-boundary breaking, grapheme cluster handling, and wide character support. ANSI sequences are preserved and propagated across line breaks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str
|
The line to split. May or may not contain ANSI sequences. |
required |
limit
|
int
|
The maximum amount of characters allowed in each line, excluding non-printing sequences. |
required |
non_first_limit
|
int | None
|
The limit after the first line. If not given, defaults
to |
None
|
fill
|
str | None
|
Optional character to pad lines to the limit width. |
None
|
Source code in pytermgui/helpers.py
16 17 18 19 20 21 22 23 24 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 | |
build_fancy_repr(obj)
Interprets objects with the __fancy_repr__ protocol.
Source code in pytermgui/fancy_repr.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
clear(what='screen')
Clears the specified screen region.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
what
|
str
|
The specifier defining the screen area. |
'screen'
|
Available options: * screen: clear whole screen and go to origin * bos: clear screen from cursor backwards * eos: clear screen from cursor forwards * line: clear line and go to beginning * bol: clear line from cursor backwards * eol: clear line from cursor forwards
Source code in pytermgui/ansi_interface.py
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 | |
clear_color_cache()
Clears _COLOR_CACHE and _COLOR_MATCH_CACHE.
Source code in pytermgui/colors.py
88 89 90 91 92 | |
consume_tag(tag)
Consumes a tag text, returns the associated Token.
Source code in pytermgui/markup/parsing.py
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 | |
create_context_dict()
Creates a new context dictionary, initializing its sub-dicts.
Returns:
| Type | Description |
|---|---|
ContextDict
|
A dictionary with |
Source code in pytermgui/markup/parsing.py
83 84 85 86 87 88 89 90 | |
cursor_column(num=0)
Moves the cursor to the num-th character of the current line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num
|
int
|
The new cursor position. |
0
|
Note
This does not flush the terminal for performance reasons. You
can do it manually with sys.stdout.flush().
Source code in pytermgui/ansi_interface.py
276 277 278 279 280 281 282 283 284 285 286 287 | |
cursor_down(num=1)
Moves the cursor up by num lines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num
|
int
|
How many lines the cursor should move by. Must be positive,
to move in the opposite direction use |
1
|
Note:
This does not flush the terminal for performance reasons. You
can do it manually with sys.stdout.flush().
Source code in pytermgui/ansi_interface.py
206 207 208 209 210 211 212 213 214 215 216 217 | |
cursor_home()
Moves cursor to get_terminal().origin.
Note
This does not flush the terminal for performance reasons. You
can do it manually with sys.stdout.flush().
Source code in pytermgui/ansi_interface.py
290 291 292 293 294 295 296 297 298 | |
cursor_left(num=1)
Moves the cursor left by num lines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num
|
int
|
How many characters the cursor should move by. Must be positive,
to move in the opposite direction use |
1
|
Note:
This does not flush the terminal for performance reasons. You
can do it manually with sys.stdout.flush().
Source code in pytermgui/ansi_interface.py
234 235 236 237 238 239 240 241 242 243 244 245 | |
cursor_next_line(num=1)
Moves the cursor to the beginning of the num-th line downwards.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num
|
int
|
The amount the cursor should move by. Must be positive, to move
in the opposite direction use |
1
|
Note:
This does not flush the terminal for performance reasons. You
can do it manually with sys.stdout.flush().
Source code in pytermgui/ansi_interface.py
248 249 250 251 252 253 254 255 256 257 258 259 | |
cursor_prev_line(num=1)
Moves the cursor to the beginning of the num-th line upwards.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num
|
int
|
The amount the cursor should move by. Must be positive, to move
in the opposite direction use |
1
|
Note:
This does not flush the terminal for performance reasons. You
can do it manually with sys.stdout.flush().
Source code in pytermgui/ansi_interface.py
262 263 264 265 266 267 268 269 270 271 272 273 | |
cursor_right(num=1)
Moves the cursor right by num lines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num
|
int
|
How many characters the cursor should move by. Must be positive,
to move in the opposite direction use |
1
|
Note:
This does not flush the terminal for performance reasons. You
can do it manually with sys.stdout.flush().
Source code in pytermgui/ansi_interface.py
220 221 222 223 224 225 226 227 228 229 230 231 | |
cursor_up(num=1)
Moves the cursor up by num lines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num
|
int
|
How many lines the cursor should move by. Must be positive,
to move in the opposite direction use |
1
|
Note:
This does not flush the terminal for performance reasons. You
can do it manually with sys.stdout.flush().
Source code in pytermgui/ansi_interface.py
192 193 194 195 196 197 198 199 200 201 202 203 | |
dim(text, reset_style=True)
Returns text in dim.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reset_style
|
Optional[bool]
|
Boolean that determines whether a reset character should be appended to the end of the string. |
True
|
Source code in pytermgui/ansi_interface.py
649 650 651 652 653 654 655 656 657 | |
escape(text)
Escapes any markup found within the given text.
Source code in pytermgui/markup/language.py
41 42 43 44 45 46 47 48 49 | |
escape_markup(text)
Escapes any potential markup to avoid double-parsing.
Use this when treating already parsed markup.
Source code in pytermgui/regex.py
79 80 81 82 83 84 85 86 87 88 89 90 | |
feed(text)
Manually feeds some text to be read by getch.
This can be used to emulate input, as well as to "interrupt" a blocking getch
call (though getch_timeout works better for that scenario).
Source code in pytermgui/input.py
81 82 83 84 85 86 87 88 89 | |
foreground(text, color, reset=True)
Sets the foreground color of the given text.
Note that the given color will be forced into background = True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to color. |
required |
color
|
str | Color
|
The color to use. See |
required |
reset
|
bool
|
Whether the return value should include a reset sequence at the end. |
True
|
Returns:
| Type | Description |
|---|---|
str
|
The colored text, including a reset if set. |
Source code in pytermgui/colors.py
929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 | |
get_markup(text)
Gets the markup representing an ANSI-coded string.
Source code in pytermgui/markup/parsing.py
581 582 583 584 | |
get_terminal()
Gets the default terminal instance used by the module.
Source code in pytermgui/term.py
645 646 647 648 | |
getch(printable=False, interrupts=True, windows_raise_timeout=False)
Wrapper to call the platform-appropriate character getter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
printable
|
bool
|
When set, printable versions of the input are returned. |
False
|
interrupts
|
bool
|
If not set, |
True
|
windows_raise_timeout
|
bool
|
If set, |
False
|
Source code in pytermgui/input.py
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 | |
getch_timeout(duration, default='', printable=False, interrupts=True)
Calls getch, returns default if timeout passes before getting input.
No timeout is applied on Windows systems, as there is no support for
SIGALRM. Instead, it will return immediately if no input is provided, since the
Windows APIs expose a way to detect that case.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
duration
|
float
|
How long the call should wait for input. |
required |
default
|
str
|
The value to return if timeout occured. |
''
|
Source code in pytermgui/input.py
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 | |
hide_cursor()
Stops printing the cursor.
Source code in pytermgui/ansi_interface.py
129 130 131 132 | |
highlight_tim(text, cache=True)
Highlights some TIM code.
Source code in pytermgui/highlighters.py
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 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
inspect(target, **inspector_args)
Inspects an object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
object
|
The object to inspect. |
required |
**inspector_args
|
Any
|
See |
{}
|
Source code in pytermgui/inspector.py
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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
inverse(text, reset_style=True)
Returns text inverse-colored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reset_style
|
Optional[bool]
|
Boolean that determines whether a reset character should be appended to the end of the string. |
True
|
Source code in pytermgui/ansi_interface.py
693 694 695 696 697 698 699 700 701 | |
invisible(text, reset_style=True)
Returns text as invisible.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reset_style
|
Optional[bool]
|
Boolean that determines whether a reset character should be appended to the end of the string. |
True
|
Note
This isn't very widely supported.
Source code in pytermgui/ansi_interface.py
704 705 706 707 708 709 710 711 712 713 714 715 | |
is_animated(target, attribute)
Determines whether the given object.attribute is animated.
This looks for __ptg_animated__, and whether it contains the given attribute.
Source code in pytermgui/animations.py
59 60 61 62 63 64 65 66 67 68 69 70 | |
italic(text, reset_style=True)
Returns text in italic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reset_style
|
Optional[bool]
|
Boolean that determines whether a reset character should be appended to the end of the string. |
True
|
Source code in pytermgui/ansi_interface.py
660 661 662 663 664 665 666 667 668 | |
move_cursor(pos)
Moves the cursor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pos
|
tuple[int, int]
|
Tuple of that the cursor will be moved to. |
required |
This does not flush the terminal for performance reasons. You
can do it manually with sys.stdout.flush().
Source code in pytermgui/ansi_interface.py
178 179 180 181 182 183 184 185 186 187 188 189 | |
optimize_markup(markup)
Optimizes markup by tokenizing it, optimizing the tokens and converting it back to markup.
Source code in pytermgui/markup/parsing.py
587 588 589 590 | |
optimize_tokens(tokens)
Optimizes a stream of tokens, only yielding functionally relevant ones.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tokens
|
list[Token]
|
Any list of Token objects. Usually obtained from |
required |
Yields:
| Type | Description |
|---|---|
Token
|
All those tokens within the input iterator that are functionally relevant, keeping their order. |
Source code in pytermgui/markup/parsing.py
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 | |
overline(text, reset_style=True)
Return text overlined.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reset_style
|
Optional[bool]
|
Boolean that determines whether a reset character should be appended to the end of the string. |
True
|
Note
This isnt' very widely supported.
Source code in pytermgui/ansi_interface.py
729 730 731 732 733 734 735 736 737 738 739 740 | |
parse(text, optimize=False, context=None, append_reset=True, ignore_unknown_tags=True)
Parses markup into the ANSI-coded string it represents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Any valid markup. |
required |
optimize
|
bool
|
If set, |
False
|
context
|
ContextDict | None
|
The context that aliases and macros found within the markup will be searched in. |
None
|
append_reset
|
bool
|
If set, |
True
|
ignore_unknown_tags
|
bool
|
If set, the |
True
|
Returns:
| Type | Description |
|---|---|
str
|
The ANSI-coded string that the markup represents. |
Source code in pytermgui/markup/parsing.py
809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 | |
parse_tokens(tokens, *, optimize=False, context=None, append_reset=True, ignore_unknown_tags=True)
Parses a stream of tokens into the ANSI-coded string they represent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tokens
|
list[Token]
|
Any list of Tokens, usually obtained from either |
required |
optimize
|
bool
|
If set, |
False
|
context
|
ContextDict | None
|
The context that aliases and macros found within the tokens will be searched in. |
None
|
append_reset
|
bool
|
If set, |
True
|
ignore_unknown_tags
|
bool
|
If set, the |
True
|
Returns:
| Type | Description |
|---|---|
str
|
The ANSI-coded string that the token stream represents. |
Source code in pytermgui/markup/parsing.py
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 | |
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 usingpytermgui.prettyor any of its printers, a singleNonereturn 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 146 | |
print_to(pos, *args, **kwargs)
Prints text to given pos.
Note
This method passes through all arguments (except for pos) to the print
method.
Source code in pytermgui/ansi_interface.py
620 621 622 623 624 625 626 627 628 629 | |
real_length(text)
cached
Gets the display-length of text.
This length means no ANSI sequences are counted. This method is a convenience wrapper
for len(strip_ansi(text)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to calculate the length of. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The display-length of text. |
Source code in pytermgui/regex.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
report_cursor()
Gets position of cursor.
Returns:
| Type | Description |
|---|---|
'Optional[tuple[int, int]]'
|
A tuple of integers, (columns, rows), describing the |
'Optional[tuple[int, int]]'
|
current (printing) cursor's position. Returns None if |
'Optional[tuple[int, int]]'
|
this could not be determined. |
'Optional[tuple[int, int]]'
|
Note that this position is not the mouse position. See |
'Optional[tuple[int, int]]'
|
|
Source code in pytermgui/ansi_interface.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
report_mouse(event, method='decimal_xterm', stop=False)
Starts reporting of mouse events.
You can specify multiple events to report on.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
str
|
The type of event to report on. See below for options. |
required |
method
|
Optional[str]
|
The method of reporting to use. See below for options. |
'decimal_xterm'
|
stop
|
bool
|
If set to True, the stopping code is written to stdout. |
False
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
The given event is not supported. |
Note
If you need this functionality, you're probably better off using the wrapper
pytermgui.context_managers.mouse_handler, which allows listening on multiple
events, gives a translator method and handles exceptions.
Possible events
- press: Report when the mouse is clicked, left or right button.
- highlight: Report highlighting.
- press_hold: Report with a left or right click, as well as both left & right drag and release.
- all: Report every event, even hover.
Functions:
| Name | Description |
|---|---|
- **None** |
Non-decimal xterm method. Limited in coordinates. |
- **decimal_xterm** |
The default setting. Most universally supported. |
- **decimal_urxvt** |
Older, less compatible, but useful on some systems. |
- **decimal_utf8** |
Apparently not too stable. |
More information here.
Source code in pytermgui/ansi_interface.py
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 | |
reset()
Resets printing mode.
Source code in pytermgui/ansi_interface.py
632 633 634 635 | |
restore_cursor()
Restore cursor position as saved by save_cursor.
Source code in pytermgui/ansi_interface.py
150 151 152 153 | |
restore_screen()
Restores the contents of the screen saved by save_screen().
Source code in pytermgui/ansi_interface.py
83 84 85 86 | |
save_cursor()
Saves the current cursor position.
Use restore_cursor to restore it.
Source code in pytermgui/ansi_interface.py
141 142 143 144 145 146 147 | |
save_screen()
Saves the contents of the screen, and wipes it.
Use restore_screen() to get them back.
Source code in pytermgui/ansi_interface.py
74 75 76 77 78 79 80 | |
set_alt_buffer()
Starts an alternate buffer.
Source code in pytermgui/ansi_interface.py
89 90 91 92 | |
set_echo()
Starts echoing of user input.
Note
This is currently only available on POSIX.
Source code in pytermgui/ansi_interface.py
351 352 353 354 355 356 357 358 359 360 361 | |
set_global_terminal(new)
Sets the terminal instance to be used by the module.
Source code in pytermgui/term.py
639 640 641 642 | |
set_mode(mode, write=True)
Sets terminal display mode.
This is better left internal. To use these modes, you can call their
specific functions, such as bold("text") or italic("text").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
Union[str, int]
|
One of the available modes. Strings and integers both work. |
required |
write
|
bool
|
Boolean that determines whether the output should be written to stdout. |
True
|
Returns:
| Type | Description |
|---|---|
str
|
A string that sets the given mode. |
Available modes
- 0: reset
- 1: bold
- 2: dim
- 3: italic
- 4: underline
- 5: blink
- 7: inverse
- 8: invisible
- 9: strikethrough
- 53: overline
Source code in pytermgui/ansi_interface.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | |
show_cursor()
Starts printing the cursor.
Source code in pytermgui/ansi_interface.py
135 136 137 138 | |
str_to_color(text, is_background=False, localize=True, use_cache=True)
cached
Creates a Color from the given text.
Accepted formats:
- 0-255:
IndexedColor. - 'rrr;ggg;bbb':
RGBColor. - '(#)rrggbb':
HEXColor. Leading hash is optional.
You can also add a leading '@' into the string to make the output represent a
background color, such as @#123abc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The string to format from. |
required |
is_background
|
bool
|
Whether the output should be forced into a background color. Mostly used internally, when set will take precedence over syntax of leading '@' symbol. |
False
|
localize
|
bool
|
Whether |
True
|
use_cache
|
bool
|
Whether caching should be used. |
True
|
Source code in pytermgui/colors.py
840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 | |
strikethrough(text, reset_style=True)
Return text as strikethrough.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reset_style
|
Optional[bool]
|
Boolean that determines whether a reset character should be appended to the end of the string. |
True
|
Source code in pytermgui/ansi_interface.py
718 719 720 721 722 723 724 725 726 | |
strip_ansi(text)
cached
Removes ANSI sequences from text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
A string or bytes object containing 0 or more ANSI sequences. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The text without any ANSI sequences. |
Source code in pytermgui/regex.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
strip_markup(text)
cached
Removes markup tags from text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
A string or bytes object containing 0 or more markup tags. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The text without any markup tags. |
Source code in pytermgui/regex.py
48 49 50 51 52 53 54 55 56 57 58 59 | |
supports_fancy_repr(obj)
Determines whether the given object supports the fancy repl protocol.
Source code in pytermgui/fancy_repr.py
37 38 39 40 | |
to_html(obj, prefix=None, inline_styles=False, include_background=True, vertical_offset=0.0, horizontal_offset=0.0, formatter=HTML_FORMAT, joiner='\n')
Creates a static HTML representation of the given object.
Note that the output HTML will not be very attractive or easy to read. This is because these files probably aren't meant to be read by a human anyways, so file sizes are more important.
If you do care about the visual style of the output, you can run it through some prettifiers to get the result you are looking for.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Widget | StyledText | str
|
The object to represent. Takes either a Widget or some markup text. |
required |
prefix
|
str | None
|
The prefix included in the generated classes, e.g. instead of |
None
|
inline_styles
|
bool
|
If set, styles will be set for each span using the inline |
False
|
include_background
|
bool
|
Whether to include the terminal's background color in the output. |
True
|
Source code in pytermgui/exporters.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | |
token_to_css(token, invert=False)
Finds the CSS representation of a token.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token
|
Token
|
The token to represent. |
required |
invert
|
bool
|
If set, the role of background & foreground colors are flipped. |
False
|
Source code in pytermgui/exporters.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |
tokenize_ansi(text)
Converts some ANSI-coded text into a stream of tokens.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Any valid ANSI-coded text. |
required |
Yields:
| Type | Description |
|---|---|
Token
|
The generated tokens, in the order they occur within the text. |
Source code in pytermgui/markup/parsing.py
191 192 193 194 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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | |
tokenize_markup(text)
Converts some markup text into a stream of tokens.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Any valid markup. |
required |
Yields:
| Type | Description |
|---|---|
Token
|
The generated tokens, in the order they occur within the markup. |
Source code in pytermgui/markup/parsing.py
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 183 184 185 186 187 188 | |
tokens_to_markup(tokens)
Converts a token stream into the markup of its tokens.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tokens
|
list[Token]
|
Any list of Token objects. Usually obtained from |
required |
Returns:
| Type | Description |
|---|---|
str
|
The markup the given tokens represent. |
Source code in pytermgui/markup/parsing.py
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 | |
translate_mouse(code, method)
Translates the output of produced by setting report_mouse into MouseEvents.
This method currently only supports decimal_xterm and decimal_urxvt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
The string of mouse code(s) to translate. |
required |
method
|
str
|
The reporting method to translate. One of |
required |
Returns:
| Type | Description |
|---|---|
list[MouseEvent | None] | None
|
A list of optional mouse events obtained from the code argument. If the code was malformed, |
list[MouseEvent | None] | None
|
and no codes could be determined None is returned. |
Source code in pytermgui/ansi_interface.py
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 | |
triadic(base)
Three complementary colors.
Each color is offset 120 degrees from the previous one on the colorwheel. If plotted on the colorwheel, they make up a regular triangle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base
|
Color
|
The color used for derivations. |
required |
Source code in pytermgui/palettes.py
54 55 56 57 58 59 60 61 62 63 64 65 66 | |
underline(text, reset_style=True)
Returns text underlined.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reset_style
|
Optional[bool]
|
Boolean that determines whether a reset character should be appended to the end of the string. |
True
|
Source code in pytermgui/ansi_interface.py
671 672 673 674 675 676 677 678 679 | |
unset_alt_buffer()
Returns to main buffer, restoring its original state.
Source code in pytermgui/ansi_interface.py
95 96 97 98 | |
unset_echo()
Stops echoing of user input.
Note
This is currently only available on POSIX.
Source code in pytermgui/ansi_interface.py
364 365 366 367 368 369 370 371 372 373 374 | |