Canvas
Module: terminaltexteffects.engine.terminal
Represent the canvas in the terminal.
The canvas is the area defined by the dimensions of the input data, unless specified otherwise in the TerminalConfig.
This class provides methods for working with the canvas, such as checking if a coordinate is within the canvas, getting random coordinates within the canvas, and getting a random coordinate outside the canvas.
This class also provides attributes for the dimensions of the canvas, the extents of the text within the canvas, and the center of the canvas.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
top
|
int
|
top row of the canvas |
required |
right
|
int
|
right column of the canvas |
required |
bottom
|
int
|
bottom row of the canvas. Defaults to 1. |
1
|
left
|
int
|
left column of the canvas. Defaults to 1. |
1
|
Attributes:
| Name | Type | Description |
|---|---|---|
top |
int
|
top row of the canvas |
right |
int
|
right column of the canvas |
bottom |
int
|
bottom row of the canvas |
left |
int
|
left column of the canvas |
center_row |
int
|
row of the center of the canvas |
center_column |
int
|
column of the center of the canvas |
center |
Coord
|
coordinate of the center of the canvas |
width |
int
|
width of the canvas |
height |
int
|
height of the canvas |
text_left |
int
|
left column of the text within the canvas |
text_right |
int
|
right column of the text within the canvas |
text_top |
int
|
top row of the text within the canvas |
text_bottom |
int
|
bottom row of the text within the canvas |
text_width |
int
|
width of the text within the canvas |
text_height |
int
|
height of the text within the canvas |
text_center_row |
int
|
row of the center of the text within the canvas |
text_center_column |
int
|
column of the center of the text within the canvas |
Methods:
| Name | Description |
|---|---|
coord_is_in_canvas |
Checks whether a coordinate is within the canvas. |
coord_is_in_text |
Checks whether a coordinate is within the text boundary of the canvas. |
random_column |
Get a random column position within the canvas. |
random_row |
Get a random row position within the canvas. |
random_coord |
Get a random coordinate within or outside the canvas. |
Source code in terminaltexteffects/engine/terminal.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 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 | |
bottom = 1
class-attribute
instance-attribute
int: bottom row of the canvas
left = 1
class-attribute
instance-attribute
int: left column of the canvas
right
instance-attribute
int: right column of the canvas
top
instance-attribute
int: top row of the canvas
__post_init__()
After initialization, calculate the center, width, height, and text dimensions of the canvas.
Source code in terminaltexteffects/engine/terminal.py
coord_is_in_canvas(coord)
Check whether a coordinate is within the canvas.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coord
|
Coord
|
coordinate to check |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
whether the coordinate is within the canvas |
Source code in terminaltexteffects/engine/terminal.py
coord_is_in_text(coord)
Check whether a coordinate is within the text boundary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coord
|
Coord
|
coordinate to check |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
whether the coordinate is within the text boundary |
Source code in terminaltexteffects/engine/terminal.py
random_column(*, within_text_boundary=False)
Get a random column position within the canvas.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
within_text_boundary
|
bool
|
If True, the column will be limited to the text boundary. Otherwise, it can be anywhere within the canvas. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
a random column position within the canvas |
Source code in terminaltexteffects/engine/terminal.py
random_coord(*, outside_scope=False, within_text_boundary=False)
Get a random coordinate. Coordinate is within the canvas unless outside_scope is True.
outside_scope takes precedence over within_text_boundary, they are functionally mutually exclusive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outside_scope
|
bool
|
whether the coordinate should fall outside the canvas. Defaults to False. |
False
|
within_text_boundary
|
bool
|
If True, the coordinate will be limited to the text boundary. Otherwise, it can be anywhere within the canvas. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Coord |
Coord
|
a random coordinate . Coordinate is within the canvas unless outside_scope is True. |
Source code in terminaltexteffects/engine/terminal.py
random_row(*, within_text_boundary=False)
Get a random row position within the canvas.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
within_text_boundary
|
bool
|
If True, the row will be limited to the text boundary. Otherwise, it can be anywhere within the canvas. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
a random row position within the canvas |