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

Function clipMainScreenFrameToVisibleRows

src/ink/log-update.ts:1119–1175  ·  view source on GitHub ↗
(
  frame: Frame,
  stylePool: StylePool,
)

Source from the content-addressed store, hash-verified

1117}
1118
1119function clipMainScreenFrameToVisibleRows(
1120 frame: Frame,
1121 stylePool: StylePool,
1122): Frame {
1123 // Main-screen repaint from CSI H starts at the visible viewport home, not at
1124 // the logical output origin in scrollback. renderFrameSlice emits CRLF after
1125 // every row, so painting a full viewport would scroll the bottom row and
1126 // duplicate/garble the visible screen. Keep the logical frame intact for the
1127 // next incremental diff, but repaint only the visible content suffix here.
1128 const visibleRows = Math.max(0, frame.viewport.height - 1)
1129 if (frame.screen.height <= visibleRows) {
1130 return frame
1131 }
1132
1133 const sourceStartY = Math.max(0, frame.screen.height - visibleRows)
1134 const clippedHeight = frame.screen.height - sourceStartY
1135 const source = frame.screen
1136 const screen = createScreen(
1137 source.width,
1138 clippedHeight,
1139 stylePool,
1140 source.charPool,
1141 source.hyperlinkPool,
1142 )
1143
1144 const cellWordsPerRow = source.width << 1
1145 const sourceCellStart = sourceStartY * cellWordsPerRow
1146 screen.cells.set(
1147 source.cells.subarray(
1148 sourceCellStart,
1149 sourceCellStart + clippedHeight * cellWordsPerRow,
1150 ),
1151 )
1152
1153 const sourceNoSelectStart = sourceStartY * source.width
1154 screen.noSelect.set(
1155 source.noSelect.subarray(
1156 sourceNoSelectStart,
1157 sourceNoSelectStart + clippedHeight * source.width,
1158 ),
1159 )
1160 screen.softWrap.set(
1161 source.softWrap.subarray(sourceStartY, sourceStartY + clippedHeight),
1162 )
1163 screen.contentEnd.set(
1164 source.contentEnd.subarray(sourceStartY, sourceStartY + clippedHeight),
1165 )
1166
1167 return {
1168 screen,
1169 viewport: frame.viewport,
1170 cursor: {
1171 ...frame.cursor,
1172 y: Math.max(0, frame.cursor.y - sourceStartY),
1173 },
1174 }
1175}
1176

Callers 2

renderMethod · 0.85

Calls 3

createScreenFunction · 0.85
maxMethod · 0.80
setMethod · 0.80

Tested by

no test coverage detected