"""Render captured CLI transcripts as images, preserving literal JSON escapes."""
from pathlib import Path
from PIL import Image, ImageDraw, ImageFont
import sys,textwrap
root=Path(sys.argv[1])
font=ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf',18)
for side in ['base','head']:
    text='\n'.join('\n'.join(textwrap.wrap(line,112,replace_whitespace=False,drop_whitespace=False)) if line else '' for line in (root/side/'transcript.txt').read_text().splitlines())
    lines=text.splitlines()
    image=Image.new('RGB',(1280,56+27*len(lines)),'#111827')
    draw=ImageDraw.Draw(image)
    for i,line in enumerate(lines): draw.text((28,28+27*i),line,font=font,fill='#e5e7eb')
    image.save(root/side/'transcript.png')
