#!/bin/bash

#  This script demonstrates a bug in vte. Invoking it without the
#  "-e" parameter causes the status line not to be updated. "-e"
#  inserts a "el" terminal capability string (clear to eol) which
#  makes the symptom go away.
#  
#  Running the script under xterm always succeeds, regardless of any
#  "-e" parameter.
#
# tput capabilities used:
#    init
#    clear
#    csr        change_scroll_region  line1 line2
#    cup        cursor_address        row column
#    el         clr_eol
#    smso       enter_standout_mode
#    cr         carriage_return
#    cuu1       cursor_up
#    rmso       exit_standout_mode
#    ind        scroll_forward


tput init                     # figure out the screen size
LINES=`tput lines`
COLUMNS=`tput cols`
DO_EL=false
DO_SLOW=false
while getopts "se" optname ; do
  case "$optname" in
    "e")
      DO_EL=true
      ;;
    "s")
      DO_SLOW=true
      ;;
  esac
done
tput clear
BOTTOM_LINE=$((LINES-1))
NMINUS1LINE=$((BOTTOM_LINE-1))
tput csr 0 $NMINUS1LINE        # create scroll region, all but last line
tput cup $NMINUS1LINE 0        # goto bottom line of scroll region.
tput ind                       # scroll forward 1 line
tput csr 0 $((LINES-1))        # create scroll region, full screen
tput cup $NMINUS1LINE 0        # goto next-to-last line
printf '%b' 'These are not the droids you are looking for.'
$DO_SLOW && sleep 1
tput cup $BOTTOM_LINE 0
printf '%b' 'Move along, citizen (a).' # NO OUTPUT!
sleep 2
tput cup $BOTTOM_LINE 0
tput el
printf '%b' 'Move along, citizen (b).' # NO OUTPUT!
sleep 2
tput csr 0 $((LINES-1))      # set scroll region to whole window
tput cup $BOTTOM_LINE 0      # goto bottom line
tput ind                     # scroll forward

