New Terminal Output:

root@d7299c7f5982:/app# cat > /app/termzip_ansi.py << 'EOF'
# Reset cursor tracking for next frame
        cur_row, cur_col = 1, 1

    sys.stdout.buffer.write(output)

if __name__ == '__main__':
    main()
EOF
> #!/usr/bin/env python3
> import struct
> import sys
>
> def read_tza(filename):
>     with open(filename, 'rb') as f:
>         magic = f.read(4)
>         if magic != b'TZA1':
>             raise ValueError(f'Invalid magic: {magic}')
>         width, height = struct.unpack('<HH', f.read(4))
>         n_frames, max_bytes = struct.unpack('<II', f.read(8))
>         frames = []
>         for _ in range(n_frames):
>             frame_data = f.read(width * height)
>             frames.append(frame_data)
>         return width, height, n_frames, max_bytes, frames
>
> def main():
>     if len(sys.argv) != 2:
>         sys.stderr.write(f'Usage: {sys.argv[0]} <frames.tza>\n')
>         sys.exit(1)
>
>     filename = sys.argv[1]
>     width, height, n_frames, max_bytes, frames = read_tza(filename)
>
>     # Previous frame starts as all spaces
>     prev_frame = b' ' * (width * height)
>     output = bytearray()
>
>     # Track cursor position (1-indexed)
>     cur_row, cur_col = 1, 1
>
>     def move_to(row, col):
>         nonlocal cur_row, cur_col, output
>         row, col = row + 1, col + 1  # Convert to 1-indexed
>         if row == cur_row and col == cur_col:
>             return
>         output.extend(b'\x1b[')
>         output.extend(str(row).encode())
>         output.extend(b';')
>         output.extend(str(col).encode())
>         output.extend(b'H')
>         cur_row, cur_col = row, col
>
>     for frame in frames:
>         for r in range(height):
>             row_start = r * width
>             for c in range(width):
>                 pos = row_start + c
>                 if prev_frame[pos] != frame[pos]:
>                     # Move cursor to this position
>                     move_to(r, c)
>                     # Output the character
>                     ch = frame[pos:pos+1]
>                     output.extend(ch)
>                     cur_col += 1
>                     if cur_col > width:
>                         cur_col = 1
>                         cur_row += 1
>         # Frame delimiter
>         output.append(0x1e)
>         prev_frame = frame
>         # Reset cursor tracking for next frame
>         cur_row, cur_col = 1, 1
>
>     sys.stdout.buffer.write(output)
>
> if __name__ == '__main__':
>     main()
> EOF
root@d7299c7f5982:/app# python3 /app/termzip_ansi.py /app/frames.tza | wc -c
302450
root@d7299c7f5982:/app#
