from PIL import Image, ImageDraw, ImageFont
import pathlib,sys
root=pathlib.Path(__file__).parent
font=ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf',19)
for side in ['before','after']:
 run=sorted(root.glob(side+'-*'))[-1]
 lines=(run/'transcript.txt').read_text().splitlines()
 lines=[line for line in lines if not line.startswith('$ t3 workflow list --tag pr --json') and not line.startswith('[{') and line != '[]']
 image=Image.new('RGB',(1500,1000),'#10151d'); draw=ImageDraw.Draw(image)
 draw.text((30,22),side.upper()+' | Real server + CLI | 501 workflow runs',font=font,fill='#9ed7ff')
 for i,line in enumerate(lines):
  color='#8ce5b5' if line.startswith('$') else '#e7edf5'
  draw.text((30,70+i*29),line,font=font,fill=color)
 image.save(root/(side+'.png'))
