tab0.sh revision a5ae21e4
1#!/bin/sh
2# $XTermId: tab0.sh,v 1.2 2019/06/01 16:03:03 tom Exp $
3# -----------------------------------------------------------------------------
4# Copyright 2019 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
37show() {
38	printf "Tabs $1:"
39	read 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 ignore
64}
65
66# enable hard tabs, disable autowrap.
67initialize() {
68	$TPUT $1
69	clear
70	stty tabs
71	printf "\033[?7l"
72}
73
74setup() {
75	initialize reset
76}
77
78# Turn hard tabs off, reenable autowrap.
79restore() {
80	stty -tabs
81	printf "\033[?7h"
82}
83
84wide=`$TPUT cols`
85
86# If the terminal honors VT100 RIS, try that as a "hard reset" to get the
87# power-on behavior.
88for name in rs1 rs2
89do
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 $name\r\n"
102		show	8
103		break
104	fi
105done
106
107# The following tests use the normal "reset" behavior.
108setup
109$TABS	-8
110show	8
111$TABS	-4
112show	4
113
114# Some terminal emulators are known to be buggy, and "reset" does not get them
115# to reset the tab-stops.
116setup
117show	8
118restore
119