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

Function diffDifferentWidth

src/ink/screen.ts:1746–1831  ·  view source on GitHub ↗

* Fallback: diff two screens with different widths (resize). * Separate indices for prev and next cells arrays.

(
  prev: Screen,
  next: Screen,
  startX: number,
  endX: number,
  startY: number,
  endY: number,
  cb: DiffCallback,
)

Source from the content-addressed store, hash-verified

1744 * Separate indices for prev and next cells arrays.
1745 */
1746function diffDifferentWidth(
1747 prev: Screen,
1748 next: Screen,
1749 startX: number,
1750 endX: number,
1751 startY: number,
1752 endY: number,
1753 cb: DiffCallback,
1754): boolean {
1755 const prevWidth = prev.width
1756 const nextWidth = next.width
1757 const prevCells = prev.cells
1758 const nextCells = next.cells
1759
1760 const prevCell: Cell = {
1761 char: ' ',
1762 styleId: 0,
1763 width: CellWidth.Narrow,
1764 hyperlink: undefined,
1765 }
1766 const nextCell: Cell = {
1767 char: ' ',
1768 styleId: 0,
1769 width: CellWidth.Narrow,
1770 hyperlink: undefined,
1771 }
1772
1773 const prevStride = prevWidth << 1
1774 const nextStride = nextWidth << 1
1775 let prevRowCI = (startY * prevWidth + startX) << 1
1776 let nextRowCI = (startY * nextWidth + startX) << 1
1777
1778 for (let y = startY; y < endY; y++) {
1779 const prevIn = y < prev.height
1780 const nextIn = y < next.height
1781 const prevEndX = prevIn ? Math.min(endX, prevWidth) : startX
1782 const nextEndX = nextIn ? Math.min(endX, nextWidth) : startX
1783 const bothEndX = Math.min(prevEndX, nextEndX)
1784
1785 let prevCI = prevRowCI
1786 let nextCI = nextRowCI
1787
1788 for (let x = startX; x < bothEndX; x++) {
1789 if (
1790 prevCells[prevCI] === nextCells[nextCI] &&
1791 prevCells[prevCI + 1] === nextCells[nextCI + 1]
1792 ) {
1793 prevCI += 2
1794 nextCI += 2
1795 continue
1796 }
1797 cellAtCI(prev, prevCI, prevCell)
1798 cellAtCI(next, nextCI, nextCell)
1799 prevCI += 2
1800 nextCI += 2
1801 if (cb(x, y, prevCell, nextCell)) return true
1802 }
1803

Callers 1

diffEachFunction · 0.85

Calls 1

cellAtCIFunction · 0.85

Tested by

no test coverage detected