from PIL import Image,ImageDraw,ImageFont
from pathlib import Path
import textwrap,time
root=Path(__file__).parent
font=ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf',18)
for side,folder in [('before','before-20261127-163011'),('after','after-20261127-163033')]:
 text=(root/folder/'capture.txt').read_text()
 lines=[]
 for line in text.splitlines(): lines.extend(textwrap.wrap(line,100,replace_whitespace=False) or [''])
 im=Image.new('RGB',(1200,1060),'#10151e');d=ImageDraw.Draw(im)
 d.text((28,22),'CAPTURED CLI OUTPUT — '+side.upper(),font=font,fill='#9dc6ff')
 for i,line in enumerate(lines):
  color='#ffaca5' if line.startswith('No T3') or line=='exit 1' else '#9ee0b0' if line in ['[]','exit 0'] else '#e5e9ef'
  d.text((28,65+i*27),line,font=font,fill=color)
 im.save(root/(side+'.png'))
 time.sleep(.5)
 im.save(root/(side+'-stable.png'))
 assert (root/(side+'.png')).read_bytes()==(root/(side+'-stable.png')).read_bytes()
