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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
|
/* This demo test some of the slsmg features. */
#include "config.h"
#include <stdio.h>
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#include <string.h>
#include <slang.h>
#include "demolib.c"
static void menu_loop (void);
static int select_menu_item (int i);
static void init_colors (void);
int main (int argc, char **argv)
{
if (-1 == demolib_init_terminal (1, 1))
return 1;
init_colors ();
(void) SLtt_set_mouse_mode (1, 0);
if (argc <= 1)
menu_loop ();
do
{
argc--;
argv++;
if (-1 == select_menu_item (atoi (*argv)))
menu_loop ();
}
while (argc > 1);
demolib_exit (0);
return 1;
}
static void quit (void)
{
demolib_exit (0);
}
static void bce_color_test (void);
static void color_test (void);
static void color_test1 (void);
static void alt_char_test (void);
static void esc_seq_test (void);
static void ansi_esc_seq_test (void);
static void line_test (void);
static void mouse_test (void);
static void low_level_test (void);
static void box_test (void);
static void draw_symbols_test (void);
static void lr_corner_test (void);
static void mono_test (void);
typedef struct
{
char *name;
void (*funct) (void);
}
Menu_Type;
static Menu_Type Root_Menu [] =
{
{"Color Test", color_test},
{"Another Color Test", color_test1},
{"BCE Color Test", bce_color_test},
{"Alt charset test", alt_char_test},
{"Drawing Symbols", draw_symbols_test},
{"Key Escape Sequence Report", esc_seq_test},
#ifdef IBMPC_SYSTEM
{"ANSI Key Escape Sequence Report", ansi_esc_seq_test},
#endif
{"Line Drawing Test", line_test},
{"Test Mouse", mouse_test},
{"Box Test", box_test},
{"Write to Lower Right Corner Test", lr_corner_test},
{"Test Low Level Functions", low_level_test},
{"Test monochrome functions", mono_test},
{"Quit", quit},
{NULL, NULL}
};
Menu_Type *Current_Menu = Root_Menu;
static void print_menu (void)
{
int i;
int row;
Menu_Type *menu;
menu = Current_Menu;
SLsig_block_signals ();
SLsmg_cls ();
row = 2;
i = 1;
while (menu->name != NULL)
{
SLsmg_gotorc (row, 3);
SLsmg_printf ("%2X. %s", i, menu->name);
menu++;
row++;
i++;
}
row = 0;
SLsmg_gotorc (row, 1);
SLsmg_write_string ("Choose number:");
SLsmg_refresh ();
SLsig_unblock_signals ();
}
static int select_menu_item (int num)
{
int i = 1;
Menu_Type *m = Current_Menu;
while (m->name != NULL)
{
if (i == num)
{
(*m->funct) ();
return 0;
}
i++;
m++;
}
return -1;
}
static void menu_loop (void)
{
int ch;
print_menu ();
while (1)
{
ch = SLkp_getkey ();
if ((ch == 'q') || (ch == 'Q'))
quit ();
if ((ch >= '0')
&& (ch <= '9'))
ch -= '0';
else if ((ch >= 'A') && (ch <= 'Z'))
ch = 10 + (ch - 'A');
else
ch = 10 + (ch - 'a');
if (-1 == select_menu_item (ch))
{
SLtt_beep ();
continue;
}
print_menu ();
}
}
static void write_centered_string (char *s, int row)
{
unsigned int len;
int col;
if (s == NULL)
return;
len = strlen (s);
/* Want 2 * col + len == SLtt_Screen_Rows */
if (len >= (unsigned int) SLtt_Screen_Cols) col = 0;
else col = (SLtt_Screen_Cols - (int)len) / 2;
SLsmg_gotorc (row, col);
SLsmg_write_string (s);
}
static void pre_test (char *title)
{
SLsig_block_signals ();
SLsmg_cls ();
write_centered_string (title, 0);
}
static void post_test (void)
{
write_centered_string ("Press any key to return.", SLtt_Screen_Rows - 1);
SLsmg_refresh ();
SLsig_unblock_signals ();
(void) SLkp_getkey ();
}
/* Various tests */
#define NUM_COLORS 16
static char *Colors [NUM_COLORS] =
{
"black/default",
"red",
"green",
"brown",
"blue",
"magenta",
"cyan",
"lightgray",
"gray",
"brightred",
"brightgreen",
"yellow",
"brightblue",
"brightmagenta",
"brightcyan",
"white"
};
static void init_colors (void)
{
int i;
char *fg, *bg;
fg = "black";
for (i = 0; i < NUM_COLORS; i++)
{
bg = Colors[i];
SLtt_set_color (i + 1, NULL, fg, bg);
}
}
static void box_test (void)
{
char *msg = "This is a box with changing background";
int r, c, dr, dc;
int color;
pre_test ("Box Test");
dr = 8;
dc = 4 + strlen (msg);
r = SLtt_Screen_Rows / 2 - dr/2;
c = SLtt_Screen_Cols / 2 - dc/2;
SLsmg_set_color (1);
SLsmg_set_char_set (1);
SLsmg_fill_region (r + 1, c + 1, dr - 2, dc - 2, SLSMG_CKBRD_CHAR);
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 ();
}
static int check_color_support (void)
{
if (SLtt_Use_Ansi_Colors)
return 0;
pre_test ("Your terminal does not provide color support.");
post_test ();
return -1;
}
static void bce_color_test (void)
{
int row;
if (-1 == check_color_support ())
return;
pre_test ("Background Color Erase Test");
SLtt_set_color (0, NULL, "lightgray", "blue");
row = SLtt_Screen_Rows/2;
SLsmg_set_color (0);
SLsmg_gotorc (row, 1);
SLsmg_write_string ("The screen background should be blue.");
row += 2;
SLsmg_gotorc (row++, 1);
SLsmg_write_string ("****If the screen update is slow, then your terminal");
SLsmg_gotorc (row++, 1);
SLsmg_write_string (" does not support background-color-erase.");
SLsmg_set_color (0);
post_test ();
}
static void lr_corner_test (void)
{
pre_test ("Write to Lower Right Corner Test");
SLsmg_gotorc (SLtt_Screen_Rows-1, SLtt_Screen_Cols-1);
SLsmg_write_string ("X");
write_centered_string ("An 'X' should be in the lower-right corner.",
SLtt_Screen_Rows/2);
SLsmg_refresh ();
SLsig_unblock_signals ();
(void) SLkp_getkey ();
}
static void color_test (void)
{
int color;
int row;
if (-1 == check_color_support ())
return;
pre_test ("Color Test");
row = 1;
color = 0;
while (row < SLtt_Screen_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 ();
}
static void color_test1 (void)
{
int color;
int r0, r1;
int c0, c1;
unsigned int dr0, dr1, dc0, dc1;
if (-1 == check_color_support ())
return;
pre_test ("Another Color Test");
r0 = 1;
r1 = SLtt_Screen_Rows / 2;
dr0 = r1;
dr1 = SLtt_Screen_Rows;
c0 = 0;
c1 = SLtt_Screen_Cols / 2;
dc0 = c1;
dc1 = SLtt_Screen_Cols;
color = 0;
do
{
SLsmg_gotorc (r1, 0);
SLsmg_set_color (color); color++; color = color % NUM_COLORS;
SLsmg_write_string (" ");
SLsmg_set_color (color); color++; color = color % NUM_COLORS;
SLsmg_write_string ("X");
SLsmg_set_color (color); color++; color = color % NUM_COLORS;
SLsmg_erase_eol ();
SLsmg_refresh ();
}
while (0 == SLang_input_pending (30));
SLang_flush_input ();
color = 0;
do
{
SLsmg_set_color (color); color++; color = color % NUM_COLORS;
SLsmg_fill_region (r0, c0, dr0, dc0, ' ');
SLsmg_set_color (color); color++; color = color % NUM_COLORS;
SLsmg_fill_region (r0, c1, dr0, dc1, ' ');
SLsmg_set_color (color); color++; color = color % NUM_COLORS;
SLsmg_fill_region (r1, c0, dr1, dc0, ' ');
SLsmg_set_color (color); color++; color = color % NUM_COLORS;
SLsmg_fill_region (r1, c1, dr1, dc1, ' ');
SLsmg_refresh ();
}
while (0 == SLang_input_pending (30));
SLsmg_set_color (0);
post_test ();
}
static void alt_char_test (void)
{
int row, col;
int ch;
pre_test ("Alternate Charset Test");
row = SLtt_Screen_Rows / 2 - 2;
col = 0;
for (ch = 32; ch < 128; ch++)
{
SLsmg_gotorc (row, col);
SLsmg_write_char (ch);
SLsmg_gotorc (row + 1, col);
SLsmg_set_char_set (1);
SLsmg_write_char (ch);
SLsmg_set_char_set (0);
col++;
if (col > 40)
{
col = 0;
row += 4;
}
}
post_test ();
}
typedef struct
{
char *name;
unsigned char value;
}
Draw_Symbols_Type;
static Draw_Symbols_Type Draw_Symbols [] =
{
{"SLSMG_HLINE_CHAR", SLSMG_HLINE_CHAR},
{"SLSMG_VLINE_CHAR", SLSMG_VLINE_CHAR},
{"SLSMG_ULCORN_CHAR", SLSMG_ULCORN_CHAR},
{"SLSMG_URCORN_CHAR", SLSMG_URCORN_CHAR},
{"SLSMG_LLCORN_CHAR", SLSMG_LLCORN_CHAR},
{"SLSMG_LRCORN_CHAR", SLSMG_LRCORN_CHAR},
{"SLSMG_RTEE_CHAR", SLSMG_RTEE_CHAR},
{"SLSMG_LTEE_CHAR", SLSMG_LTEE_CHAR},
{"SLSMG_UTEE_CHAR", SLSMG_UTEE_CHAR},
{"SLSMG_DTEE_CHAR", SLSMG_DTEE_CHAR},
{"SLSMG_PLUS_CHAR", SLSMG_PLUS_CHAR},
{"SLSMG_CKBRD_CHAR", SLSMG_CKBRD_CHAR},
{"SLSMG_DIAMOND_CHAR", SLSMG_DIAMOND_CHAR},
{"SLSMG_DEGREE_CHAR", SLSMG_DEGREE_CHAR},
{"SLSMG_PLMINUS_CHAR", SLSMG_PLMINUS_CHAR},
{"SLSMG_BULLET_CHAR", SLSMG_BULLET_CHAR},
{"SLSMG_LARROW_CHAR", SLSMG_LARROW_CHAR},
{"SLSMG_RARROW_CHAR", SLSMG_RARROW_CHAR},
{"SLSMG_DARROW_CHAR", SLSMG_DARROW_CHAR},
{"SLSMG_UARROW_CHAR", SLSMG_UARROW_CHAR},
{"SLSMG_BOARD_CHAR", SLSMG_BOARD_CHAR},
{"SLSMG_BLOCK_CHAR", SLSMG_BLOCK_CHAR},
{NULL}
};
static void draw_symbols_test (void)
{
int row, col;
Draw_Symbols_Type *d;
pre_test ("Alternate Charset Test");
row = 3;
col = 3;
d = Draw_Symbols;
while (d->name != NULL)
{
SLsmg_gotorc (row, col);
SLsmg_set_char_set (1);
SLsmg_write_char ((char) d->value);
SLsmg_set_char_set (0);
SLsmg_printf (":%s", d->name);
col += 40;
if (col >= 80)
{
col = 3;
row++;
}
d++;
}
post_test ();
}
static void line_test (void)
{
int row, col;
pre_test ("Line Test");
row = 4;
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 ();
}
static void do_esc_seq_test (char *testname)
{
int row;
unsigned char ch;
unsigned char buf[80], *b;
pre_test (testname);
while (1)
{
row = SLtt_Screen_Rows / 2;
SLsmg_gotorc (row, 0);
SLsmg_write_string ("Press key: (RETURN quits)");
SLsmg_refresh ();
ch = SLang_getkey ();
SLang_ungetkey (ch);
if (ch == '\r')
break;
SLsmg_gotorc (row+1, 0);
SLsmg_write_string ("Key returned \"");
b = buf;
do
{
ch = SLang_getkey ();
if (ch < ' ')
{
*b++ = '^';
ch += '@';
*b++ = ch;
}
else if (ch >= 127)
{
sprintf ((char *) b, "\\x%02X", ch);
b += strlen ((char *) b);
}
else if ((ch == '"') || (ch == '\\'))
{
*b++ = '\\';
*b++ = ch;
}
else *b++ = ch;
}
while (SLang_input_pending (3) > 0);
*b++ = '"';
*b = 0;
SLsmg_write_string ((char *) buf);
SLsmg_erase_eol ();
SLsmg_refresh ();
}
post_test ();
}
static void esc_seq_test (void)
{
#ifdef IBMPC_SYSTEM
SLgetkey_map_to_ansi (0);
#endif
do_esc_seq_test ("Escape Sequence Report");
}
#ifdef IBMPC_SYSTEM
static void ansi_esc_seq_test (void)
{
SLgetkey_map_to_ansi (1);
do_esc_seq_test ("ANSI Escape Sequence Report");
}
#endif
static void mouse_test (void)
{
int row;
int b, x, y;
pre_test ("Mouse Test");
row = SLtt_Screen_Rows / 2;
SLsmg_gotorc (row, 0);
SLsmg_write_string ("Click Mouse: ");
SLsmg_refresh ();
if ((27 != SLang_getkey ())
|| ('[' != SLang_getkey ())
|| ('M' != SLang_getkey ()))
{
SLsmg_gotorc (row, 0);
SLsmg_write_string ("That did not appear to be a mouse escape sequence");
post_test ();
return;
}
b = SLang_getkey () - ' ';
x = SLang_getkey () - ' ';
y = SLang_getkey () - ' ';
SLsmg_gotorc (row, 0); SLsmg_printf ("Button: %d ", b);
SLsmg_gotorc (row + 1, 0); SLsmg_printf ("Column: %d", x);
SLsmg_gotorc (row + 2, 0); SLsmg_printf (" Row: %d", y);
post_test ();
}
static void mono_test (void)
{
int row;
int c;
c = SLtt_Use_Ansi_Colors;
SLtt_Use_Ansi_Colors = 0;
SLsmg_normal_video ();
SLsmg_cls ();
pre_test ("Mono Test");
row = SLtt_Screen_Rows / 2;
SLsmg_set_color(1);
SLsmg_gotorc (row, 0);
/* Make a gap for testing erase_eol in bw mode */
SLsmg_write_string ("This line");
SLsmg_set_color (2);
SLsmg_erase_eol ();
SLsmg_gotorc (row, 30);
SLsmg_write_string ("should be in reverse video");
SLsmg_refresh ();
(void) SLkp_getkey ();
SLsmg_gotorc (row, 20);
SLsmg_write_string ("xxxxx");
SLsmg_refresh ();
post_test ();
SLtt_Use_Ansi_Colors = c;
}
static void low_level_test (void)
{
int mid, bot;
int r;
if (SLtt_Term_Cannot_Scroll)
{
pre_test ("Sorry! Your terminal lacks scrolling capability.");
post_test ();
return;
}
if (-1 == SLsmg_suspend_smg ())
SLang_exit_error ("SLsmg_suspend_smg failed");
if (-1 == SLtt_init_video ())
SLang_exit_error ("SLang_init_video failed");
SLtt_get_screen_size ();
mid = SLtt_Screen_Rows/2;
bot = SLtt_Screen_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 ();
(void) 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, SLtt_Screen_Cols - 5);
SLtt_write_string ("End->");
SLtt_flush_output ();
SLtt_set_scroll_region (mid, bot - 1);
r = (bot - mid) - 1;
while (r > 0)
{
(void) 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)
{
(void) SLang_input_pending (2); /* 3/10 sec delay */
SLtt_goto_rc (0,0); /* relative to scroll region */
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)
{
(void) SLang_input_pending (2); /* 3/10 sec delay */
SLtt_goto_rc (0,0); /* relative to scroll region */
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)
{
(void) SLang_input_pending (3); /* 3/10 sec delay */
SLtt_goto_rc (0,0); /* relative to scroll region */
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 ();
(void) SLang_getkey ();
SLtt_reset_video ();
SLsmg_resume_smg ();
}
|