Develop and Download Open Source Software

Browse Subversion Repository

Contents of /branches/ttcomtester/tests/color-sgr-decscnm.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10521 - (show annotations) (download) (as text)
Fri Jan 20 16:03:38 2023 UTC (14 months, 3 weeks ago) by zmatsuo
File MIME type: text/x-perl
File size: 6421 byte(s)
add communication test tool
1 #!/usr/bin/perl
2
3 use utf8;
4 use strict;
5 use warnings;
6 use Class::Struct;
7
8 local $| = 1;
9
10 sub Pause {
11 printf("pause(hit enter)\n");
12 <STDIN>;
13 }
14
15 sub ShowAttributesSGR {
16 my @AttrTestsSGR = (
17 {
18 Enter => "\x1b[0m",
19 Str => "Normal / SGR 0",
20 },
21 {
22 Enter => "\x1b[39m\x1b[49m",
23 Str => "Normal / SGR 39, 49",
24 },
25 {
26 Enter => "\x1b[1m",
27 Str => "Bold / SGR 1",
28 },
29 {
30 Enter => "\x1b[4m",
31 Str => "Underline / SGR 4",
32 },
33 {
34 Enter => "\x1b[5m",
35 Str => "Blink(Slow blink) / SGR 5",
36 },
37 {
38 Enter => "\x1b[7m",
39 Str => "Reverse / SGR 7",
40 },
41 {
42 Enter => "\x1b[0m",
43 Str => "https://ttssh2.osdn.jp/ SGR 0(Normal) + URL string",
44 },
45 {
46 Enter => "\x1b[0m\x1b[31m",
47 Str => "FG Red / SGR 0 + SGR 31(FG Red)",
48 },
49 {
50 Enter => "\x1b[0m\x1b[42m",
51 Str => "BG Red / SGR 0 + SGR 42(BG Green)",
52 },
53 {
54 Enter => "\x1b[31m\x1b[42m",
55 Str => "FG Red + BG Green / SGR 31(FG Red) + SGR 42(BG Green)",
56 },
57 {
58 Enter => "\x1b[7m\x1b[31m\x1b[42m",
59 Str => "Reverse / SGR 7 + SGR 31(FG Red) + SGR 42(BG Green)",
60 },
61 {
62 Enter => "\x1b[1m\x1b[41m",
63 Str => "BOLD + BG RED / SGR 1 + SGR 41(BG Red)",
64 },
65 {
66 Enter => "\x1b[5m\x1b[46m",
67 Str => "Blink(Slow blink) / SGR 5 + SGR 46(BG Cyan)",
68 },
69 {
70 Enter => "\x1b[5m\x1b[106m",
71 Str => "Blink(Slow blink) / SGR 5 + SGR 106(BG Bright Cyan)",
72 },
73 {
74 Enter => "\x1b[4m\x1b[44m",
75 Str => "Underline / SGR 4 + SGR 44(BG Blue)",
76 },
77 {
78 Enter => "\x1b[4m\x1b[104m",
79 Str => "Underline / SGR 4 + SGR 104(BG Bright Blue)",
80 },
81 {
82 Enter => "\x1b[30m\x1b[40m",
83 Str => "Black+Black / SGR 30 + SGR 40 (FG&BG Black)",
84 },
85 {
86 Enter => "\x1b[37m\x1b[47m",
87 Str => "White+White(8) / SGR 37 + SGR 47 (FG&BG White(8color)/Gray(16,256color))",
88 },
89 {
90 Enter => "\x1b[97m\x1b[107m",
91 Str => "White+White / SGR 97 + SGR 107 (FG&BG White(16,256color))",
92 }
93 );
94
95 print "\x1b[0m";
96 print "==================== support attributes\n";
97 for my $i (0 .. $#AttrTestsSGR) {
98 print "$AttrTestsSGR[$i]{Enter}";
99 printf("%02d ", $i);
100 print "$AttrTestsSGR[$i]{Str}";
101 print "\x1b[0m\n";
102 }
103 }
104
105 sub ShowAttributesREVERSE {
106 my @AttrTestsReverse = (
107 {
108 Enter => "\x1b[0m",
109 Str => "Normal / SGR 0",
110 },
111 {
112 Enter => "\x1b[7m",
113 Str => "Reverse / + SGR 7",
114 },
115 {
116 Enter => "\x1b[32m",
117 Str => "FG ANSIGreen / SGR 32(FG ANSIGreen)",
118 },
119 {
120 Enter => "\x1b[32m\x1b[7m",
121 Str => "FG ANSIGreen + R / + SGR 7",
122 },
123 {
124 Enter => "\x1b[41m",
125 Str => "BG ANSIRed / SGR 41(BG ANSIRed)",
126 },
127 {
128 Enter => "\x1b[41m\x1b[7m",
129 Str => "BG ANSIRed + R / + SGR 7",
130 },
131 {
132 Enter => "\x1b[32m\x1b[41m",
133 Str => "FG ANSIGreed + BG ANSIRed / SGR 32 + SGR 41(FG ANSIGreen + FG ANSIRed)",
134 },
135 {
136 Enter => "\x1b[32m\x1b[41m\x1b[7m",
137 Str => "FG ANSIGreed + BG ANSIRed + R / + SGR 7",
138 },
139 );
140 print "\x1b[0m";
141 print "==================== reverse test\n";
142 for my $i (0 .. $#AttrTestsReverse) {
143 print "$AttrTestsReverse[$i]{Enter}";
144 printf("%02d ", $i);
145 print "$AttrTestsReverse[$i]{Str}";
146 print "\x1b[0m\n";
147 }
148 }
149
150 sub ShowANSIColor {
151 print "==================== ANSI color\n";
152
153 print "\x1b[0m";
154
155 print "3bit(8) Standard color / 4bit(16) Darker color\n";
156 print " FG: SGR 30..37 m BG: SGR 40..47 m\n";
157 for (my $f = 0; $f < 8; $f++) {
158 for (my $b = 0; $b < 8; $b++) {
159 printf("\x1b[%d;%dm %3d/%3d ", $f + 30, $b + 40, $f + 30, $b + 40);
160 }
161 print "\x1b[0m";
162 print "\n";
163 }
164 print "\x1b[0m";
165 print "\n";
166
167 if (1) {
168 print "aixterm 4bit(16) bright color\n";
169 print " FG: SGR 90..97 m BG: SGR 100..107 m\n";
170 for (my $f = 0; $f < 8; $f++) {
171 for (my $b = 0; $b < 8; $b++) {
172 printf("\x1b[%d;%dm %3d/%3d ", $f + 90, $b + 100, $f + 90 , $b + 100);
173 }
174 print "\x1b[0m";
175 print "\n";
176 }
177 }
178
179 if (1) {
180 print "PC-Style 4bit(16) bright color\n";
181 print " FG: SGR 30..37 m BG: SGR 40..47 m\n";
182 for (my $f = 0; $f < 8; $f++) {
183 for (my $b = 0; $b < 8; $b++) {
184 print "\x1b[1m"; # Bold (SGR 1) bright color fore
185 print "\x1b[5m"; # Blink (SGR 5) bright color back
186 printf("\x1b[%d;%dm %3d/%3d ", $f + 30, $b + 40, $f + 30, $b + 40);
187 }
188 print "\x1b[0m";
189 print "\n";
190 }
191 print "\x1b[0m";
192 print "\n";
193 }
194
195 if (1) {
196 print "PC 4bit(16) color\n";
197 print " FG: SGR 38 ; 5 ; n m BG: 48 ; 5 ; n m (256color only)\n";
198 for (my $f = 0; $f < 8; $f++) {
199 for ($b = 0; $b < 8; $b++) {
200 printf("\x1b[38;5;%dm\x1b[48;5;%dm %3d/%3d ", $f, $b, $f, $b);
201 }
202 print "\x1b[0m";
203 print "\n";
204 }
205 for (my $f = 0; $f < 8; $f++) {
206 for (my $b = 0; $b < 8; $b++) {
207 printf("\x1b[38;5;%dm\x1b[48;5;%dm %3d/%3d ", $f + 8, $b + 8, $f + 8, $b + 8);
208 }
209 print "\x1b[0m";
210 print "\n";
211 }
212 }
213 }
214
215 # OSC��������������� ���������
216 sub TestOSC()
217 {
218 print "==================== OSC test\n";
219 Pause();
220
221 printf("black-white\n");
222 for (my $i = 0; $i < 16; $i++) {
223 printf("\x1b]4;%d;#%1x%1x%1x\x1b\\", $i, $i, $i, $i);
224 }
225 Pause();
226
227 printf("reset color\n");
228 for (my $i = 0; $i < 16; $i++) {
229 printf("\x1b]104;%d\x1b\\", $i);
230 }
231 }
232
233 # DECSCNM ���������������������
234 # DECSET ESC [ ? 5 h ������
235 # echo -en "\033[?5h"
236 # DECRST ESC [ ? 5 l ������
237 # echo -en "\033[?5l"
238 sub ReverseVideoMode {
239 print "==================== DECSCNM test\n";
240 print "flushing..\n";
241 for (my $i = 0; $i < 50; $i++) {
242 if (($i % 2) == 0) {
243 print "\x1b[?5l";
244 } else {
245 print "\x1b[?5h";
246 }
247 sleep(1);
248 }
249 print "\x1b[?5l";
250 }
251
252 my $arg = (@ARGV != 0) ? $ARGV[0] : "";
253
254 print "\x1b[0m";
255 print "SGR(Select Graphic Rendition) test\n";
256
257 FINISH: for(;;)
258 {
259 my $s;
260 if (length($arg) != 0) {
261 print "> $arg\n";
262 $s = $arg;
263 $arg = "";
264 } else {
265 print <<EOF;
266 a attribute test patterns
267 c ansi color list
268 o Test OSC
269 r reverse test patterns
270 R reverse video
271 q quit
272 EOF
273 print "> ";
274 $s = <STDIN>;
275 }
276 $s =~ s/[\n\r]//g;
277
278 for(;;) {
279 if (length($s) == 0) {
280 next FINISH;
281 }
282 my $c = substr($s, 0, 1);
283 $s = substr($s, 1);
284
285 if ($c eq 'q') {
286 last FINISH;
287 } elsif ($c eq 'a') {
288 ShowAttributesSGR();
289 } elsif ($c eq 'c') {
290 ShowANSIColor();
291 } elsif ($c eq 'o') {
292 TestOSC();
293 } elsif ($c eq 'R') {
294 ReverseVideoMode();
295 } elsif ($c eq 'r') {
296 ShowAttributesREVERSE();
297 } else {
298 print " ?\n"
299 }
300 }
301 }
302 print "\x1b[0m";
303 print "finish\n";

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26