Develop and Download Open Source Software

Browse Subversion Repository

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10257 - (hide annotations) (download) (as text)
Sat Sep 10 15:29:18 2022 UTC (19 months ago) by zmatsuo
Original Path: trunk/tests/color-sgr-decscnm.pl
File MIME type: text/x-perl
File size: 6335 byte(s)
表示テストのパターンを追加

- 反転表示テストを追加
- テストをメニューと引数で選べるようにした
1 nmaya 10207 #!/usr/bin/perl
2 nmaya 10206
3 zmatsuo 10257 use utf8;
4     use strict;
5     use warnings;
6     use Class::Struct;
7    
8 nmaya 10206 local $| = 1;
9    
10 zmatsuo 10257 sub Pause {
11 zmatsuo 10242 printf("pause(hit enter)\n");
12     <STDIN>;
13     }
14    
15 zmatsuo 10257 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\n",
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 nmaya 10206
95 zmatsuo 10257 print "\x1b[0m";
96 nmaya 10206 print "==================== support attributes\n";
97 zmatsuo 10257 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 nmaya 10206
105 zmatsuo 10257 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 nmaya 10206 print "\x1b[0m";
141 zmatsuo 10257 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 nmaya 10206 }
149    
150 zmatsuo 10257 sub ShowANSIColor {
151 nmaya 10206 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 zmatsuo 10257 for (my $f = 0; $f < 8; $f++) {
158     for (my $b = 0; $b < 8; $b++) {
159 nmaya 10206 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 zmatsuo 10257 for (my $f = 0; $f < 8; $f++) {
171     for (my $b = 0; $b < 8; $b++) {
172 nmaya 10206 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 zmatsuo 10257 for (my $f = 0; $f < 8; $f++) {
183     for (my $b = 0; $b < 8; $b++) {
184 nmaya 10206 print "\x1b[1m";
185     printf("\x1b[%d;%dm %3d/%3d ", $f + 30, $b + 40, $f + 30, $b + 40);
186     }
187     print "\x1b[0m";
188     print "\n";
189     }
190     print "\x1b[0m";
191     print "\n";
192     }
193    
194     if (1) {
195     print "PC 4bit(16) color\n";
196     print " FG: SGR 38 ; 5 ; n m BG: 48 ; 5 ; n m (256color only)\n";
197 zmatsuo 10257 for (my $f = 0; $f < 8; $f++) {
198 nmaya 10206 for ($b = 0; $b < 8; $b++) {
199     printf("\x1b[38;5;%dm\x1b[48;5;%dm %3d/%3d ", $f, $b, $f, $b);
200     }
201     print "\x1b[0m";
202     print "\n";
203     }
204 zmatsuo 10257 for (my $f = 0; $f < 8; $f++) {
205     for (my $b = 0; $b < 8; $b++) {
206 nmaya 10206 printf("\x1b[38;5;%dm\x1b[48;5;%dm %3d/%3d ", $f + 8, $b + 8, $f + 8, $b + 8);
207     }
208     print "\x1b[0m";
209     print "\n";
210     }
211     }
212     }
213    
214 zmatsuo 10242 # OSC��������������� ���������
215 zmatsuo 10257 sub TestOSC()
216     {
217 zmatsuo 10242 print "==================== OSC test\n";
218 zmatsuo 10257 Pause();
219 zmatsuo 10242
220     printf("black-white\n");
221 zmatsuo 10257 for (my $i = 0; $i < 16; $i++) {
222 zmatsuo 10242 printf("\x1b]4;%d;#%1x%1x%1x\x1b\\", $i, $i, $i, $i);
223     }
224 zmatsuo 10257 Pause();
225 zmatsuo 10242
226     printf("reset color\n");
227 zmatsuo 10257 for (my $i = 0; $i < 16; $i++) {
228     printf("\x1b]104;%d\x1b\\", $i);
229 zmatsuo 10242 }
230     }
231    
232 nmaya 10206 # DECSCNM ���������������������
233     # DECSET ESC [ ? 5 h ������
234     # echo -en "\033[?5h"
235     # DECRST ESC [ ? 5 l ������
236     # echo -en "\033[?5l"
237 zmatsuo 10257 sub ReverseVideoMode {
238 nmaya 10206 print "==================== DECSCNM test\n";
239 zmatsuo 10257 print "flushing..\n";
240     for (my $i = 0; $i < 50; $i++) {
241 nmaya 10206 if (($i % 2) == 0) {
242     print "\x1b[?5l";
243     } else {
244     print "\x1b[?5h";
245     }
246     sleep(1);
247     }
248 nmaya 10207 print "\x1b[?5l";
249 nmaya 10206 }
250 zmatsuo 10257
251     my $arg = (@ARGV != 0) ? $ARGV[0] : "";
252    
253     print "\x1b[0m";
254     print "SGR(Select Graphic Rendition) test\n";
255    
256     FINISH: for(;;)
257     {
258     my $s;
259     if (length($arg) != 0) {
260     print "> $arg\n";
261     $s = $arg;
262     $arg = "";
263     } else {
264     print <<EOF;
265     a attribute test patterns
266     c ansi color list
267     o Test OSC
268     r reverse test patterns
269     R reverse video
270     q quit
271     EOF
272     print "> ";
273     $s = <STDIN>;
274     }
275     $s =~ s/[\n\r]//g;
276    
277     for(;;) {
278     if (length($s) == 0) {
279     next FINISH;
280     }
281     my $c = substr($s, 0, 1);
282     $s = substr($s, 1);
283    
284     if ($c eq 'q') {
285     last FINISH;
286     } elsif ($c eq 'a') {
287     ShowAttributesSGR();
288     } elsif ($c eq 'c') {
289     ShowANSIColor();
290     } elsif ($c eq 'o') {
291     TestOSC();
292     } elsif ($c eq 'R') {
293     ReverseVideoMode();
294     } elsif ($c eq 'r') {
295     ShowAttributesREVERSE();
296     } else {
297     print " ?\n"
298     }
299     }
300     }
301     print "\x1b[0m";
302     print "finish\n";

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