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