from PIL import Image, ImageDraw, ImageFont
from pathlib import Path
import textwrap,time,hashlib
root=Path(__file__).parent
font=ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf',20)
for side in ['before','after']:
 lines=[]
 for line in (root/(side+'.txt')).read_text().splitlines():
  lines.extend(textwrap.wrap(line,100,replace_whitespace=False,drop_whitespace=False) or [''])
 def render():
  im=Image.new('RGB',(1280,1050),'#10151e'); d=ImageDraw.Draw(im)
  for n,line in enumerate(lines):
   color='#e0e7ef'
   if line.startswith('$'): color='#86b8ff'
   if line.startswith('exit: 1') or 'InvalidError:' in line: color='#ff9a9a'
   if line.startswith('exit: 0'): color='#9ce3ae'
   d.text((30,24+n*29),line,font=font,fill=color)
  return im
 first=render(); time.sleep(.5); second=render()
 assert first.tobytes()==second.tobytes()
 second.save(root/(side+'.png'))
