#!/bin/ksh


USAGE="Usage: $arg0 [-h] [-d delay_secs] command_string"

usage()
{
  echo "$USAGE" >&2
  exit 1
}

help()
{
  echo "$USAGE"
  echo "Options:"
  echo "        -h      Display this help"
  echo "        -d      Time to delay between running the command"
  echo "        -n      No Bolding"
  exit
}

delay=2
bolding=yes

while getopts "d:hn" opt
do
  case "$opt" in
    d)  delay=$OPTARG
        ;;
    n)  bolding=''
        ;;
    h)  help
        ;;
    *)  usage
        ;;
  esac
done

OPTIND=`expr $OPTIND - 1`
shift $OPTIND

EL=`tput el || tput ce`
ED=`tput ed || tput cd`
THOME=`tput home`

if [ "$bolding" = yes ]
then
  SMSO=`tput smso`
  RMSO=`tput rmso`
else
  SMSO=''
  RMSO=''
fi

tput clear

while true
do
  line_no=0
  NL="$THOME"
  echo "$THOME\c"
  eval "$@" |
   while IFS='' read line
   do
    if [ -z "${prev_line[$line_no]}" ]
    then
      prev_line[$line_no]="$line"
    fi
    if [ "x$line" = "x${prev_line[$line_no]}" ]
    then
      print -nr "$NL$EL$line$EL"
    else
      print -nr "$NL$EL$SMSO$line$EL$RMSO"
    fi
    NL="
"
    prev_line[$line_no]="$line"
    let line_no=line_no+1
   done
  if [ $line_no -eq 0 ]
  then
    echo "    ---===${SMSO} No Output ${RMSO}===---    $EL\c"
  fi
  echo "$ED\c"
  sleep $delay
done