# Two screens, compared a cell at a time: is the second the first, restored? # # Cells rather than pixels, and "ink or no ink" rather than colour, because what is being # checked is that the TEXT came back - a restore that got the map right and the palette wrong # would still be a restore that lost the colours, and that is checked by the colours being # the console's own elsewhere. # # THE ROWS AROUND THE CURSOR ARE ALLOWED TO DIFFER, and they are found rather than guessed at. # The screen is given back and THEN the shell carries on writing to it - a "finished" and a # prompt, two or three lines - so the bottom of what was there is where they land. The cursor # is not near the bottom of the SCREEN, so "the last few rows of the screen" is the wrong # exemption and let a real difference through the first time this ran. # # Everything above that is what the restore is judged on, which here is 25 rows of 28. import sys def cells(path): data = open(path, "rb").read() fields = data.split(b"\n", 3) width, height = (int(n) for n in fields[1].split()) body = fields[3] out = [] for cy in range(height // 8): row = "" for cx in range(width // 8): inked = any( body[((cy * 8 + j) * width + cx * 8 + i) * 3: ((cy * 8 + j) * width + cx * 8 + i) * 3 + 3] != b"\x00\x00\x00" for j in range(8) for i in range(8)) row += "#" if inked else "." out.append(row) return out before, after = cells(sys.argv[1]), cells(sys.argv[2]) if len(before) != len(after): print("the screens are different sizes") sys.exit(0) differ = [n for n, (b, a) in enumerate(zip(before, after)) if b != a] inked = [n for n, row in enumerate(before) if "#" in row] settled = (max(inked) - 3) if inked else 0 early = [n for n in differ if n < settled] if early: print("row %d is not what it was" % early[0]) else: print("yes")