| 1 |
#!/usr/bin/perl -w |
| 2 |
|
| 3 |
# $Id: smgtest,v 1.4 2000/03/29 17:48:20 daniel Exp $ |
| 4 |
|
| 5 |
use strict; |
| 6 |
use ExtUtils::testlib; |
| 7 |
use Term::Slang qw(:all); |
| 8 |
|
| 9 |
SLtt_get_terminfo(); |
| 10 |
SLang_init_tty(-1,0,1); |
| 11 |
SLsig_block_signals(); |
| 12 |
SLsmg_init_smg; |
| 13 |
SLsig_unblock_signals(); |
| 14 |
SLkp_init(); |
| 15 |
|
| 16 |
my ($s_rows,$s_cols) = SLtt_get_screen_size(); |
| 17 |
|
| 18 |
my @colors = qw( |
| 19 |
black red green brown blue magenta cyan lightgray gray brightred |
| 20 |
brightgreen yello brightblue brightmagenta brightcyan white |
| 21 |
); |
| 22 |
my $num_colors = scalar @colors; |
| 23 |
|
| 24 |
init_colors(); |
| 25 |
|
| 26 |
SLtt_set_mouse_mode(1,0); |
| 27 |
|
| 28 |
menu_loop(); |
| 29 |
|
| 30 |
quit(); |
| 31 |
|
| 32 |
############### |
| 33 |
sub quit { |
| 34 |
SLang_reset_tty(); |
| 35 |
SLsmg_reset_smg(); |
| 36 |
exit; |
| 37 |
} |
| 38 |
|
| 39 |
sub print_menu { |
| 40 |
SLsig_block_signals(); |
| 41 |
SLsmg_cls(); |
| 42 |
|
| 43 |
my $row = 2; |
| 44 |
my $i = 1; |
| 45 |
|
| 46 |
my @names = ( |
| 47 |
'Color Test', |
| 48 |
'Alt charset test', |
| 49 |
'Key Escape Sequence Report', |
| 50 |
'Line Drawing Test', |
| 51 |
'Test Mouse', |
| 52 |
'Box Test', |
| 53 |
'Test Low Level Functions', |
| 54 |
'Quit', |
| 55 |
); |
| 56 |
|
| 57 |
for my $name (@names) { |
| 58 |
SLsmg_gotorc($row, 3); |
| 59 |
SLsmg_write_string("$i $name"); |
| 60 |
$row++; |
| 61 |
$i++; |
| 62 |
} |
| 63 |
|
| 64 |
$row = 0; |
| 65 |
SLsmg_gotorc($row, 1); |
| 66 |
SLsmg_write_string('Choose number:'); |
| 67 |
|
| 68 |
SLsmg_refresh(); |
| 69 |
SLsig_unblock_signals(); |
| 70 |
} |
| 71 |
|
| 72 |
sub menu_loop { |
| 73 |
print_menu(); |
| 74 |
|
| 75 |
my @names = ('', |
| 76 |
\&color_test,\&alt_char_test,\&esc_seq_test,\&line_test, |
| 77 |
\&mouse_test,\&box_test,\&low_level_test,\&quit, |
| 78 |
); |
| 79 |
|
| 80 |
while (1) { |
| 81 |
my $ch = chr SLkp_getkey(); |
| 82 |
if ($names[$ch]) { |
| 83 |
&{$names[$ch]}; |
| 84 |
} elsif ($ch eq '\r') { |
| 85 |
next; |
| 86 |
} else { |
| 87 |
SLtt_beep(); |
| 88 |
} |
| 89 |
print_menu(); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
sub write_centered_string { |
| 94 |
my ($s,$row) = @_; |
| 95 |
my $col; |
| 96 |
|
| 97 |
return if $s =~ /^\s*$/; |
| 98 |
my $len = length $s; |
| 99 |
|
| 100 |
# Want 2 * col + len == SLtt_Screen_Rows |
| 101 |
$col = $len >= $s_cols ? 0 : ($s_cols - $len) / 2; |
| 102 |
|
| 103 |
SLsmg_gotorc($row,$col); |
| 104 |
SLsmg_write_string($s); |
| 105 |
} |
| 106 |
|
| 107 |
sub pre_test { |
| 108 |
my $title = shift; |
| 109 |
SLsig_block_signals; |
| 110 |
SLsmg_cls; |
| 111 |
write_centered_string($title,0); |
| 112 |
} |
| 113 |
|
| 114 |
sub post_test { |
| 115 |
write_centered_string('Press any key to return.',$s_rows - 1); |
| 116 |
SLsmg_refresh; |
| 117 |
SLsig_unblock_signals; |
| 118 |
SLkp_getkey; |
| 119 |
} |
| 120 |
|
| 121 |
sub init_colors { |
| 122 |
for(my $i = 0; $i < $num_colors; $i++) { |
| 123 |
SLtt_set_color($i+1,'','black',$colors[$i]); |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
# The tests. |
| 128 |
sub box_test { |
| 129 |
my $msg = 'This is a box with changing background'; |
| 130 |
my $color; |
| 131 |
|
| 132 |
pre_test('Box Test'); |
| 133 |
|
| 134 |
my $dr = 8; |
| 135 |
my $dc = 4 + length $msg; |
| 136 |
my $r = $s_rows / 2 - $dr/2; |
| 137 |
my $c = $s_cols / 2 - $dc/2; |
| 138 |
|
| 139 |
SLsmg_set_color(1); |
| 140 |
SLsmg_set_char_set(1); |
| 141 |
SLsmg_fill_region($r + 1, $c + 1, $dr - 2, $dc - 2, 'a'); |
| 142 |
SLsmg_set_char_set(0); |
| 143 |
SLsmg_set_color(0); |
| 144 |
SLsmg_gotorc($r + $dr/2, $c + 2); |
| 145 |
SLsmg_write_string($msg); |
| 146 |
SLsmg_draw_box($r, $c, $dr, $dc); |
| 147 |
|
| 148 |
SLsmg_refresh(); |
| 149 |
|
| 150 |
$color = 2; |
| 151 |
while (0 == SLang_input_pending(10)) { |
| 152 |
SLsmg_set_color_in_region($color,$r,$c,$dr,$dc); |
| 153 |
SLsmg_refresh(); |
| 154 |
$color++; |
| 155 |
$color = $color % $num_colors; |
| 156 |
} |
| 157 |
post_test(); |
| 158 |
} |
| 159 |
|
| 160 |
sub color_test { |
| 161 |
pre_test('Color Test'); |
| 162 |
|
| 163 |
my $row = 1; |
| 164 |
my $color = 0; |
| 165 |
while ($row < $s_rows - 1) { |
| 166 |
$color = $color % $num_colors; |
| 167 |
|
| 168 |
SLsmg_gotorc($row, 0); |
| 169 |
SLsmg_set_color(0); |
| 170 |
SLsmg_write_string($colors[$color]); |
| 171 |
$color++; |
| 172 |
SLsmg_set_color($color); |
| 173 |
SLsmg_erase_eol; |
| 174 |
$row++; |
| 175 |
} |
| 176 |
|
| 177 |
SLsmg_set_color(0); |
| 178 |
post_test(); |
| 179 |
} |
| 180 |
|
| 181 |
sub alt_char_test { |
| 182 |
pre_test('Alternate Charset Test'); |
| 183 |
|
| 184 |
my $row = $s_rows / 2 - 2; |
| 185 |
my $col = 0; |
| 186 |
|
| 187 |
for (my $ch = 32; $ch < 128; $ch++) { |
| 188 |
SLsmg_gotorc($row, $col); |
| 189 |
SLsmg_write_char(chr $ch); |
| 190 |
SLsmg_gotorc($row + 1, $col); |
| 191 |
SLsmg_set_char_set(1); |
| 192 |
SLsmg_write_char(chr $ch); |
| 193 |
SLsmg_set_char_set(0); |
| 194 |
$col++; |
| 195 |
|
| 196 |
if ($col > 40) { |
| 197 |
$col = 0; |
| 198 |
$row += 4; |
| 199 |
} |
| 200 |
} |
| 201 |
post_test(); |
| 202 |
} |
| 203 |
|
| 204 |
sub line_test { |
| 205 |
pre_test('Line Test'); |
| 206 |
|
| 207 |
my $row = 4; |
| 208 |
my $col = 2; |
| 209 |
SLsmg_gotorc($row, $col); |
| 210 |
SLsmg_draw_hline(10); |
| 211 |
SLsmg_write_string('Result of SLsmg_draw_hline(10)'); |
| 212 |
SLsmg_draw_vline(5); |
| 213 |
SLsmg_write_string('Result of SLsmg_draw_vline(5)'); |
| 214 |
|
| 215 |
post_test(); |
| 216 |
} |
| 217 |
|
| 218 |
sub esc_seq_test { |
| 219 |
pre_test('Escape Sequence Report'); |
| 220 |
|
| 221 |
my $row = $s_rows / 2; |
| 222 |
|
| 223 |
SLsmg_gotorc($row, 0); |
| 224 |
SLsmg_write_string('Press key: '); |
| 225 |
SLsmg_refresh(); |
| 226 |
|
| 227 |
SLsmg_gotorc($row, 0); |
| 228 |
SLsmg_write_string('Key returned '); |
| 229 |
|
| 230 |
my $ch = SLang_getkey(); |
| 231 |
my $buf = '"'; |
| 232 |
|
| 233 |
if ($ch >= 127) { |
| 234 |
$buf .= sprintf("\\d%d", $ch); |
| 235 |
|
| 236 |
} elsif ($ch eq '"' or $ch eq '\\') { |
| 237 |
$buf .= '\\'.chr $ch; |
| 238 |
|
| 239 |
} else { |
| 240 |
$buf .= chr $ch; |
| 241 |
} |
| 242 |
|
| 243 |
while (SLang_input_pending(3) > 0) { } |
| 244 |
|
| 245 |
$buf .= '"'; |
| 246 |
SLsmg_write_string($buf); |
| 247 |
post_test(); |
| 248 |
} |
| 249 |
|
| 250 |
sub mouse_test { |
| 251 |
pre_test('Mouse Test'); |
| 252 |
|
| 253 |
my $row = $s_rows / 2; |
| 254 |
|
| 255 |
SLsmg_gotorc($row, 0); |
| 256 |
SLsmg_write_string('Click Mouse: '); |
| 257 |
SLsmg_refresh(); |
| 258 |
|
| 259 |
my $ch = SLang_getkey(); |
| 260 |
|
| 261 |
if ($ch != 27) { |
| 262 |
SLsmg_gotorc($row, 0); |
| 263 |
SLsmg_write_string('That did not appear to be a mouse escape sequence'); |
| 264 |
SLsmg_gotorc($row+1,0); |
| 265 |
SLsmg_write_string("You pressed: $ch"); |
| 266 |
post_test(); |
| 267 |
return; |
| 268 |
} |
| 269 |
|
| 270 |
my $b = SLang_getkey(); |
| 271 |
my $x = SLang_getkey(); |
| 272 |
my $y = SLang_getkey(); |
| 273 |
|
| 274 |
SLsmg_gotorc($row, 0); |
| 275 |
SLsmg_write_string("Button: $b "); |
| 276 |
SLsmg_gotorc($row + 1, 0); |
| 277 |
SLsmg_write_string("Column: $x"); |
| 278 |
SLsmg_gotorc($row + 2, 0); |
| 279 |
SLsmg_write_string(" Row: $y"); |
| 280 |
SLang_getkey(); |
| 281 |
SLang_getkey(); |
| 282 |
post_test(); |
| 283 |
} |
| 284 |
|
| 285 |
sub low_level_test { |
| 286 |
# XXX not implemented yet |
| 287 |
#if (SLtt_Term_Cannot_Scroll) { |
| 288 |
# pre_test('Sorry! Your terminal lacks scrolling capability.'); |
| 289 |
# post_test(); |
| 290 |
# return; |
| 291 |
#} |
| 292 |
|
| 293 |
SLsmg_suspend_smg(); |
| 294 |
SLtt_init_video(); |
| 295 |
|
| 296 |
my $mid = $s_rows / 2; |
| 297 |
my $bot = $s_rows - 1; |
| 298 |
|
| 299 |
SLtt_cls(); |
| 300 |
SLtt_goto_rc(0, 0); |
| 301 |
SLtt_write_string("The following set of tests are designed to test the display system."); |
| 302 |
SLtt_goto_rc(1, 0); |
| 303 |
SLtt_write_string("There should be a line of text in the middle and one at the bottom."); |
| 304 |
SLtt_goto_rc($mid, 0); |
| 305 |
SLtt_write_string("This line is in the middle."); |
| 306 |
SLtt_goto_rc($bot, 0); |
| 307 |
SLtt_write_string("This line is at the bottom."); |
| 308 |
|
| 309 |
SLtt_goto_rc(2, 0); |
| 310 |
SLtt_write_string("Press return now."); |
| 311 |
SLtt_flush_output(); |
| 312 |
SLang_flush_input(); |
| 313 |
SLang_getkey(); |
| 314 |
|
| 315 |
SLtt_goto_rc(2, 0); |
| 316 |
SLtt_write_string("The middle row should slowly move down next the bottom and then back up."); |
| 317 |
SLtt_goto_rc($mid - 1, 0); |
| 318 |
SLtt_write_string("This line should not move."); |
| 319 |
SLtt_goto_rc($mid + 1, 0); |
| 320 |
SLtt_write_string("This line should vanish at the bottom"); |
| 321 |
SLtt_goto_rc($mid + 1, $s_cols - 5); |
| 322 |
SLtt_write_string("End->"); |
| 323 |
SLtt_flush_output(); |
| 324 |
|
| 325 |
SLtt_set_scroll_region($mid, $bot - 1); |
| 326 |
|
| 327 |
my $r = ($bot - $mid) - 1; |
| 328 |
|
| 329 |
while ($r > 0) { |
| 330 |
SLang_input_pending(2); # 3/10 sec delay |
| 331 |
SLtt_goto_rc(0,0); # relative to scroll region |
| 332 |
SLtt_reverse_index(1); |
| 333 |
SLtt_flush_output(); |
| 334 |
$r--; |
| 335 |
} |
| 336 |
|
| 337 |
$r = ($bot - $mid) - 1; |
| 338 |
while ($r > 0) { |
| 339 |
SLang_input_pending(2); |
| 340 |
SLtt_goto_rc(0,0); |
| 341 |
SLtt_delete_nlines(1); |
| 342 |
SLtt_flush_output(); |
| 343 |
$r--; |
| 344 |
} |
| 345 |
|
| 346 |
SLtt_reset_scroll_region(); |
| 347 |
SLtt_goto_rc($mid - 1, 0); |
| 348 |
SLtt_write_string("Now the bottom will come up and clear the lines below"); |
| 349 |
|
| 350 |
SLtt_set_scroll_region($mid, $bot); |
| 351 |
$r = ($bot - $mid) + 1; |
| 352 |
while ($r > 0) { |
| 353 |
SLang_input_pending(2); |
| 354 |
SLtt_goto_rc(0,0); |
| 355 |
SLtt_delete_nlines(1); |
| 356 |
SLtt_flush_output(); |
| 357 |
$r--; |
| 358 |
} |
| 359 |
|
| 360 |
SLtt_reset_scroll_region(); |
| 361 |
SLtt_goto_rc(3,0); |
| 362 |
SLtt_write_string("This line will go down and vanish"); |
| 363 |
SLtt_set_scroll_region(3, $mid - 2); |
| 364 |
|
| 365 |
$r = (($mid - 2) - 3) + 1; |
| 366 |
while ($r > 0) { |
| 367 |
SLang_input_pending(3); |
| 368 |
SLtt_goto_rc(0,0); |
| 369 |
SLtt_reverse_index(1); |
| 370 |
SLtt_flush_output(); |
| 371 |
$r--; |
| 372 |
} |
| 373 |
|
| 374 |
SLtt_reset_scroll_region(); |
| 375 |
SLtt_set_scroll_region(1,1); |
| 376 |
SLtt_goto_rc (0,0); |
| 377 |
SLtt_delete_nlines(1); |
| 378 |
SLtt_reset_scroll_region(); |
| 379 |
SLtt_set_scroll_region(2,2); |
| 380 |
SLtt_goto_rc(0,0); |
| 381 |
SLtt_reverse_index(1); |
| 382 |
SLtt_reset_scroll_region(); |
| 383 |
|
| 384 |
SLtt_goto_rc(1, 10); |
| 385 |
SLtt_write_string("Press Any Key To Continue."); |
| 386 |
SLtt_flush_output(); |
| 387 |
$r = 15; |
| 388 |
|
| 389 |
#if (0 == SLtt_Term_Cannot_Insert()) { |
| 390 |
while ($r) { |
| 391 |
$r--; |
| 392 |
SLtt_goto_rc(1, 0); |
| 393 |
SLtt_begin_insert(); |
| 394 |
SLtt_putchar(' '); |
| 395 |
SLtt_end_insert(); |
| 396 |
SLtt_flush_output(); |
| 397 |
SLang_input_pending(2); |
| 398 |
} |
| 399 |
#} |
| 400 |
|
| 401 |
SLang_flush_input(); |
| 402 |
SLang_getkey(); |
| 403 |
|
| 404 |
SLtt_reset_video(); |
| 405 |
SLsmg_resume_smg(); |
| 406 |
} |
| 407 |
|
| 408 |
__END__ |