MCPcopy Create free account
hub / github.com/Noumena-Network/code / createScreen

Function createScreen

src/ink/screen.ts:487–529  ·  view source on GitHub ↗
(
  width: number,
  height: number,
  styles: StylePool,
  charPool: CharPool,
  hyperlinkPool: HyperlinkPool,
)

Source from the content-addressed store, hash-verified

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

Callers 15

cloneFrameForMutationFunction · 0.85
emptyFrameFunction · 0.85
createOutputFunction · 0.85
output.test.tsFile · 0.85
renderToScreenFunction · 0.85
makeFrameFunction · 0.85
createRendererFunction · 0.85
makeFrameFunction · 0.85
createTestScreenFunction · 0.85
screen.test.tsFile · 0.85

Calls 1

maxMethod · 0.80

Tested by 8

createOutputFunction · 0.68
makeFrameFunction · 0.68
makeFrameFunction · 0.68
createTestScreenFunction · 0.68
createTestScreenFunction · 0.68
makeFrameFunction · 0.68
makeFrameFunction · 0.68
makeStyledLineFrameFunction · 0.68