"Fossies" - the Fresh Open Source Software Archive

Member "xterm-379/vttests/tab0.sh" (25 Apr 2022, 2900 Bytes) of package /linux/misc/xterm-379.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "tab0.sh": 372_vs_373.

    1 #!/bin/sh
    2 # $XTermId: tab0.sh,v 1.6 2022/04/25 22:49:46 tom Exp $
    3 # -----------------------------------------------------------------------------
    4 # Copyright 2019,2022 by Thomas E. Dickey
    5 #
    6 #                         All Rights Reserved
    7 #
    8 # Permission is hereby granted, free of charge, to any person obtaining a
    9 # copy of this software and associated documentation files (the
   10 # "Software"), to deal in the Software without restriction, including
   11 # without limitation the rights to use, copy, modify, merge, publish,
   12 # distribute, sublicense, and/or sell copies of the Software, and to
   13 # permit persons to whom the Software is furnished to do so, subject to
   14 # the following conditions:
   15 #
   16 # The above copyright notice and this permission notice shall be included
   17 # in all copies or substantial portions of the Software.
   18 #
   19 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
   20 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   21 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   22 # IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
   23 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
   24 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
   25 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   26 #
   27 # Except as contained in this notice, the name(s) of the above copyright
   28 # holders shall not be used in advertising or otherwise to promote the
   29 # sale, use or other dealings in this Software without prior written
   30 # authorization.
   31 # -----------------------------------------------------------------------------
   32 # Demonstrate hard-tabs.
   33 
   34 : "${TABS:=tabs}"
   35 : "${TPUT:=tput}"
   36 
   37 show() {
   38     printf "Tabs %s:" "$1"
   39     read -r ignore
   40     p=0
   41     while [ "$p" -lt "$wide" ]
   42     do
   43         printf "%s+----%d" "----" "`expr 1 + \( "$p" / 10 \)`"
   44         p=`expr $p + 10`
   45     done
   46     printf '\n'
   47     p=1
   48     printf " "
   49     while [ "$p" -lt "$wide" ]
   50     do
   51         printf "%*s" "$1" "*"
   52         p=`expr "$p" + "$1"`
   53     done
   54     printf '\n'
   55     p=0
   56     while [ "$p" -lt "$wide" ]
   57     do
   58         printf '\t+'
   59         p=`expr "$p" + "$1"`
   60     done
   61     printf '\n'
   62     printf "...done"
   63     read -r ignore
   64 }
   65 
   66 # enable hard tabs, disable autowrap.
   67 initialize() {
   68     "$TPUT" "$1"
   69     clear
   70     stty tabs
   71     printf '\033[?7l'
   72 }
   73 
   74 setup() {
   75     initialize reset
   76 }
   77 
   78 # Turn hard tabs off, reenable autowrap.
   79 restore() {
   80     stty -tabs
   81     printf '\033[?7h'
   82 }
   83 
   84 wide=`$TPUT cols`
   85 
   86 # If the terminal honors VT100 RIS, try that as a "hard reset" to get the
   87 # power-on behavior.
   88 for name in rs1 rs2
   89 do
   90     value=`$TPUT $name | sed -e 's//ESC:/g'`
   91     case "$value" in
   92     *ESC:c*)
   93         ;;
   94     *)
   95         value=
   96         ;;
   97     esac
   98     if [ -n "$value" ]
   99     then
  100         initialize $name
  101         printf 'Testing after tput %s\r\n' "$name"
  102         show    8
  103         break
  104     fi
  105 done
  106 
  107 # The following tests use the normal "reset" behavior.
  108 setup
  109 $TABS   -8
  110 show    8
  111 $TABS   -4
  112 show    4
  113 
  114 # Some terminal emulators are known to be buggy, and "reset" does not get them
  115 # to reset the tab-stops.
  116 setup
  117 show    8
  118 restore