from PIL import Image,ImageDraw,ImageFont
from pathlib import Path
import textwrap
root=Path(__file__).parent/'20261126-070254'
font=ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf',18)
for side,sha in [('before','d451c500f5'),('after','8646e82664')]:
 text=(root/(side+'.txt')).read_text()
 blocks=text.split('$ t3 ')
 lines=[side.upper()+'  '+sha,'Linux | source CLI + isolated real server | fresh synthetic data','Replay: command-output | identical commands on both commits','Captured stdout/stderr and exit status; usage help omitted below.','']
 for b in blocks:
  if not b.startswith('thread show'): continue
  if '--json' in b.splitlines()[0]: continue
  if '\nDESCRIPTION\n' in b:
   b=b.split('\nDESCRIPTION\n')[0]+'\n'+b[b.index('ERROR\n'):]
  lines+=textwrap.wrap('$ t3 '+b.splitlines()[0],105)
  for line in b.splitlines()[1:]: lines+=textwrap.wrap(line,105) or ['']
  lines+=['']
 im=Image.new('RGB',(1240,len(lines)*25+48),'#101820');d=ImageDraw.Draw(im)
 for i,line in enumerate(lines):d.text((24,24+i*25),line,font=font,fill='#e7edf4')
 im.save(root/(side+'.png'))
