File: smgtest

package info (click to toggle)
libterm-slang-perl 0.07-7
  • links: PTS
  • area: main
  • in suites: woody
  • size: 100 kB
  • ctags: 39
  • sloc: perl: 614; makefile: 42
file content (408 lines) | stat: -rwxr-xr-x 7,822 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
#!/usr/bin/perl -w

# $Id: smgtest,v 1.4 2000/04/17 03:53:11 joey Rel $

use strict;
use ExtUtils::testlib;
use Term::Slang qw(:all);

SLtt_get_terminfo();
SLang_init_tty(-1,0,1);
SLsig_block_signals();
SLsmg_init_smg;
SLsig_unblock_signals();
SLkp_init();

my ($s_rows,$s_cols) = SLtt_get_screen_size();

my @colors = qw(
	black red green brown blue magenta cyan lightgray gray brightred
	brightgreen yello brightblue brightmagenta brightcyan white
);
my $num_colors = scalar @colors;

init_colors();
	
SLtt_set_mouse_mode(1,0);

menu_loop();

quit();

###############
sub quit {
	SLang_reset_tty();
	SLsmg_reset_smg();
	exit;
}

sub print_menu {
	SLsig_block_signals();
	SLsmg_cls();
	
	my $row = 2;
	my $i   = 1;

	my @names = (
		'Color Test',
		'Alt charset test',
		'Key Escape Sequence Report',
		'Line Drawing Test',
		'Test Mouse',
		'Box Test',
		'Test Low Level Functions',
		'Quit',
	);

	for my $name (@names) {
		SLsmg_gotorc($row, 3);
		SLsmg_write_string("$i $name");
		$row++;
		$i++;
	}
	
	$row = 0;
	SLsmg_gotorc($row, 1);
	SLsmg_write_string('Choose number:');
	
	SLsmg_refresh();
	SLsig_unblock_signals();
}

sub menu_loop {
	print_menu();

	my @names = ('',
		\&color_test,\&alt_char_test,\&esc_seq_test,\&line_test,
		\&mouse_test,\&box_test,\&low_level_test,\&quit,
	);
	
	while (1) {
		my $ch = chr SLkp_getkey();
		if ($names[$ch]) {
			&{$names[$ch]};
		} elsif ($ch eq '\r') {
			next;
		} else {
			SLtt_beep();
		}
		print_menu();
	}
}

sub write_centered_string {
	my ($s,$row) = @_;
	my $col;

	return if $s =~ /^\s*$/;
	my $len = length $s;  

	# Want 2 * col + len == SLtt_Screen_Rows 
	$col = $len >= $s_cols ? 0 : ($s_cols - $len) / 2;

	SLsmg_gotorc($row,$col);
	SLsmg_write_string($s);
}

sub pre_test {
	my $title = shift;
	SLsig_block_signals;
	SLsmg_cls;
	write_centered_string($title,0);
}

sub post_test {
	write_centered_string('Press any key to return.',$s_rows - 1);
	SLsmg_refresh;
	SLsig_unblock_signals;
	SLkp_getkey;
}

sub init_colors {
	for(my $i = 0; $i < $num_colors; $i++) {
		SLtt_set_color($i+1,'','black',$colors[$i]);
	}
}

# The tests.
sub box_test  {
	my $msg = 'This is a box with changing background';
	my $color;

	pre_test('Box Test');
	
	my $dr = 8;
	my $dc = 4 + length $msg;
	my $r  = $s_rows / 2 - $dr/2;
	my $c  = $s_cols / 2 - $dc/2;

	SLsmg_set_color(1);
	SLsmg_set_char_set(1);
	SLsmg_fill_region($r + 1, $c + 1, $dr - 2, $dc - 2, 'a');
	SLsmg_set_char_set(0);
	SLsmg_set_color(0);
	SLsmg_gotorc($r + $dr/2, $c + 2);
	SLsmg_write_string($msg);
	SLsmg_draw_box($r, $c, $dr, $dc);

	SLsmg_refresh();

	$color = 2;
	while (0 == SLang_input_pending(10)) {
		SLsmg_set_color_in_region($color,$r,$c,$dr,$dc);
		SLsmg_refresh();
		$color++;
		$color = $color % $num_colors;
	}
	post_test();
}

sub color_test {
	pre_test('Color Test');
	
	my $row = 1;
	my $color = 0;
	while ($row < $s_rows - 1) {
		$color = $color % $num_colors;

		SLsmg_gotorc($row, 0);
		SLsmg_set_color(0);
		SLsmg_write_string($colors[$color]);
		$color++;
		SLsmg_set_color($color);
		SLsmg_erase_eol;
		$row++;
	}
	
	SLsmg_set_color(0);
	post_test();
}

sub alt_char_test {
	pre_test('Alternate Charset Test');
	
	my $row = $s_rows / 2 - 2;
	my $col = 0;

	for (my $ch = 32; $ch < 128; $ch++) {
		SLsmg_gotorc($row, $col);
		SLsmg_write_char(chr $ch);
		SLsmg_gotorc($row + 1, $col);
		SLsmg_set_char_set(1);
		SLsmg_write_char(chr $ch);
		SLsmg_set_char_set(0);
		$col++;
	
		if ($col > 40) {
			$col  = 0;
			$row += 4;
		}
	}
	post_test();
}

sub line_test {
	pre_test('Line Test');
	
	my $row = 4;
	my $col = 2;
	SLsmg_gotorc($row, $col);
	SLsmg_draw_hline(10);
	SLsmg_write_string('Result of SLsmg_draw_hline(10)');
	SLsmg_draw_vline(5);
	SLsmg_write_string('Result of SLsmg_draw_vline(5)');

	post_test();
}

sub esc_seq_test {
	pre_test('Escape Sequence Report');
	
	my $row = $s_rows / 2;
	
	SLsmg_gotorc($row, 0);
	SLsmg_write_string('Press key: ');
	SLsmg_refresh();
	
	SLsmg_gotorc($row, 0);
	SLsmg_write_string('Key returned ');

	my $ch = SLang_getkey();
	my $buf = '"';

	if ($ch >= 127) {
		$buf .= sprintf("\\d%d", $ch);

	} elsif ($ch eq '"' or $ch eq '\\') {
	    $buf .= '\\'.chr $ch;

	} else { 
		$buf .= chr $ch;
	}

	while (SLang_input_pending(3) > 0) { }

	$buf .= '"';
	SLsmg_write_string($buf);
	post_test();
}

sub mouse_test {
	pre_test('Mouse Test');
	
	my $row = $s_rows / 2;
	
	SLsmg_gotorc($row, 0);
	SLsmg_write_string('Click Mouse: ');
	SLsmg_refresh();

	my $ch = SLang_getkey();
	
	if ($ch != 27) { 
		SLsmg_gotorc($row, 0);
		SLsmg_write_string('That did not appear to be a mouse escape sequence');
		SLsmg_gotorc($row+1,0);
		SLsmg_write_string("You pressed: $ch");
		post_test();
		return;
	}
	
	my $b = SLang_getkey();
	my $x = SLang_getkey();
	my $y = SLang_getkey();
	
	SLsmg_gotorc($row, 0);
	SLsmg_write_string("Button: $b     ");
	SLsmg_gotorc($row + 1, 0);
	SLsmg_write_string("Column: $x");
	SLsmg_gotorc($row + 2, 0);
	SLsmg_write_string("   Row: $y");
	SLang_getkey();
	SLang_getkey();
	post_test();
}

sub low_level_test {
	# XXX not implemented yet
	#if (SLtt_Term_Cannot_Scroll) {
	#	pre_test('Sorry!  Your terminal lacks scrolling capability.');
	#	post_test();
	#	return;
	#}

	SLsmg_suspend_smg();
	SLtt_init_video();

	my $mid = $s_rows / 2;
	my $bot = $s_rows - 1;

	SLtt_cls();
	SLtt_goto_rc(0, 0);
	SLtt_write_string("The following set of tests are designed to test the display system.");
	SLtt_goto_rc(1, 0);
	SLtt_write_string("There should be a line of text in the middle and one at the bottom.");
	SLtt_goto_rc($mid, 0);
	SLtt_write_string("This line is in the middle.");
	SLtt_goto_rc($bot, 0);
	SLtt_write_string("This line is at the bottom.");
	
	SLtt_goto_rc(2, 0); 
	SLtt_write_string("Press return now.");
	SLtt_flush_output();
	SLang_flush_input();
	SLang_getkey();
	
	SLtt_goto_rc(2, 0);
	SLtt_write_string("The middle row should slowly move down next the bottom and then back up.");
	SLtt_goto_rc($mid - 1, 0);
	SLtt_write_string("This line should not move.");
	SLtt_goto_rc($mid + 1, 0);
	SLtt_write_string("This line should vanish at the bottom");
	SLtt_goto_rc($mid + 1, $s_cols - 5);
	SLtt_write_string("End->");
	SLtt_flush_output();

	SLtt_set_scroll_region($mid, $bot - 1);
	
	my $r = ($bot - $mid) - 1;

	while ($r > 0) {
		SLang_input_pending(2); # 3/10 sec delay
		SLtt_goto_rc(0,0);	# relative to scroll region 
		SLtt_reverse_index(1);
		SLtt_flush_output();
		$r--;
	}
	
	$r = ($bot - $mid) - 1;
	while ($r > 0) {
		SLang_input_pending(2);
		SLtt_goto_rc(0,0);
		SLtt_delete_nlines(1);
		SLtt_flush_output();
		$r--;
	}
	
	SLtt_reset_scroll_region();
	SLtt_goto_rc($mid - 1, 0);
	SLtt_write_string("Now the bottom will come up and clear the lines below");
	
	SLtt_set_scroll_region($mid, $bot);
	$r = ($bot - $mid) + 1;
	while ($r > 0) {
		SLang_input_pending(2);
		SLtt_goto_rc(0,0);
		SLtt_delete_nlines(1);
		SLtt_flush_output();
		$r--;
	}

	SLtt_reset_scroll_region();
	SLtt_goto_rc(3,0);
	SLtt_write_string("This line will go down and vanish");
	SLtt_set_scroll_region(3, $mid - 2);

	$r = (($mid - 2) - 3) + 1;
	while ($r > 0) {
		SLang_input_pending(3);
		SLtt_goto_rc(0,0);
		SLtt_reverse_index(1);
		SLtt_flush_output();
		$r--;
	}
	
	SLtt_reset_scroll_region();
	SLtt_set_scroll_region(1,1);
	SLtt_goto_rc (0,0);
	SLtt_delete_nlines(1);
	SLtt_reset_scroll_region();
	SLtt_set_scroll_region(2,2);
	SLtt_goto_rc(0,0);
	SLtt_reverse_index(1);
	SLtt_reset_scroll_region();

	SLtt_goto_rc(1, 10);
	SLtt_write_string("Press Any Key To Continue.");
	SLtt_flush_output();
	$r = 15;

	#if (0 == SLtt_Term_Cannot_Insert()) {
		while ($r) {
			$r--;
			SLtt_goto_rc(1, 0);
			SLtt_begin_insert();
			SLtt_putchar(' ');
			SLtt_end_insert();
			SLtt_flush_output();
			SLang_input_pending(2);
		}
	#}
	
	SLang_flush_input();
	SLang_getkey();
	
	SLtt_reset_video();
	SLsmg_resume_smg();
}

__END__