( width: number, height: number, styles: StylePool, charPool: CharPool, hyperlinkPool: HyperlinkPool, )
| 488 | // --- |
| 489 | |
| 490 | export function createScreen( |
| 491 | width: number, |
| 492 | height: number, |
| 493 | styles: StylePool, |
| 494 | charPool: CharPool, |
| 495 | hyperlinkPool: HyperlinkPool, |
| 496 | ): Screen { |
| 497 | // Warn if dimensions are not valid integers (likely bad yoga layout output) |
| 498 | warn.ifNotInteger(width, 'createScreen width') |
| 499 | warn.ifNotInteger(height, 'createScreen height') |
| 500 | |
| 501 | // Ensure width and height are valid integers to prevent crashes |
| 502 | if (!Number.isInteger(width) || width < 0) { |
| 503 | width = Math.max(0, Math.floor(width) || 0) |
| 504 | } |
| 505 | if (!Number.isInteger(height) || height < 0) { |
| 506 | height = Math.max(0, Math.floor(height) || 0) |
| 507 | } |
| 508 | |
| 509 | const size = width * height |
| 510 | |
| 511 | // Allocate one buffer, two views: Int32Array for per-word access, |
| 512 | // BigInt64Array for bulk fill in resetScreen/clearRegion. |
| 513 | // ArrayBuffer is zero-filled, which is exactly the empty cell value: |
| 514 | // [EMPTY_CHAR_INDEX=0, packWord1(emptyStyleId=0,0,0)=0]. |
| 515 | const buf = new ArrayBuffer(size << 3) // 8 bytes per cell |
| 516 | const cells = new Int32Array(buf) |
| 517 | const cells64 = new BigInt64Array(buf) |
| 518 | |
| 519 | return { |
| 520 | width, |
| 521 | height, |
| 522 | cells, |
| 523 | cells64, |
| 524 | charPool, |
| 525 | hyperlinkPool, |
| 526 | emptyStyleId: styles.none, |
| 527 | damage: undefined, |
| 528 | noSelect: new Uint8Array(size), |
| 529 | softWrap: new Int32Array(height), |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | /** |
| 534 | * Reset an existing screen for reuse, avoiding allocation of new typed arrays. |
no test coverage detected