Current Terminal Screen:
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
>         # Find changed rows and their changes
>         row_changes = {}
>         for r in range(h):
>             prev_row = frames[i-1][r*w:(r+1)*w]
>             curr_row = frames[i][r*w:(r+1)*w]
>             if prev_row != curr_row:
>                 changes = [c for c in range(w) if prev_row[c] != curr_row[c]]
>                 row_changes[r] = (changes, curr_row)
>
>         if not row_changes:
>             out.append('\x1e')
>             continue
>
>         for r, (changes, curr_row) in sorted(row_changes.items()):
>             runs = find_runs(changes)
>
>             # Calculate costs
>             # EL+rewrite: ESC[r;1H + ESC[2K + row
>             cost_erase = 3 + len(str(r+1)) + 1 + 1 + 4 + w
>
>             # Partial: sum of positioning + content for each run
>             cost_partial = sum(3 + len(str(r+1)) + 1 + len(str(start+1)) + 1 + (end-start+1) for start, end in runs)
>
>             if cost_erase <= cost_partial:
>                 out.append(f'\x1b[{r+1};1H')
>                 out.append('\x1b[2K')
>                 out.append(curr_row.decode('latin1'))
>             else:
>                 for start, end in runs:
>                     out.append(f'\x1b[{r+1};{start+1}H')
>                     out.append(curr_row[start:end+1].decode('latin1'))
>
>         out.append('\x1e')
>
>     sys.stdout.write(''.join(out))
>
> if __name__ == '__main__':
>     main()
> EOF
root@f3f8d6319494:/app#
