installed pty
[VSoRC/.git] / node_modules / node-pty / deps / winpty / misc / color-test.sh
1 #!/bin/bash
2
3 FORE=$1
4 BACK=$2
5 FILL=$3
6
7 if [ "$FORE" = "" ]; then
8     FORE=DefaultFore
9 fi
10 if [ "$BACK" = "" ]; then
11     BACK=DefaultBack
12 fi
13
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
17 # "#" or "@".
18 if [ "$FILL" = "" ]; then
19     FILL="█"
20 fi
21
22 # SGR (Select Graphic Rendition)
23 s() {
24     printf '\033[0m'
25     while [ "$1" != "" ]; do
26         printf '\033['"$1"'m'
27         shift
28     done
29 }
30
31 # Print
32 p() {
33     echo -n "$@"
34 }
35
36 # Print with newline
37 pn() {
38     echo "$@"
39 }
40
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"
44
45
46
47 ### Test order of Invert(7) -- it does not matter what order it appears in.
48
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
52 # Fore/Back colors.
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
56
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
61
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;
65
66 pn
67
68
69
70 ### Test effect of Bold(1) on color, with and without Invert(7).
71
72 # The Bold flag does not affect the background color when Reverse is missing.
73 # There should always be 8 colored boxes.
74 p "  "
75 for x in $BACK_COLORS; do
76     s $x; p "-"; s $x 1; p "-"
77 done
78 s; pn "    Bold should not affect background"
79
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
83 # also have 16 boxes.
84 p "  "
85 for x in $FORE_COLORS; do
86     s $x; p "$FILL"; s $x 1; p "$FILL"
87 done
88 s; pn "    Does bold affect foreground color?"
89
90 # On some terminals, Bold+Invert highlights the final Background color.
91 p "  "
92 for x in $FORE_COLORS; do
93     s $x 7; p "-"; s $x 7 1; p "-"
94 done
95 s; pn "    Test if Bold+Invert affects background color"
96
97 # On some terminals, Bold+Invert highlights the final Foreground color.
98 p "  "
99 for x in $BACK_COLORS; do
100     s $x 7; p "$FILL"; s $x 7 1; p "$FILL"
101 done
102 s; pn "    Test if Bold+Invert affects foreground color"
103
104 pn
105
106
107
108 ### Test for support of ForeHi and BackHi properties.
109
110 # ForeHi
111 p "  "
112 for x in $FORE_COLORS; do
113     hi=$(( $x + 60 ))
114     s $x; p "$FILL"; s $hi; p "$FILL"
115 done
116 s; pn "    Test for support of ForeHi colors"
117 p "  "
118 for x in $FORE_COLORS; do
119     hi=$(( $x + 60 ))
120     s $x; p "$FILL"; s $x $hi; p "$FILL"
121 done
122 s; pn "    Test for support of ForeHi colors (w/compat)"
123
124 # BackHi
125 p "  "
126 for x in $BACK_COLORS; do
127     hi=$(( $x + 60 ))
128     s $x; p "-"; s $hi; p "-"
129 done
130 s; pn "    Test for support of BackHi colors"
131 p "  "
132 for x in $BACK_COLORS; do
133     hi=$(( $x + 60 ))
134     s $x; p "-"; s $x $hi; p "-"
135 done
136 s; pn "    Test for support of BackHi colors (w/compat)"
137
138 pn
139
140
141
142 ### Identify the default fore and back colors.
143
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 ))
150     p "  "
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"
156 done
157
158 pn
159
160
161
162 ### Test coloring of rest-of-line.
163
164 #
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.
167 #
168
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
173 pn
174
175
176
177 ### Moving the cursor around does not change colors of anything.
178
179 pn "Test modifying uncolored lines with a colored SGR:"
180 pn "aaaa"
181 pn
182 pn "____e"
183 s 31 42; printf '\033[4C\033[3A'; pn "bb"
184 pn "cccc"
185 pn "dddd"
186 s; pn
187
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 -->"
191 pn
192
193
194
195 ### Full-width character overwriting
196
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
203 pn
204
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
212 pn