1f2e35a3aSmrg#!/bin/sh
204b94745Smrg# $XTermId: other-sgr.sh,v 1.9 2022/04/24 23:36:20 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=''
415307cd1aSmrg: "${TMPDIR=/tmp}"
425307cd1aSmrgTMP=`(mktemp "$TMPDIR/xterm.XXXXXXXX") 2>/dev/null` || TMP="$TMPDIR/xterm$$"
43f2e35a3aSmrgeval '$CMD $OPT >$TMP || echo fail >$TMP' 2>/dev/null
445307cd1aSmrg{ test ! -f "$TMP" || test -s "$TMP"; } &&
45ad37e533Smrgfor verb in "printf" "print" ; do
465307cd1aSmrg    rm -f "$TMP"
47f2e35a3aSmrg    eval '$verb "\c" >$TMP || echo fail >$TMP' 2>/dev/null
485307cd1aSmrg    if test -f "$TMP" ; then
495307cd1aSmrg	if test ! -s "$TMP" ; then
50f2e35a3aSmrg	    CMD="$verb"
51f2e35a3aSmrg	    OPT=
52f2e35a3aSmrg	    SUF='\c'
53f2e35a3aSmrg	    break
54f2e35a3aSmrg	fi
55f2e35a3aSmrg    fi
56f2e35a3aSmrgdone
575307cd1aSmrgrm -f "$TMP"
58f2e35a3aSmrg
594419d26bSmrgtrap '$CMD $OPT "${CSI}0m"; exit 1' 1 2 3 15
604419d26bSmrgtrap '$CMD $OPT "${CSI}0m"' 0
61f2e35a3aSmrg
62ad37e533Smrgecho "${CSI}0m"
63f2e35a3aSmrgwhile true
64f2e35a3aSmrgdo
65f2e35a3aSmrg    # blink(5) and conceal(8) are omitted because they are distracting, but the
66f2e35a3aSmrg    # case-statement handles those if the for-statement includes them.
67f2e35a3aSmrg    for GRP in 0 1 4 7
68f2e35a3aSmrg    do
69f2e35a3aSmrg	case $GRP in
70f2e35a3aSmrg	0) attr="normal  ";;
71f2e35a3aSmrg	1) attr="bold    ";;
72f2e35a3aSmrg	4) attr="under   ";;
73f2e35a3aSmrg	5) attr="blink   ";;
74f2e35a3aSmrg	7) attr="reverse ";;
75f2e35a3aSmrg	8) attr="conceal ";;
76f2e35a3aSmrg	esac
77f2e35a3aSmrg	for NUL in "0" "21"
78f2e35a3aSmrg	do
79f2e35a3aSmrg	    for ROW in $NUL "2" "3" "9" "2;3" "2;9" "3;9" "2;3;9"
80f2e35a3aSmrg	    do
81f2e35a3aSmrg		case $ROW in
82f2e35a3aSmrg		"0")     rlabel="normal  ";;
83f2e35a3aSmrg		"21")    rlabel="double  ";;
84f2e35a3aSmrg		"2")     rlabel="dim     ";;
85f2e35a3aSmrg		"3")     rlabel="italic  ";;
86f2e35a3aSmrg		"2;3")   rlabel="di/it   ";;
87f2e35a3aSmrg		"9")     rlabel="crossout";;
88f2e35a3aSmrg		"2;9")   rlabel="di/cr   ";;
89f2e35a3aSmrg		"3;9")   rlabel="it/cr   ";;
90f2e35a3aSmrg		"2;3;9") rlabel="di/it/cr";;
91f2e35a3aSmrg		*)       rlabel="UNKNOWN ";;
92f2e35a3aSmrg		esac
93f2e35a3aSmrg		# video attributes from the first two columns intentionally
94f2e35a3aSmrg		# "bleed through" to the other columns to help show some of
95f2e35a3aSmrg		# the possible combinations of attributes.
96ad37e533Smrg		$CMD $OPT "$GRP:${CSI}${GRP}m$attr${SUF}"
97ad37e533Smrg		$CMD $OPT "${CSI}${ROW}m$rlabel${SUF}"
98f2e35a3aSmrg		for COL in $NUL "3" "9" "2;3" "2;9" "3;9" "2;3;9"
99f2e35a3aSmrg		do
100f2e35a3aSmrg		    END=""
101f2e35a3aSmrg		    case $COL in
102f2e35a3aSmrg		    "0")     clabel="normal  ";;
103ad37e533Smrg		    "21")    clabel="double  "; END="${CSI}24m";;
104ad37e533Smrg		    "2")     clabel="dim     "; END="${CSI}22m";;
105ad37e533Smrg		    "3")     clabel="italic  "; END="${CSI}23m";;
106ad37e533Smrg		    "2;3")   clabel="di/it   "; END="${CSI}22;23m";;
107ad37e533Smrg		    "9")     clabel="crossout"; END="${CSI}29m";;
108ad37e533Smrg		    "2;9")   clabel="di/cr   "; END="${CSI}22;29m";;
109ad37e533Smrg		    "3;9")   clabel="it/cr   "; END="${CSI}23;29m";;
110ad37e533Smrg		    "2;3;9") clabel="di/it/cr"; END="${CSI}23;29m";;
111f2e35a3aSmrg		    *)       clabel="UNKNOWN ";;
112f2e35a3aSmrg		    esac
113f2e35a3aSmrg		    # The remaining columns (try to) reset their respective
114f2e35a3aSmrg		    # attribute, to make the result somewhat readable.
115ad37e533Smrg		    $CMD $OPT "${CSI}${COL}m$clabel${END}${SUF}"
116f2e35a3aSmrg		done
117ad37e533Smrg		echo "${CSI}0m:$GRP"
118f2e35a3aSmrg	    done
119f2e35a3aSmrg	done
120f2e35a3aSmrg	[ -t 1 ] && sleep 3
121f2e35a3aSmrg    done
122f2e35a3aSmrg    [ -t 1 ] || break
123f2e35a3aSmrgdone
124