#!/bin/bash

# Take 80x25 screen shot from the end of a text file, and excape it for html.

process_text_file()
{
  X=0

  # Break into 80 line chunks, substituting &, < and >
  sed -e 's/\(................................................................................\)/\1\n/g' \
      -e 's@\&@\&amp;@g' -e 's@<@\&lt;@g' -e 's@>@\&gt;@g' | \
  tail -n 25 | while read i
  do
    # Grab the first line.  If it's shorter than 80 characters, pad it.
    if [ $X -eq 0 ]
    then
      X=1
      echo -n "$i"
      echo -n "                                                                                " | cut -b 1-$(( 80-$(echo -n "$i" | wc -c) ))
    else
      echo "$i"
    fi
  done
}

for i in $(ls screenshot-*.txt | sed 's/screenshot-\(.*\)\.txt/\1/')
do
  process_text_file < "screenshot-$i.txt" > "screenshot-$i.html"
done



