home *** CD-ROM | disk | FTP | other *** search
/ PC World 2000 February / PCWorld_2000-02_cd.bin / live / usr / share / xterm / vttests / resize.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  1999-09-19  |  1KB  |  75 lines

  1. #!/bin/sh
  2. # $XFree86: xc/programs/xterm/vttests/resize.sh,v 1.2 1999/04/11 13:11:44 dawes Exp $
  3. #
  4. # -- Thomas Dickey (1999/3/27)
  5. # Obtain the current screen size, then resize the terminal to the nominal
  6. # screen width/height, and restore the size.
  7.  
  8. ESC=""
  9. CMD='echo'
  10. OPT='-n'
  11. SUF=''
  12. TMP=/tmp/xterm$$
  13. for verb in print printf ; do
  14.     rm -f $TMP
  15.     eval '$verb "\c" >$TMP || echo fail >$TMP' 2>/dev/null
  16.     if test -f $TMP ; then
  17.     if test ! -s $TMP ; then
  18.         CMD="$verb"
  19.         OPT=
  20.         SUF='\c'
  21.         break
  22.     fi
  23.     fi
  24. done
  25. rm -f $TMP
  26.  
  27. exec </dev/tty
  28. old=`stty -g`
  29. stty raw -echo min 0  time 5
  30.  
  31. $CMD $OPT "${ESC}[18t${SUF}" > /dev/tty
  32. IFS=';' read junk high wide
  33.  
  34. $CMD $OPT "${ESC}[19t${SUF}" > /dev/tty
  35. IFS=';' read junk maxhigh maxwide
  36.  
  37. stty $old
  38.  
  39. wide=`echo $wide|sed -e 's/t.*//'`
  40. maxwide=`echo $maxwide|sed -e 's/t.*//'`
  41. original=${ESC}[8\;${high}\;${wide}t${SUF}
  42.  
  43. test $maxwide = 0 && maxwide=`expr $wide \* 2`
  44. test $maxhigh = 0 && maxhigh=`expr $high \* 2`
  45.  
  46. trap '$CMD $OPT "$original" >/dev/tty; exit' 0 1 2 5 15
  47. w=$wide
  48. h=$high
  49. a=1
  50. while true
  51. do
  52. #    sleep 1
  53.     echo resizing to $h by $w
  54.     $CMD $OPT "${ESC}[8;${h};${w}t" >/dev/tty
  55.     if test $a = 1 ; then
  56.         if test $w = $maxwide ; then
  57.             h=`expr $h + $a`
  58.             if test $h = $maxhigh ; then
  59.                 a=-1
  60.             fi
  61.         else
  62.             w=`expr $w + $a`
  63.         fi
  64.     else
  65.         if test $w = $wide ; then
  66.             h=`expr $h + $a`
  67.             if test $h = $high ; then
  68.                 a=1
  69.             fi
  70.         else
  71.             w=`expr $w + $a`
  72.         fi
  73.     fi
  74. done
  75.