7 if [ "$FORE" = "" ]; then
10 if [ "$BACK" = "" ]; then
14 # To detect color changes, we want a character that fills the whole cell
15 # if possible. U+2588 is perfect, except that it becomes invisible in the
16 # original xterm, when bolded. For that terminal, use something else, like
18 if [ "$FILL" = "" ]; then
22 # SGR (Select Graphic Rendition)
25 while [ "$1" != "" ]; do
41 # For practical reasons, sandwich black and white in-between the other colors.
42 FORE_COLORS="31 30 37 32 33 34 35 36"
43 BACK_COLORS="41 40 47 42 43 44 45 46"
47 ### Test order of Invert(7) -- it does not matter what order it appears in.
49 # The Red color setting here (31) is shadowed by the green setting (32). The
50 # Reverse flag does not cause (32) to alter the background color immediately;
51 # instead, the Reverse flag is applied once to determine the final effective
53 s 7 31 32; p " -- Should be: $BACK-on-green -- "; s; pn
54 s 31 7 32; p " -- Should be: $BACK-on-green -- "; s; pn
55 s 31 32 7; p " -- Should be: $BACK-on-green -- "; s; pn
57 # As above, but for the background color.
58 s 7 41 42; p " -- Should be: green-on-$FORE -- "; s; pn
59 s 41 7 42; p " -- Should be: green-on-$FORE -- "; s; pn
60 s 41 42 7; p " -- Should be: green-on-$FORE -- "; s; pn
62 # One last, related test
63 s 7; p "Invert text"; s 7 1; p " with some words bold"; s; pn;
64 s 0; p "Normal text"; s 0 1; p " with some words bold"; s; pn;
70 ### Test effect of Bold(1) on color, with and without Invert(7).
72 # The Bold flag does not affect the background color when Reverse is missing.
73 # There should always be 8 colored boxes.
75 for x in $BACK_COLORS; do
76 s $x; p "-"; s $x 1; p "-"
78 s; pn " Bold should not affect background"
80 # On some terminals, Bold affects color, and on some it doesn't. If there
81 # are only 8 colored boxes, then the next two tests will also show 8 colored
82 # boxes. If there are 16 boxes, then exactly one of the next two tests will
85 for x in $FORE_COLORS; do
86 s $x; p "$FILL"; s $x 1; p "$FILL"
88 s; pn " Does bold affect foreground color?"
90 # On some terminals, Bold+Invert highlights the final Background color.
92 for x in $FORE_COLORS; do
93 s $x 7; p "-"; s $x 7 1; p "-"
95 s; pn " Test if Bold+Invert affects background color"
97 # On some terminals, Bold+Invert highlights the final Foreground color.
99 for x in $BACK_COLORS; do
100 s $x 7; p "$FILL"; s $x 7 1; p "$FILL"
102 s; pn " Test if Bold+Invert affects foreground color"
108 ### Test for support of ForeHi and BackHi properties.
112 for x in $FORE_COLORS; do
114 s $x; p "$FILL"; s $hi; p "$FILL"
116 s; pn " Test for support of ForeHi colors"
118 for x in $FORE_COLORS; do
120 s $x; p "$FILL"; s $x $hi; p "$FILL"
122 s; pn " Test for support of ForeHi colors (w/compat)"
126 for x in $BACK_COLORS; do
128 s $x; p "-"; s $hi; p "-"
130 s; pn " Test for support of BackHi colors"
132 for x in $BACK_COLORS; do
134 s $x; p "-"; s $x $hi; p "-"
136 s; pn " Test for support of BackHi colors (w/compat)"
142 ### Identify the default fore and back colors.
144 pn "Match default fore and back colors against 16-color palette"
145 pn " ==fore== ==back=="
146 for fore in $FORE_COLORS; do
147 forehi=$(( $fore + 60 ))
148 back=$(( $fore + 10 ))
149 backhi=$(( $back + 60 ))
151 s $fore; p "$FILL"; s; p "$FILL"; s $fore; p "$FILL"; s; p " "
152 s $forehi; p "$FILL"; s; p "$FILL"; s $forehi; p "$FILL"; s; p " "
153 s $back; p "-"; s; p "-"; s $back; p "-"; s; p " "
154 s $backhi; p "-"; s; p "-"; s $backhi; p "-"; s; p " "
155 pn " $fore $forehi $back $backhi"
162 ### Test coloring of rest-of-line.
165 # When a new line is scrolled in, every cell in the line receives the
166 # current background color, which can be the default/transparent color.
169 p "Newline with red background: usually no red -->"; s 41; pn
170 s; pn "This text is plain, but rest is red if scrolled -->"
171 s; p " "; s 41; printf '\033[1K'; s; printf '\033[1C'; pn "<-- red Erase-in-Line to beginning"
172 s; p "red Erase-in-Line to end -->"; s 41; printf '\033[0K'; s; pn
177 ### Moving the cursor around does not change colors of anything.
179 pn "Test modifying uncolored lines with a colored SGR:"
183 s 31 42; printf '\033[4C\033[3A'; pn "bb"
188 pn "Test modifying colored+inverted+bold line with plain text:"
189 s 42 31 7 1; printf 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\r';
190 s; pn "This text is plain and followed by green-on-red -->"
195 ### Full-width character overwriting
197 pn 'Overwrite part of a full-width char with a half-width char'
198 p 'initial U+4000 ideographs -->'; s 31 42; p '䀀䀀'; s; pn
199 p 'write X to index #1 -->'; s 31 42; p '䀀䀀'; s 35 44; printf '\033[24G'; p X; s; pn
200 p 'write X to index #2 -->'; s 31 42; p '䀀䀀'; s 35 44; printf '\033[25G'; p X; s; pn
201 p 'write X to index #3 -->'; s 31 42; p '䀀䀀'; s 35 44; printf '\033[26G'; p X; s; pn
202 p 'write X to index #4 -->'; s 31 42; p '䀀䀀'; s 35 44; printf '\033[27G'; p X; s; pn
205 pn 'Verify that Erase-in-Line can "fix" last char in line'
206 p 'original -->'; s 31 42; p '䀀䀀'; s; pn
207 p 'overwrite -->'; s 31 42; p '䀀䀀'; s 35 44; printf '\033[30G'; p 'XXX'; s; pn
208 p 'overwrite + Erase-in-Line -->'; s 31 42; p '䀀䀀'; s 35 44; printf '\033[30G'; p 'XXX'; s; printf '\033[0K'; pn
209 p 'original -->'; s 31 42; p 'X䀀䀀'; s; pn
210 p 'overwrite -->'; s 31 42; p 'X䀀䀀'; s 35 44; printf '\033[30G'; p 'ーー'; s; pn
211 p 'overwrite + Erase-in-Line -->'; s 31 42; p 'X䀀䀀'; s 35 44; printf '\033[30G'; p 'ーー'; s; printf '\033[0K'; pn