from PIL import Image,ImageDraw,ImageFont
import pathlib,sys,textwrap
run=pathlib.Path(sys.argv[1])
font=ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf',18)
for side in ['before','after']:
 text=(run/(side+'.txt')).read_text().split('\n$ /opt/T3')[0]
 lines=[]
 for line in text.splitlines():
  if line.startswith('Depends: '):
   line='Generated libc6 dependency: '+line.split(', ')[-1]
  lines.extend(textwrap.wrap(line,width=112,replace_whitespace=False,drop_whitespace=False) or [''])
 im=Image.new('RGB',(1320,1160),'#111827'); d=ImageDraw.Draw(im)
 d.text((28,20),side.upper()+' — captured packaging and Ubuntu 22.04 installer output',font=font,fill='#ffffff')
 for i,line in enumerate(lines):
  color='#d1d5db'
  if '2.39' in line or 'unpacked' in line or 'dependency problems' in line: color='#fbbf24'
  if 'install ok installed' in line or 'exit status: 0' in line: color='#86efac'
  d.text((28,65+i*26),line,font=font,fill=color)
 im.save(run/(side+'.png'))
