tab0.sh revision a5ae21e4
1a5ae21e4Smrg#!/bin/sh 2a5ae21e4Smrg# $XTermId: tab0.sh,v 1.2 2019/06/01 16:03:03 tom Exp $ 3a5ae21e4Smrg# ----------------------------------------------------------------------------- 4a5ae21e4Smrg# Copyright 2019 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 34a5ae21e4Smrg: ${TABS:=tabs} 35a5ae21e4Smrg: ${TPUT:=tput} 36a5ae21e4Smrg 37a5ae21e4Smrgshow() { 38a5ae21e4Smrg printf "Tabs $1:" 39a5ae21e4Smrg read ignore 40a5ae21e4Smrg p=0 41a5ae21e4Smrg while [ $p -lt $wide ] 42a5ae21e4Smrg do 43a5ae21e4Smrg printf "%s+----%d" "----" `expr 1 + \( $p / 10 \)` 44a5ae21e4Smrg p=`expr $p + 10` 45a5ae21e4Smrg done 46a5ae21e4Smrg printf "\n" 47a5ae21e4Smrg p=1 48a5ae21e4Smrg printf " " 49a5ae21e4Smrg while [ $p -lt $wide ] 50a5ae21e4Smrg do 51a5ae21e4Smrg printf "%*s" $1 "*" 52a5ae21e4Smrg p=`expr $p + $1` 53a5ae21e4Smrg done 54a5ae21e4Smrg printf "\n" 55a5ae21e4Smrg p=0 56a5ae21e4Smrg while [ $p -lt $wide ] 57a5ae21e4Smrg do 58a5ae21e4Smrg printf "\t+" 59a5ae21e4Smrg p=`expr $p + $1` 60a5ae21e4Smrg done 61a5ae21e4Smrg printf "\n" 62a5ae21e4Smrg printf "...done" 63a5ae21e4Smrg read ignore 64a5ae21e4Smrg} 65a5ae21e4Smrg 66a5ae21e4Smrg# enable hard tabs, disable autowrap. 67a5ae21e4Smrginitialize() { 68a5ae21e4Smrg $TPUT $1 69a5ae21e4Smrg clear 70a5ae21e4Smrg stty tabs 71a5ae21e4Smrg printf "\033[?7l" 72a5ae21e4Smrg} 73a5ae21e4Smrg 74a5ae21e4Smrgsetup() { 75a5ae21e4Smrg initialize reset 76a5ae21e4Smrg} 77a5ae21e4Smrg 78a5ae21e4Smrg# Turn hard tabs off, reenable autowrap. 79a5ae21e4Smrgrestore() { 80a5ae21e4Smrg stty -tabs 81a5ae21e4Smrg 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 101a5ae21e4Smrg printf "Testing after tput $name\r\n" 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