other-sgr.sh revision 4419d26b
1f2e35a3aSmrg#!/bin/sh 24419d26bSmrg# $XTermId: other-sgr.sh,v 1.7 2022/02/13 14:36:10 tom Exp $ 3f2e35a3aSmrg# ----------------------------------------------------------------------------- 4f2e35a3aSmrg# this file is part of xterm 5f2e35a3aSmrg# 64419d26bSmrg# Copyright 2018-2021,2022 by Thomas E. Dickey 7f2e35a3aSmrg# 8f2e35a3aSmrg# All Rights Reserved 9f2e35a3aSmrg# 10f2e35a3aSmrg# Permission is hereby granted, free of charge, to any person obtaining a 11f2e35a3aSmrg# copy of this software and associated documentation files (the 12f2e35a3aSmrg# "Software"), to deal in the Software without restriction, including 13f2e35a3aSmrg# without limitation the rights to use, copy, modify, merge, publish, 14f2e35a3aSmrg# distribute, sublicense, and/or sell copies of the Software, and to 15f2e35a3aSmrg# permit persons to whom the Software is furnished to do so, subject to 16f2e35a3aSmrg# the following conditions: 17f2e35a3aSmrg# 18f2e35a3aSmrg# The above copyright notice and this permission notice shall be included 19f2e35a3aSmrg# in all copies or substantial portions of the Software. 20f2e35a3aSmrg# 21f2e35a3aSmrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 22f2e35a3aSmrg# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23f2e35a3aSmrg# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 24f2e35a3aSmrg# IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY 25f2e35a3aSmrg# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 26f2e35a3aSmrg# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 27f2e35a3aSmrg# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28f2e35a3aSmrg# 29f2e35a3aSmrg# Except as contained in this notice, the name(s) of the above copyright 30f2e35a3aSmrg# holders shall not be used in advertising or otherwise to promote the 31f2e35a3aSmrg# sale, use or other dealings in this Software without prior written 32f2e35a3aSmrg# authorization. 33f2e35a3aSmrg# ----------------------------------------------------------------------------- 34f2e35a3aSmrg# Show non-VTxx SGRs combined with the conventional VT100/VT220 SGRs 35f2e35a3aSmrg 36f2e35a3aSmrgESC="" 37ad37e533SmrgCSI="${ESC}[" 38f2e35a3aSmrgCMD='/bin/echo' 39f2e35a3aSmrgOPT='-n' 40f2e35a3aSmrgSUF='' 41ad37e533SmrgTMP=`(mktemp) 2>/dev/null` || TMP=/tmp/xterm$$ 42f2e35a3aSmrgeval '$CMD $OPT >$TMP || echo fail >$TMP' 2>/dev/null 43ad37e533Smrg{ test ! -f $TMP || test -s $TMP; } && 44ad37e533Smrgfor verb in "printf" "print" ; do 45f2e35a3aSmrg rm -f $TMP 46f2e35a3aSmrg eval '$verb "\c" >$TMP || echo fail >$TMP' 2>/dev/null 47f2e35a3aSmrg if test -f $TMP ; then 48f2e35a3aSmrg if test ! -s $TMP ; then 49f2e35a3aSmrg CMD="$verb" 50f2e35a3aSmrg OPT= 51f2e35a3aSmrg SUF='\c' 52f2e35a3aSmrg break 53f2e35a3aSmrg fi 54f2e35a3aSmrg fi 55f2e35a3aSmrgdone 56f2e35a3aSmrgrm -f $TMP 57f2e35a3aSmrg 584419d26bSmrgtrap '$CMD $OPT "${CSI}0m"; exit 1' 1 2 3 15 594419d26bSmrgtrap '$CMD $OPT "${CSI}0m"' 0 60f2e35a3aSmrg 61ad37e533Smrgecho "${CSI}0m" 62f2e35a3aSmrgwhile true 63f2e35a3aSmrgdo 64f2e35a3aSmrg # blink(5) and conceal(8) are omitted because they are distracting, but the 65f2e35a3aSmrg # case-statement handles those if the for-statement includes them. 66f2e35a3aSmrg for GRP in 0 1 4 7 67f2e35a3aSmrg do 68f2e35a3aSmrg case $GRP in 69f2e35a3aSmrg 0) attr="normal ";; 70f2e35a3aSmrg 1) attr="bold ";; 71f2e35a3aSmrg 4) attr="under ";; 72f2e35a3aSmrg 5) attr="blink ";; 73f2e35a3aSmrg 7) attr="reverse ";; 74f2e35a3aSmrg 8) attr="conceal ";; 75f2e35a3aSmrg esac 76f2e35a3aSmrg for NUL in "0" "21" 77f2e35a3aSmrg do 78f2e35a3aSmrg for ROW in $NUL "2" "3" "9" "2;3" "2;9" "3;9" "2;3;9" 79f2e35a3aSmrg do 80f2e35a3aSmrg case $ROW in 81f2e35a3aSmrg "0") rlabel="normal ";; 82f2e35a3aSmrg "21") rlabel="double ";; 83f2e35a3aSmrg "2") rlabel="dim ";; 84f2e35a3aSmrg "3") rlabel="italic ";; 85f2e35a3aSmrg "2;3") rlabel="di/it ";; 86f2e35a3aSmrg "9") rlabel="crossout";; 87f2e35a3aSmrg "2;9") rlabel="di/cr ";; 88f2e35a3aSmrg "3;9") rlabel="it/cr ";; 89f2e35a3aSmrg "2;3;9") rlabel="di/it/cr";; 90f2e35a3aSmrg *) rlabel="UNKNOWN ";; 91f2e35a3aSmrg esac 92f2e35a3aSmrg # video attributes from the first two columns intentionally 93f2e35a3aSmrg # "bleed through" to the other columns to help show some of 94f2e35a3aSmrg # the possible combinations of attributes. 95ad37e533Smrg $CMD $OPT "$GRP:${CSI}${GRP}m$attr${SUF}" 96ad37e533Smrg $CMD $OPT "${CSI}${ROW}m$rlabel${SUF}" 97f2e35a3aSmrg for COL in $NUL "3" "9" "2;3" "2;9" "3;9" "2;3;9" 98f2e35a3aSmrg do 99f2e35a3aSmrg END="" 100f2e35a3aSmrg case $COL in 101f2e35a3aSmrg "0") clabel="normal ";; 102ad37e533Smrg "21") clabel="double "; END="${CSI}24m";; 103ad37e533Smrg "2") clabel="dim "; END="${CSI}22m";; 104ad37e533Smrg "3") clabel="italic "; END="${CSI}23m";; 105ad37e533Smrg "2;3") clabel="di/it "; END="${CSI}22;23m";; 106ad37e533Smrg "9") clabel="crossout"; END="${CSI}29m";; 107ad37e533Smrg "2;9") clabel="di/cr "; END="${CSI}22;29m";; 108ad37e533Smrg "3;9") clabel="it/cr "; END="${CSI}23;29m";; 109ad37e533Smrg "2;3;9") clabel="di/it/cr"; END="${CSI}23;29m";; 110f2e35a3aSmrg *) clabel="UNKNOWN ";; 111f2e35a3aSmrg esac 112f2e35a3aSmrg # The remaining columns (try to) reset their respective 113f2e35a3aSmrg # attribute, to make the result somewhat readable. 114ad37e533Smrg $CMD $OPT "${CSI}${COL}m$clabel${END}${SUF}" 115f2e35a3aSmrg done 116ad37e533Smrg echo "${CSI}0m:$GRP" 117f2e35a3aSmrg done 118f2e35a3aSmrg done 119f2e35a3aSmrg [ -t 1 ] && sleep 3 120f2e35a3aSmrg done 121f2e35a3aSmrg [ -t 1 ] || break 122f2e35a3aSmrgdone 123