1 /*
2  * This is a test program for PDCurses. Originally by
3  * John Burnell <johnb@kea.am.dsir.govt.nz>
4  *
5  *  wrs(5/28/93) -- modified to be consistent (perform identically)
6  *                  with either PDCurses or under Unix System V, R4
7  */
8 
9 #ifndef _XOPEN_SOURCE_EXTENDED
10 # define _XOPEN_SOURCE_EXTENDED 1
11 #endif
12 
13 #ifdef PDC_WIDE
14    #define HAVE_WIDE 1
15    #include <wchar.h>
16    #include <curses.h>
17 #endif
18 #ifdef HAVE_NCURSESW
19    #define HAVE_WIDE 1
20    #include <wchar.h>
21    #include <ncursesw/curses.h>
22 #endif
23 
24 #ifndef HAVE_WIDE
25    #include <curses.h>
26    #define HAVE_WIDE 0
27 #endif
28 
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <ctype.h>
32 #include <string.h>
33 #include <locale.h>
34 
35 #if defined( PDCURSES)
36    #define getmouse nc_getmouse
37 #else
38    #define NCURSES_MOUSE_INTERFACE
39 #endif
40 
41 
42 #if defined(PDCURSES) && !defined(XCURSES)
43 # define HAVE_RESIZE 1
44 #else
45 # define HAVE_RESIZE 0
46 #endif
47 
48 #ifdef A_COLOR
49 # define HAVE_COLOR 1
50 #else
51 # define HAVE_COLOR 0
52 #endif
53 
54 /* Set to non-zero if you want to test the PDCurses clipboard */
55 /* (obviously,  can't do that with ncurses) */
56 
57 #if defined( PDCURSES)
58    #define HAVE_CLIPBOARD 1
59 #else
60    #define HAVE_CLIPBOARD 0
61 #endif
62 
63 void inputTest(WINDOW *);
64 void scrollTest(WINDOW *);
65 void introTest(WINDOW *);
66 int initTest(WINDOW **, int, char **);
67 void outputTest(WINDOW *);
68 void padTest(WINDOW *);
69 void acsTest(WINDOW *);
70 
71 #if HAVE_COLOR
72 void colorTest(WINDOW *);
73 #endif
74 
75 #if HAVE_RESIZE
76 void resizeTest(WINDOW *);
77 #endif
78 
79 #if HAVE_CLIPBOARD
80 void clipboardTest(WINDOW *);
81 #endif
82 
83 #if HAVE_WIDE
84 void wideTest(WINDOW *);
85 #endif
86 
87 void display_menu(int, int);
88 
89 struct commands
90 {
91     const char *text;
92     void (*function)(WINDOW *);
93 };
94 
95 typedef struct commands COMMAND;
96 
97 #define MAX_OPTIONS (6 + HAVE_COLOR + HAVE_RESIZE + HAVE_CLIPBOARD + HAVE_WIDE)
98 
99 COMMAND command[MAX_OPTIONS] =
100 {
101     {"Intro Test", introTest},
102     {"Pad Test", padTest},
103 #if HAVE_RESIZE
104     {"Resize Test", resizeTest},
105 #endif
106     {"Scroll Test", scrollTest},
107     {"Input Test", inputTest},
108     {"Output Test", outputTest},
109     {"ACS Test", acsTest},
110 #if HAVE_COLOR
111     {"Color Test", colorTest},
112 #endif
113 #if HAVE_CLIPBOARD
114     {"Clipboard Test", clipboardTest},
115 #endif
116 #if HAVE_WIDE
117     {"Wide Input", wideTest}
118 #endif
119 };
120 
121 int width, height;
122 static short background_index = COLOR_BLACK;
123 static bool report_mouse_movement = FALSE;
124 
main(int argc,char * argv[])125 int main(int argc, char *argv[])
126 {
127     WINDOW *win;
128     int key, old_option = -1, new_option = 0, i;
129     bool quit = FALSE;
130 
131     setlocale(LC_ALL, "");
132 
133 #ifdef PDCURSES
134     PDC_set_resize_limits( 20, 50, 70, 200);
135 #endif
136 
137     if (initTest(&win, argc, argv))
138         return 1;
139 
140     for( i = 1; i < argc; i++)
141         if( argv[i][0] == '-')
142             switch( argv[i][1])
143             {
144                 case 'l': case 'L':
145                     setlocale( LC_ALL, argv[i] + 2);
146                     break;
147                 case 'i': case 'I':
148                     background_index = (short)atoi( argv[i] + 2);
149                     break;
150 #ifdef PDCURSES
151                 case 'b': case 'B':
152                     PDC_set_blink( TRUE);
153                     break;
154                 case 'm': case 'M':
155                     PDC_return_key_modifiers( TRUE);
156                     break;
157                 case 'r':     /* allow user-resizable windows */
158                     {
159                         int min_lines, max_lines, min_cols, max_cols;
160 
161                         if( sscanf( argv[i] + 2, "%d,%d,%d,%d",
162                                        &min_lines, &max_lines,
163                                        &min_cols, &max_cols) == 4)
164                             PDC_set_resize_limits( min_lines, max_lines,
165                                                    min_cols, max_cols);
166                     }
167                     break;
168 #endif
169                 case 'z':
170                     report_mouse_movement = TRUE;
171                     break;
172                 default:
173                     break;
174             }
175 
176 #ifdef A_COLOR
177     if (has_colors())
178     {
179         init_pair(1, COLOR_WHITE, COLOR_BLUE);
180         wbkgd(win, COLOR_PAIR(1));
181     }
182     else
183 #endif
184         wbkgd(win, A_REVERSE);
185 
186 #ifdef PDCURSES
187     PDC_set_function_key( FUNCTION_KEY_ABORT, 3 );  /* ctrl-C aborts */
188 #endif
189 
190     erase();
191     display_menu(old_option, new_option);
192 
193     while (1)
194     {
195         noecho();
196         keypad(stdscr, TRUE);
197         raw();
198         mousemask( ALL_MOUSE_EVENTS, NULL);
199 
200         key = getch();
201 
202         switch(key)
203         {
204         case KEY_MOUSE:
205             {
206                const int tmarg = (LINES - (MAX_OPTIONS + 2)) / 2;
207                int selected_opt;
208                MEVENT mouse_event;
209 
210                getmouse( &mouse_event);
211 
212                selected_opt = mouse_event.y - tmarg;
213                if( selected_opt >= 0 && selected_opt < MAX_OPTIONS)
214                {
215                   old_option = new_option;
216                   new_option = selected_opt;
217                   display_menu( old_option, new_option);
218                }
219                if( mouse_event.bstate & BUTTON1_DOUBLE_CLICKED)
220                   key = 10;
221             }
222             if( key != 10)
223                break;
224         case 10:
225         case 13:
226         case KEY_ENTER:
227             old_option = -1;
228             erase();
229             refresh();
230             (*command[new_option].function)(win);
231             erase();
232             display_menu(old_option, new_option);
233             break;
234 
235         case KEY_PPAGE:
236         case KEY_HOME:
237             old_option = new_option;
238             new_option = 0;
239             display_menu(old_option, new_option);
240             break;
241 
242         case KEY_NPAGE:
243         case KEY_END:
244             old_option = new_option;
245             new_option = MAX_OPTIONS - 1;
246             display_menu(old_option, new_option);
247             break;
248 
249         case KEY_UP:
250             old_option = new_option;
251             new_option = (new_option == 0) ?
252                 new_option : new_option - 1;
253             display_menu(old_option, new_option);
254             break;
255 
256         case KEY_DOWN:
257             old_option = new_option;
258             new_option = (new_option == MAX_OPTIONS - 1) ?
259                 new_option : new_option + 1;
260             display_menu(old_option, new_option);
261             break;
262         case KEY_RESIZE:
263 # ifdef PDCURSES
264             resize_term(0, 0);
265 # endif
266             old_option = -1;
267             erase();
268             display_menu(old_option, new_option);
269             break;
270         case 'Q':
271         case 'q':
272             quit = TRUE;
273         }
274 
275         if (quit == TRUE)
276             break;
277     }
278 
279     delwin(win);
280     endwin();
281 
282     return 0;
283 }
284 
Continue(WINDOW * win)285 void Continue(WINDOW *win)
286 {
287     mvwaddstr(win, 10, 1, " Press any key to continue");
288     wrefresh(win);
289     raw();
290     wgetch(win);
291     wrefresh(win);
292 }
293 
Continue2(void)294 void Continue2(void)
295 {
296     move(LINES - 1, 1);
297     clrtoeol();
298     mvaddstr(LINES - 2, 1, " Press any key to continue");
299     refresh();
300     raw();
301     getch();
302 }
303 
initTest(WINDOW ** win,int argc,char * argv[])304 int initTest(WINDOW **win, int argc, char *argv[])
305 {
306 #ifdef XCURSES
307     Xinitscr(argc, argv);
308 #else
309     initscr();
310 #endif
311 #ifdef A_COLOR
312     if (has_colors())
313         start_color();
314 #endif
315     /* Create a drawing window */
316 
317     width  = 60;
318     height = 19;
319 
320     *win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2);
321 
322     if (*win == NULL)
323     {
324         endwin();
325         return 1;
326     }
327 
328     return 0;
329 }
330 
introTest(WINDOW * win)331 void introTest(WINDOW *win)
332 {
333     werase(win);
334     wmove(win, height / 2 - 5, width / 2);
335     wvline(win, ACS_VLINE, 10);
336     wmove(win, height / 2, width / 2 - 10);
337     whline(win, ACS_HLINE, 20);
338     Continue(win);
339 
340     beep();
341     werase(win);
342 
343     box(win, ACS_VLINE, ACS_HLINE);
344     wrefresh(win);
345 
346     cbreak();
347     mvwaddstr(win, 1, 1,
348         "You should have a rectangle in the middle of the screen");
349     mvwaddstr(win, 2, 1, "You should have heard a beep");
350     Continue(win);
351 
352     flash();
353     mvwaddstr(win, 3, 1, "You should have seen a flash");
354     Continue(win);
355 }
356 
scrollTest(WINDOW * win)357 void scrollTest(WINDOW *win)
358 {
359     int i, OldY;
360 #ifndef PDCURSES
361     int OldX;
362 #endif
363     werase(win);
364     mvwaddstr(win, height - 2, 1, "The window will now scroll slowly");
365     box(win, ACS_VLINE, ACS_HLINE);
366     wrefresh(win);
367     scrollok(win, TRUE);
368     napms(500);
369 
370     for (i = 1; i <= height; i++)
371     {
372         napms(150);
373         scroll(win);
374         wrefresh(win);
375     };
376 
377 #ifdef PDCURSES
378     OldY = getmaxy(win);
379 #else
380     getmaxyx(win, OldY, OldX);
381 #endif
382     mvwaddstr(win, 6, 1, "The top of the window will scroll");
383     wmove(win, 1, 1);
384     wsetscrreg(win, 0, 4);
385     box(win, ACS_VLINE, ACS_HLINE);
386     wrefresh(win);
387 
388     for (i = 1; i <= 5; i++)
389     {
390         napms(500);
391         scroll(win);
392         wrefresh(win);
393     }
394 
395     mvwaddstr(win, 3, 1, "The bottom of the window will scroll");
396     wmove(win, 8, 1);
397     wsetscrreg(win, 5, --OldY);
398     box(win, ACS_VLINE, ACS_HLINE);
399     wrefresh(win);
400 
401     for (i = 5; i <= OldY; i++)
402     {
403         napms(300);
404         wscrl(win, -1);
405         wrefresh(win);
406     }
407 
408     wsetscrreg(win, 0, OldY);
409 }
410 
inputTest(WINDOW * win)411 void inputTest(WINDOW *win)
412 {
413     int w, h, bx, by, sw, sh, i, c, num = 0;
414     int line_to_use = 3;
415     char buffer[80];
416     WINDOW *subWin;
417     static const char spinner[4] = "/-\\|";
418     int spinner_count = 0;
419 
420     wclear(win);
421 
422     getmaxyx(win, h, w);
423     getbegyx(win, by, bx);
424 
425     sw = w / 3;
426     sh = h / 3;
427 
428     if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2))
429         == NULL)
430         return;
431 
432 #ifdef A_COLOR
433     if (has_colors())
434     {
435         init_pair(2, COLOR_WHITE, COLOR_RED);
436         wbkgd(subWin, COLOR_PAIR(2) | A_BOLD);
437     }
438     else
439 #endif
440         wbkgd(subWin, A_BOLD);
441 
442     box(subWin, ACS_VLINE, ACS_HLINE);
443     wrefresh(win);
444 
445     nocbreak();
446 
447     wclear (win);
448     mvwaddstr(win, 1, 1,
449         "Press keys (or mouse buttons) to show their names");
450     mvwaddstr(win, 2, 1, "Press spacebar to finish");
451     wrefresh(win);
452 
453     keypad(win, TRUE);
454     raw();
455     noecho();
456 
457     wtimeout(win, 200);
458 
459 
460     mousemask( ALL_MOUSE_EVENTS |
461             (report_mouse_movement ? REPORT_MOUSE_POSITION : 0), NULL);
462 #ifdef PDCURSES
463     PDC_save_key_modifiers(TRUE);
464 #else
465     if( report_mouse_movement)
466        printf("\033[?1003h\n");   /* used in ncurses with some X-based */
467 #endif                         /* terms to enable mouse move events */
468     curs_set(0);        /* turn cursor off */
469 
470     while (1)
471     {
472         while (1)
473         {
474             c = wgetch(win);
475 
476             if (c == ERR)
477             {
478                 spinner_count++;
479                 if (spinner_count == 4)
480                     spinner_count = 0;
481                 mvwaddch(win, line_to_use, 3, spinner[spinner_count]);
482                 wrefresh(win);
483             }
484             else
485                 break;
486         }
487 #ifdef PDCURSES
488 /*      wmove(win, line_to_use + 1, 18);
489         wclrtoeol(win);  */
490 #endif
491         mvwaddstr(win, line_to_use, 5, "Key Pressed: ");
492         wclrtoeol(win);
493 
494         wprintw( win, "(%x) ", c);
495         if( has_key( c))
496             wprintw(win, "%s", keyname(c));
497         else if (isprint(c) || c > 0xff)
498             waddch( win, c);
499         else
500             wprintw(win, "%s", unctrl(c));
501         if (c == KEY_MOUSE)
502         {
503 #ifdef NCURSES_MOUSE_INTERFACE
504             const mmask_t masks[ ] = {
505                   BUTTON1_RELEASED, BUTTON1_PRESSED, BUTTON1_CLICKED,
506                   BUTTON1_DOUBLE_CLICKED, BUTTON1_TRIPLE_CLICKED,
507                   BUTTON2_RELEASED, BUTTON2_PRESSED, BUTTON2_CLICKED,
508                   BUTTON2_DOUBLE_CLICKED, BUTTON2_TRIPLE_CLICKED,
509                   BUTTON3_RELEASED, BUTTON3_PRESSED, BUTTON3_CLICKED,
510                   BUTTON3_DOUBLE_CLICKED, BUTTON3_TRIPLE_CLICKED,
511                   BUTTON4_RELEASED, BUTTON4_PRESSED, BUTTON4_CLICKED,
512                   BUTTON4_DOUBLE_CLICKED, BUTTON4_TRIPLE_CLICKED,
513 #ifdef BUTTON5_RELEASED
514                   BUTTON5_RELEASED, BUTTON5_PRESSED, BUTTON5_CLICKED,
515                   BUTTON5_DOUBLE_CLICKED, BUTTON5_TRIPLE_CLICKED,
516 #endif
517                   };
518 #ifdef BUTTON4_RESERVED_EVENT
519             const mmask_t reserved_masks[] = {
520                   BUTTON1_RESERVED_EVENT, BUTTON2_RESERVED_EVENT,
521                   BUTTON3_RESERVED_EVENT, BUTTON4_RESERVED_EVENT };
522 #endif
523             MEVENT mouse_event;
524 
525             getmouse( &mouse_event);
526             wmove(win, line_to_use, 5);
527             wclrtoeol(win);
528             wprintw(win, "Posn: Y: %d X: %d", mouse_event.y, mouse_event.x);
529             for( i = 0; i < sizeof( masks) / sizeof( masks[0]); i++)
530                 if( mouse_event.bstate & masks[i])
531                 {
532                     const char *event_names[] = { "released", "pressed", "clicked",
533                             "double-clicked", "triple-clicked" };
534 
535                      wprintw( win, " Button %d %s", i / 5 + 1, event_names[i % 5]);
536                 }
537 #ifdef BUTTON_CTRL
538             if( mouse_event.bstate & BUTTON_CTRL)
539                   wprintw( win, " Ctrl");
540 #endif
541             if( mouse_event.bstate & BUTTON_ALT)
542                   wprintw( win, " Alt");
543             if( mouse_event.bstate & BUTTON_SHIFT)
544                   wprintw( win, " Shift");
545 #ifdef BUTTON4_RESERVED_EVENT
546             for( i = 0; i < sizeof( reserved_masks) / sizeof( reserved_masks[0]); i++)
547                 if( mouse_event.bstate & reserved_masks[i])
548                     wprintw( win, " Reserved %d", i + 1);
549 #endif
550 
551 #else          /* using the 'classic' (undocumented) Sys V mouse functions */
552             int button = 0, status = 0;
553             request_mouse_pos();
554 
555             if (BUTTON_CHANGED(1))
556                 button = 1;
557             else if (BUTTON_CHANGED(2))
558                 button = 2;
559             else if (BUTTON_CHANGED(3))
560                 button = 3;
561             else if (BUTTON_CHANGED(4))   /* added 21 Jan 2011: BJG */
562                 button = 4;
563             else if (BUTTON_CHANGED(5))
564                 button = 5;
565             if( button)
566                 status = (button > 3 ? Mouse_status.xbutton[(button) - 4] :
567                                        Mouse_status.button[(button) - 1]);
568 
569             wmove(win, line_to_use, 5);
570             wclrtoeol(win);
571             wprintw(win, "Button %d: ", button);
572 
573             if (MOUSE_MOVED)
574                 waddstr(win, "moved: ");
575             else if (MOUSE_WHEEL_UP)
576                 waddstr(win, "wheel up: ");
577             else if (MOUSE_WHEEL_DOWN)
578                 waddstr(win, "wheel dn: ");
579             else if (MOUSE_WHEEL_LEFT)
580                 waddstr(win, "wheel lt: ");
581             else if (MOUSE_WHEEL_RIGHT)
582                 waddstr(win, "wheel rt: ");
583             else if ((status & BUTTON_ACTION_MASK) == BUTTON_PRESSED)
584                 waddstr(win, "pressed: ");
585             else if ((status & BUTTON_ACTION_MASK) == BUTTON_CLICKED)
586                 waddstr(win, "clicked: ");
587             else if ((status & BUTTON_ACTION_MASK) == BUTTON_DOUBLE_CLICKED)
588                 waddstr(win, "double: ");
589             else if ((status & BUTTON_ACTION_MASK) == BUTTON_TRIPLE_CLICKED)
590                 waddstr(win, "triple: ");
591             else if( button)
592                 waddstr(win, "released: ");
593 
594             wprintw(win, "Posn: Y: %d X: %d", MOUSE_Y_POS, MOUSE_X_POS);
595             if (button && (status & BUTTON_MODIFIER_MASK))
596             {
597                 if (status & BUTTON_SHIFT)
598                     waddstr(win, " SHIFT");
599 
600                 if (status & BUTTON_CONTROL)
601                     waddstr(win, " CONTROL");
602 
603                 if (status & BUTTON_ALT)
604                     waddstr(win, " ALT");
605             }
606         }
607         else if (PDC_get_key_modifiers())
608         {
609             waddstr(win, " Modifier(s):");
610             if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_SHIFT)
611                 waddstr(win, " SHIFT");
612 
613             if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_CONTROL)
614                 waddstr(win, " CONTROL");
615 
616             if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_ALT)
617                 waddstr(win, " ALT");
618 
619             if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_NUMLOCK)
620                 waddstr(win, " NUMLOCK");
621 #endif            /* end of mouse display */
622         }
623         wrefresh(win);
624 
625         if (c == ' ')
626             break;
627         line_to_use++;
628         if( line_to_use == 17)
629            line_to_use = 3;
630     }
631 
632     wtimeout(win, -1);  /* turn off timeout() */
633     curs_set(1);        /* turn cursor back on */
634 
635 #ifdef PDCURSES
636     mouse_set(0L);
637     PDC_save_key_modifiers(FALSE);
638 /*  PDC_return_key_modifiers(FALSE);   */
639 #endif
640     wclear(win);
641 #ifdef PDCURSES
642     PDC_set_function_key( FUNCTION_KEY_ABORT, 0 );  /* un-abortable */
643 #endif
644     mvwaddstr(win, 2, 1, "Press some keys for 5 seconds");
645     mvwaddstr(win, 1, 1, "Pressing ^C should do nothing");
646     wrefresh(win);
647 
648     werase(subWin);
649     box(subWin, ACS_VLINE, ACS_HLINE);
650 
651     for (i = 0; i < 5; i++)
652     {
653         mvwprintw(subWin, 1, 1, "Time = %d", i);
654         wrefresh(subWin);
655         napms(1000);
656         flushinp();
657     }
658 
659 #ifdef PDCURSES
660     PDC_set_function_key( FUNCTION_KEY_ABORT, 3 );  /* ctrl-C aborts */
661 #endif
662 
663     delwin(subWin);
664     werase(win);
665     flash();
666     wrefresh(win);
667     napms(500);
668     flushinp();
669 
670     mvwaddstr(win, 2, 1, "Press a key, followed by ENTER");
671     wmove(win, 9, 10);
672     wrefresh(win);
673     echo();
674 
675     keypad(win, TRUE);
676     raw();
677     wgetnstr(win, buffer, 3);
678     flushinp();
679 
680     wmove(win, 9, 10);
681     wdelch(win);
682     mvwaddstr(win, 4, 1, "The character should now have been deleted");
683     Continue(win);
684 
685     refresh();
686     wclear(win);
687     echo();
688     buffer[0] = '\0';
689     mvwaddstr(win, 3, 2, "The window should have moved");
690     mvwaddstr(win, 4, 2,
691               "This text should have appeared without you pressing a key");
692     mvwaddstr(win, 6, 2, "Enter a number then a string separated by space");
693     mvwin(win, 2, 1);
694     wrefresh(win);
695     mvwscanw(win, 7, 6, "%d %s", &num, buffer);
696     mvwprintw(win, 8, 6, "String: %s Number: %d", buffer, num);
697     Continue(win);
698 
699     refresh();
700     wclear(win);
701     echo();
702     mvwaddstr(win, 3, 2, "Enter a 5 character string: ");
703     wgetnstr(win, buffer, 5);
704     mvwprintw(win, 4, 2, "String: %s", buffer);
705     Continue(win);
706 }
707 
outputTest(WINDOW * win)708 void outputTest(WINDOW *win)
709 {
710     WINDOW *win1;
711     char Buffer[80];
712     chtype ch;
713     int by, bx;
714 
715     nl();
716     wclear(win);
717     mvwaddstr(win, 1, 1, "You should now have a screen in the upper "
718                          "left corner, and this text should have wrapped");
719     waddstr(win,"\nThis text should be down\n");
720     waddstr(win,  "and broken into two here ^");
721     Continue(win);
722 
723     wclear(win);
724     wattron(win, A_BOLD);
725     mvwaddstr(win, 1, 1, "A new window will appear with this text in it");
726     mvwaddstr(win, 8, 1, "Press any key to continue");
727     wrefresh(win);
728     wgetch(win);
729 
730     getbegyx(win, by, bx);
731 
732     if (LINES < 24 || COLS < 75)
733     {
734         mvwaddstr(win, 5, 1, "Some tests have been skipped as they require a");
735         mvwaddstr(win, 6, 1, "display of at least 24 LINES by 75 COLUMNS");
736         Continue(win);
737     }
738     else
739     {
740         win1 = newwin(10, 50, 14, 25);
741 
742         if (win1 == NULL)
743         {
744             endwin();
745             return;
746         }
747 
748 #ifdef A_COLOR
749         if (has_colors())
750         {
751             init_pair(3, COLOR_BLUE, COLOR_WHITE);
752             wbkgd(win1, COLOR_PAIR(3));
753         }
754         else
755 #endif
756             wbkgd(win1, A_NORMAL);
757 
758         wclear(win1);
759         mvwaddstr(win1, 5, 1, "This text should appear; using overlay option");
760         copywin(win, win1, 0, 0, 0, 0, 9, 49, TRUE);
761         box(win1, ACS_VLINE, ACS_HLINE);
762         wmove(win1, 8, 26);
763         wrefresh(win1);
764         wgetch(win1);
765 
766         wclear(win1);
767 
768         wattron(win1, A_BLINK);
769         mvwaddstr(win1, 4, 1,
770                   "This blinking text should appear in only the second window");
771         wattroff(win1, A_BLINK);
772 
773         mvwin(win1, by, bx);
774         overlay(win, win1);
775         mvwin(win1, 14, 25);
776         wmove(win1, 8, 26);
777         wrefresh(win1);
778         wgetch(win1);
779 
780         delwin(win1);
781     }
782 
783     clear();
784     wclear(win);
785     wrefresh(win);
786     mvwaddstr(win, 6, 2, "This line shouldn't appear");
787     mvwaddstr(win, 4, 2, "Only half of the next line is visible");
788     mvwaddstr(win, 5, 2, "Only half of the next line is visible");
789     wmove(win, 6, 1);
790     wclrtobot(win);
791     wmove(win, 5, 20);
792     wclrtoeol(win);
793     mvwaddstr(win, 8, 2, "This line also shouldn't appear");
794     wmove(win, 8, 1);
795     winsdelln(win, -1);
796     Continue(win);
797 
798     wmove(win, 5, 9);
799     ch = winch(win);
800 
801     wclear(win);
802     wmove(win, 6, 2);
803     waddstr(win, "The next char should be l:  ");
804     winsch(win, ch);
805     Continue(win);
806 
807     mvwinsstr(win, 6, 2, "A1B2C3D4E5");
808     Continue(win);
809 
810     wmove(win, 5, 1);
811     winsdelln(win, 1);
812     mvwaddstr(win, 5, 2, "The lines below should have moved down");
813     Continue(win);
814 
815     wclear(win);
816     wmove(win, 2, 2);
817     wprintw(win, "This is a formatted string in a window: %d %s\n",
818             42, "is it");
819     mvwaddstr(win, 10, 1, "Enter a string: ");
820     wrefresh(win);
821     echo();
822     wscanw(win, "%s", Buffer);
823 
824     printw("This is a formatted string in stdscr: %d %s\n", 42, "is it");
825     mvaddstr(10, 1, "Enter a string: ");
826     scanw("%s", Buffer);
827 
828     wclear(win);
829     curs_set(2);
830     mvwaddstr(win, 1, 1, "The cursor should be in high-visibility mode");
831     Continue(win);
832 
833     wclear(win);
834     curs_set(0);
835     mvwaddstr(win, 1, 1, "The cursor should have disappeared");
836     Continue(win);
837 
838     wclear(win);
839     curs_set(1);
840     mvwaddstr(win, 1, 1, "The cursor should be normal");
841     Continue(win);
842 
843 #ifdef A_COLOR
844     if (has_colors())
845     {
846         wclear(win);
847         mvwaddstr(win, 1, 1, "Colors should change after you press a key");
848         Continue(win);
849 
850         init_pair(1, COLOR_RED, COLOR_WHITE);
851         wrefresh(win);
852     }
853 #endif
854     werase(win);
855     mvwaddstr(win, 1, 1, "Information About Your Terminal");
856     mvwaddstr(win, 3, 1, termname());
857     mvwaddstr(win, 4, 1, longname());
858 
859     if (termattrs() & A_BLINK)
860         mvwaddstr(win, 5, 1, "This terminal claims to support blinking.");
861     else
862         mvwaddstr(win, 5, 1, "This terminal does NOT support blinking.");
863 
864     mvwaddnstr(win, 7, 5, "Have a nice day!ok", 16);
865     wrefresh(win);
866 
867     mvwinnstr(win, 7, 5, Buffer, 18);
868     mvaddstr(LINES - 2, 10, Buffer);
869     refresh();
870     Continue(win);
871 }
872 
873 #if HAVE_RESIZE
resizeTest(WINDOW * dummy)874 void resizeTest(WINDOW *dummy)
875 {
876     WINDOW *win1;
877     int nwidth = 135, nheight = 52;
878     int owidth = COLS, oheight = LINES;
879 
880     savetty();
881 
882     resize_term(nheight, nwidth);
883 
884     clear();
885     refresh();
886 
887     win1 = newwin(10, 50, 14, 25);
888 
889     if (win1 == NULL)
890     {
891         endwin();
892         return;
893     }
894 
895 #ifdef A_COLOR
896     if (has_colors())
897     {
898         init_pair(3, COLOR_BLUE, COLOR_WHITE);
899         wattrset(win1, COLOR_PAIR(3));
900     }
901 
902     wclear(win1);
903 #endif
904     mvwaddstr(win1, 0, 0, "The screen may now be resized");
905     mvwprintw(win1, 1, 4, "Given size: %d by %d", nwidth, nheight);
906     mvwprintw(win1, 2, 4, "Actual size: %d by %d", COLS, LINES);
907     Continue(win1);
908 
909     wclear(win1);
910     resetty();
911 
912     mvwaddstr(win1, 0, 0, "The screen should now be reset");
913     mvwprintw(win1, 1, 6, "Old size: %d by %d", owidth, oheight);
914     mvwprintw(win1, 2, 6, "Size now: %d by %d", COLS, LINES);
915     Continue(win1);
916 
917     delwin(win1);
918 
919     clear();
920     refresh();
921 }
922 #endif /* HAVE_RESIZE */
923 
padTest(WINDOW * dummy)924 void padTest(WINDOW *dummy)
925 {
926     WINDOW *pad, *spad;
927 
928     pad = newpad(50, 100);
929     wattron(pad, A_REVERSE);
930     mvwaddstr(pad, 5, 2, "This is a new pad");
931     wattrset(pad, 0);
932     mvwaddstr(pad, 8, 0,
933         "The end of this line should be truncated here:except  now");
934     mvwaddstr(pad, 11, 1, "This line should not appear.It will now");
935     wmove(pad, 10, 1);
936     wclrtoeol(pad);
937     mvwaddstr(pad, 10, 1, " Press any key to continue");
938     prefresh(pad, 0, 0, 0, 0, 10, 45);
939     keypad(pad, TRUE);
940     raw();
941     wgetch(pad);
942 
943     spad = subpad(pad, 12, 25, 7, 52);
944     mvwaddstr(spad, 2, 2, "This is a new subpad");
945     box(spad, 0, 0);
946     prefresh(pad, 0, 0, 0, 0, 15, 75);
947     keypad(pad, TRUE);
948     raw();
949     wgetch(pad);
950 
951     mvwaddstr(pad, 35, 2, "This is displayed at line 35 in the pad");
952     mvwaddstr(pad, 40, 1, " Press any key to continue");
953     prefresh(pad, 30, 0, 0, 0, 10, 45);
954     keypad(pad, TRUE);
955     raw();
956     wgetch(pad);
957 
958     delwin(pad);
959 }
960 
961 #if HAVE_CLIPBOARD
clipboardTest(WINDOW * win)962 void clipboardTest(WINDOW *win)
963 {
964     static const char *text =
965         "This string placed in clipboard by PDCurses test program, testcurs.";
966     char *ptr = NULL;
967     long i, length = 0;
968 
969     mvaddstr(1, 1,
970              "This test will display the contents of the system clipboard");
971 
972     Continue2();
973 
974     scrollok(stdscr, TRUE);
975     i = PDC_getclipboard(&ptr, &length);
976 
977     switch(i)
978     {
979     case PDC_CLIP_ACCESS_ERROR:
980         mvaddstr(3, 1, "There was an error accessing the clipboard");
981         refresh();
982         break;
983 
984     case PDC_CLIP_MEMORY_ERROR:
985         mvaddstr(3, 1,
986             "Unable to allocate memory for clipboard contents");
987         break;
988 
989     case PDC_CLIP_EMPTY:
990         mvaddstr(3, 1, "There was no text in the clipboard");
991         break;
992 
993     default:
994         wsetscrreg(stdscr, 0, LINES - 1);
995         clear();
996         mvaddstr(1, 1, "Clipboard contents...");
997         mvprintw(2, 1, "%s\n", ptr);
998     }
999 
1000     Continue2();
1001 
1002     clear();
1003     mvaddstr(1, 1,
1004         "This test will place the following string in the system clipboard:");
1005     mvaddstr(2, 1, text);
1006 
1007     i = PDC_setclipboard(text, (long)strlen(text));
1008 
1009     switch(i)
1010     {
1011     case PDC_CLIP_ACCESS_ERROR:
1012         mvaddstr(3, 1, "There was an error accessing the clipboard");
1013         break;
1014 
1015     case PDC_CLIP_MEMORY_ERROR:
1016         mvaddstr(3, 1, "Unable to allocate memory for clipboard contents");
1017         break;
1018 
1019     default:
1020         mvaddstr(3, 1, "The string was placed in the clipboard successfully");
1021     }
1022 
1023     Continue2();
1024 }
1025 #endif /* HAVE_CLIPBOARD */
1026 
acsTest(WINDOW * win)1027 void acsTest(WINDOW *win)
1028 {
1029     static const char *acs_names[] =
1030     {
1031         "ACS_ULCORNER", "ACS_URCORNER", "ACS_LLCORNER", "ACS_LRCORNER",
1032         "ACS_LTEE", "ACS_RTEE", "ACS_TTEE", "ACS_BTEE", "ACS_HLINE",
1033         "ACS_VLINE", "ACS_PLUS",
1034 
1035 #ifdef ACS_D_ULCORNER
1036         "ACS_D_ULCORNER", "ACS_D_URCORNER", "ACS_D_LLCORNER", "ACS_D_LRCORNER",
1037         "ACS_D_LTEE", "ACS_D_RTEE", "ACS_D_TTEE", "ACS_D_BTEE", "ACS_D_HLINE",
1038         "ACS_D_VLINE", "ACS_D_PLUS",
1039 #endif
1040 #ifdef ACS_SD_ULCORNER
1041         "ACS_SD_ULCORNER", "ACS_SD_URCORNER", "ACS_SD_LLCORNER",
1042         "ACS_SD_LRCORNER", "ACS_SD_LTEE",
1043         "ACS_SD_RTEE", "ACS_SD_TTEE", "ACS_SD_BTEE", "ACS_SD_PLUS",
1044         "ACS_DS_ULCORNER", "ACS_DS_URCORNER", "ACS_DS_LLCORNER",
1045         "ACS_DS_LRCORNER", "ACS_DS_LTEE", "ACS_DS_RTEE", "ACS_DS_TTEE",
1046         "ACS_DS_BTEE", "ACS_DS_PLUS",
1047 #endif
1048         "ACS_S1",
1049 #ifdef ACS_S3
1050         "ACS_S3", "ACS_S7",
1051 #endif
1052         "ACS_S9", "ACS_DIAMOND",
1053 #ifdef ACS_CLUB
1054         "ACS_CLUB", "ACS_SPADE", "ACS_HEART",
1055         "ACS_LTBOARD",
1056 #endif
1057         "ACS_BOARD", "ACS_CKBOARD", "ACS_DEGREE", "ACS_PLMINUS",
1058         "ACS_BULLET",
1059 #ifdef ACS_SM_BULLET
1060         "ACS_SM_BULLET", "ACS_MED_BULLET", "ACS_WHITE_BULLET",
1061         "ACS_PILCROW", "ACS_SECTION", "ACS_SMILE", "ACS_REV_SMILE",
1062 #endif
1063         "ACS_LARROW", "ACS_RARROW", "ACS_UARROW", "ACS_DARROW",
1064         "ACS_LANTERN", "ACS_BLOCK",
1065 #ifdef ACS_LEQUAL
1066         "ACS_LEQUAL", "ACS_GEQUAL", "ACS_NEQUAL",
1067         "ACS_PI",  "ACS_STERLING",
1068 #endif
1069 #ifdef ACS_CENT
1070         "ACS_CENT", "ACS_YEN", "ACS_PESETA",
1071         "ACS_ALPHA", "ACS_BETA", "ACS_GAMMA", "ACS_UP_SIGMA",
1072         "ACS_LO_SIGMA", "ACS_MU", "ACS_TAU", "ACS_UP_PHI", "ACS_LO_PHI",
1073         "ACS_OMEGA", "ACS_DELTA", "ACS_INFINITY", "ACS_THETA", "ACS_EPSILON",
1074         "ACS_INTERSECT", "ACS_SUP2", "ACS_SUP_N", "ACS_TRIPLE_BAR",
1075         "ACS_APPROX_EQ", "ACS_SQUARE_ROOT", "ACS_NOT", "ACS_REV_NOT",
1076         "ACS_HALF", "ACS_QUARTER", "ACS_DIVISION",
1077         "ACS_UP_INTEGRAL", "ACS_LO_INTEGRAL",
1078         "ACS_UBLOCK", "ACS_BBLOCK",
1079         "ACS_LBLOCK", "ACS_RBLOCK",
1080         "ACS_A_ORDINAL", "ACS_O_ORDINAL",
1081         "ACS_INV_BANG", "ACS_INV_QUERY",
1082         "ACS_LEFT_ANG_QU", "ACS_RIGHT_ANG_QU",
1083         "ACS_CENTER_SQU", "ACS_F_WITH_HOOK",
1084 #endif
1085     };
1086 
1087     const chtype acs_values[] =
1088     {
1089         ACS_ULCORNER, ACS_URCORNER, ACS_LLCORNER, ACS_LRCORNER,
1090         ACS_LTEE, ACS_RTEE, ACS_TTEE, ACS_BTEE, ACS_HLINE,
1091         ACS_VLINE, ACS_PLUS,
1092 
1093 #ifdef ACS_D_ULCORNER
1094         ACS_D_ULCORNER, ACS_D_URCORNER, ACS_D_LLCORNER, ACS_D_LRCORNER,
1095         ACS_D_LTEE, ACS_D_RTEE, ACS_D_TTEE, ACS_D_BTEE, ACS_D_HLINE,
1096         ACS_D_VLINE, ACS_D_PLUS,
1097 #endif
1098 #ifdef ACS_SD_ULCORNER
1099         ACS_SD_ULCORNER, ACS_SD_URCORNER, ACS_SD_LLCORNER,
1100         ACS_SD_LRCORNER, ACS_SD_LTEE,
1101         ACS_SD_RTEE, ACS_SD_TTEE, ACS_SD_BTEE, ACS_SD_PLUS,
1102         ACS_DS_ULCORNER, ACS_DS_URCORNER, ACS_DS_LLCORNER,
1103         ACS_DS_LRCORNER, ACS_DS_LTEE, ACS_DS_RTEE, ACS_DS_TTEE,
1104         ACS_DS_BTEE, ACS_DS_PLUS,
1105 #endif
1106         ACS_S1,
1107 #ifdef ACS_S3
1108         ACS_S3, ACS_S7,
1109 #endif
1110         ACS_S9, ACS_DIAMOND,
1111 #ifdef ACS_CLUB
1112         ACS_CLUB, ACS_SPADE, ACS_HEART, ACS_LTBOARD,
1113 #endif
1114         ACS_BOARD, ACS_CKBOARD, ACS_DEGREE, ACS_PLMINUS, ACS_BULLET,
1115 #ifdef ACS_SM_BULLET
1116         ACS_SM_BULLET, ACS_MED_BULLET, ACS_WHITE_BULLET,
1117         ACS_PILCROW, ACS_SECTION, ACS_SMILE, ACS_REV_SMILE,
1118 #endif
1119         ACS_LARROW, ACS_RARROW, ACS_UARROW, ACS_DARROW,
1120         ACS_LANTERN, ACS_BLOCK,
1121 #ifdef ACS_LEQUAL
1122         ACS_LEQUAL, ACS_GEQUAL, ACS_NEQUAL,
1123         ACS_PI,  ACS_STERLING,
1124 #endif
1125 #ifdef ACS_CENT
1126         ACS_CENT, ACS_YEN, ACS_PESETA,
1127         ACS_ALPHA, ACS_BETA, ACS_GAMMA, ACS_UP_SIGMA,
1128         ACS_LO_SIGMA, ACS_MU, ACS_TAU, ACS_UP_PHI, ACS_LO_PHI,
1129         ACS_OMEGA, ACS_DELTA, ACS_INFINITY, ACS_THETA, ACS_EPSILON,
1130         ACS_INTERSECT, ACS_SUP2, ACS_SUP_N, ACS_TRIPLE_BAR,
1131         ACS_APPROX_EQ, ACS_SQUARE_ROOT, ACS_NOT, ACS_REV_NOT,
1132         ACS_HALF, ACS_QUARTER, ACS_DIVISION,
1133         ACS_UP_INTEGRAL, ACS_LO_INTEGRAL,
1134         ACS_UBLOCK, ACS_BBLOCK,
1135         ACS_LBLOCK, ACS_RBLOCK,
1136         ACS_A_ORDINAL, ACS_O_ORDINAL,
1137         ACS_INV_BANG, ACS_INV_QUERY,
1138         ACS_LEFT_ANG_QU, ACS_RIGHT_ANG_QU,
1139         ACS_CENTER_SQU, ACS_F_WITH_HOOK,
1140 #endif
1141     };
1142 
1143 #ifdef WACS_S1
1144     const cchar_t *wacs_values[] =
1145     {
1146         WACS_ULCORNER, WACS_URCORNER, WACS_LLCORNER, WACS_LRCORNER,
1147         WACS_LTEE, WACS_RTEE, WACS_TTEE, WACS_BTEE, WACS_HLINE,
1148         WACS_VLINE, WACS_PLUS,
1149 
1150 #ifdef WACS_D_ULCORNER
1151         WACS_D_ULCORNER, WACS_D_URCORNER, WACS_D_LLCORNER, WACS_D_LRCORNER,
1152         WACS_D_LTEE, WACS_D_RTEE, WACS_D_TTEE, WACS_D_BTEE, WACS_D_HLINE,
1153         WACS_D_VLINE, WACS_D_PLUS,
1154 #endif
1155 #ifdef WACS_SD_ULCORNER
1156         WACS_SD_ULCORNER, WACS_SD_URCORNER, WACS_SD_LLCORNER,
1157         WACS_SD_LRCORNER, WACS_SD_LTEE,
1158         WACS_SD_RTEE, WACS_SD_TTEE, WACS_SD_BTEE, WACS_SD_PLUS,
1159         WACS_DS_ULCORNER, WACS_DS_URCORNER, WACS_DS_LLCORNER,
1160         WACS_DS_LRCORNER, WACS_DS_LTEE, WACS_DS_RTEE, WACS_DS_TTEE,
1161         WACS_DS_BTEE, WACS_DS_PLUS,
1162 #endif
1163         WACS_S1,
1164 #ifdef WACS_S3
1165         WACS_S3, WACS_S7,
1166 #endif
1167         WACS_S9, WACS_DIAMOND,
1168 #ifdef WACS_CLUB
1169         WACS_CLUB, WACS_SPADE, WACS_HEART, WACS_LTBOARD,
1170 #endif
1171         WACS_BOARD, WACS_CKBOARD, WACS_DEGREE, WACS_PLMINUS, WACS_BULLET,
1172 #ifdef WACS_SM_BULLET
1173         WACS_SM_BULLET, WACS_MED_BULLET, WACS_WHITE_BULLET,
1174         WACS_PILCROW, WACS_SECTION, WACS_SMILE, WACS_REV_SMILE,
1175 #endif
1176         WACS_LARROW, WACS_RARROW, WACS_UARROW, WACS_DARROW,
1177         WACS_LANTERN, WACS_BLOCK,
1178 #ifdef WACS_LEQUAL
1179         WACS_LEQUAL, WACS_GEQUAL, WACS_NEQUAL,
1180         WACS_PI,  WACS_STERLING,
1181 #endif
1182 #ifdef WACS_CENT
1183         WACS_CENT, WACS_YEN, WACS_PESETA,
1184         WACS_ALPHA, WACS_BETA, WACS_GAMMA, WACS_UP_SIGMA,
1185         WACS_LO_SIGMA, WACS_MU, WACS_TAU, WACS_UP_PHI, WACS_LO_PHI,
1186         WACS_OMEGA, WACS_DELTA, WACS_INFINITY, WACS_THETA, WACS_EPSILON,
1187         WACS_INTERSECT, WACS_SUP2, WACS_SUP_N, WACS_TRIPLE_BAR,
1188         WACS_APPROX_EQ, WACS_SQUARE_ROOT, WACS_NOT, WACS_REV_NOT,
1189         WACS_HALF, WACS_QUARTER, WACS_DIVISION,
1190         WACS_UP_INTEGRAL, WACS_LO_INTEGRAL,
1191         WACS_UBLOCK, WACS_BBLOCK,
1192         WACS_LBLOCK, WACS_RBLOCK,
1193         WACS_A_ORDINAL, WACS_O_ORDINAL,
1194         WACS_INV_BANG, WACS_INV_QUERY,
1195         WACS_LEFT_ANG_QU, WACS_RIGHT_ANG_QU,
1196         WACS_CENTER_SQU, WACS_F_WITH_HOOK,
1197 #endif               /* #if WACS_CENT */
1198     };
1199 #endif               /* #ifdef WACS_S1   */
1200 
1201 #ifdef WACS_S1
1202     static const wchar_t russian[] = {0x0420, 0x0443, 0x0441, 0x0441,
1203         0x043a, 0x0438, 0x0439, L' ', 0x044f, 0x0437, 0x044b, 0x043a, 0};
1204 
1205     static const wchar_t greek[] = {0x0395, 0x03bb, 0x03bb, 0x03b7,
1206         0x03bd, 0x03b9, 0x03ba, 0x03ac, 0};
1207 
1208     static const wchar_t georgian[] = {0x10e5, 0x10d0, 0x10e0, 0x10d7,
1209         0x10e3, 0x10da, 0x10d8, L' ', 0x10d4, 0x10dc, 0x10d0, 0};
1210 
1211     static const wchar_t fullwidth[] = { 0xff26, 0xff55, 0xff4c, 0xff4c,
1212         0xff57, 0xff49, 0xff44, 0xff54, 0xff48, 0 };  /* "Fullwidth" */
1213 #endif
1214 
1215     int i, tmarg = 1, ncols = (COLS - 4) / 19;
1216     int col_size = (COLS - 4) / ncols;
1217     int n_items = sizeof( acs_names) / sizeof( acs_names[0]);
1218     int n_rows = LINES / 2 - 4;
1219 
1220     i = 0;
1221     while( i < n_items)
1222     {
1223         int j, xloc = 3;
1224 
1225         attrset(A_BOLD);
1226         mvaddstr( 1, (COLS - 23) / 2, "Alternate Character Set");
1227         attrset(A_NORMAL);
1228         tmarg = 4;
1229         while( i < n_items && xloc < COLS - col_size)
1230         {
1231             for( j = 0; i < n_items && j < n_rows; j++, i++)
1232             {
1233                 move( j * 2 + tmarg, xloc);
1234                 addch(acs_values[i]);
1235                 printw(" %s", acs_names[i]);
1236             }
1237             xloc += col_size;
1238         }
1239 
1240         mvaddstr( tmarg + n_rows * 2, 3, curses_version( ));
1241         move( tmarg + n_rows * 2 + 1, 3);
1242         printw( "sizeof( chtype) = %d; sizeof( mmask_t) = %d",
1243                            (int)sizeof( chtype), (int)sizeof( mmask_t));
1244         mvaddstr(tmarg + n_rows * 2 + 2, 3, "Press any key to continue");
1245         getch();
1246         clear( );
1247     }
1248 
1249 #if HAVE_WIDE
1250     i = 0;
1251     while( i < n_items)
1252     {
1253         int j, xloc = 3;
1254 
1255         attrset(A_BOLD);
1256         mvaddstr( 1, (COLS - 28) / 2, "Wide Alternate Character Set");
1257         attrset(A_NORMAL);
1258         tmarg = 4;
1259 #ifdef WACS_S1
1260         while( i < n_items && xloc < COLS - col_size)
1261         {
1262             for( j = 0; i < n_items && j < n_rows; j++, i++)
1263             {
1264                 move( j * 2 + tmarg, xloc);
1265                 add_wch( wacs_values[i]);
1266                 printw(" W%s", acs_names[i]);
1267             }
1268             xloc += col_size;
1269         }
1270 #endif
1271     /* Spanish, Russian, Greek, Georgian, fullwidth */
1272 
1273         tmarg += n_rows * 2;
1274         mvaddwstr(tmarg, COLS / 8 - 5, L"Espa\xf1ol");
1275         mvaddwstr(tmarg, 3 * (COLS / 8) - 5, russian);
1276         mvaddwstr(tmarg, 5 * (COLS / 8) - 5, greek);
1277         mvaddwstr(tmarg, 7 * (COLS / 8) - 5, georgian);
1278         mvaddwstr(tmarg + 1, COLS / 8 - 5, fullwidth);
1279 
1280 #if(CHTYPE_LONG >= 2)       /* "non-standard" 64-bit chtypes     */
1281         mvaddch( tmarg + 1, 7 * (COLS / 8) - 5, (chtype)0x1d11e);
1282 #endif            /* U+1D11E = musical symbol G clef */
1283 
1284         mvaddstr(tmarg + 2, 3, "Press any key to continue");
1285         getch();
1286         clear( );
1287     }
1288 #endif
1289 }
1290 
1291 #if HAVE_COLOR
1292 
1293 #if CHTYPE_LONG >= 2 || (CHTYPE_LONG == 1 && !defined( PDC_WIDE))
1294    #define GOT_DIM
1295    #define GOT_OVERLINE
1296    #define GOT_STRIKEOUT
1297 #endif
1298 
colorTest(WINDOW * win)1299 void colorTest(WINDOW *win)
1300 {
1301     static const short colors[] =
1302     {
1303         COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_BLUE,
1304         COLOR_CYAN, COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE
1305     };
1306 
1307     static const char *colornames[] =
1308     {
1309         "COLOR_BLACK", "COLOR_RED", "COLOR_GREEN", "COLOR_BLUE",
1310         "COLOR_CYAN", "COLOR_MAGENTA", "COLOR_YELLOW", "COLOR_WHITE"
1311     };
1312 
1313     chtype fill = ACS_BLOCK;
1314 
1315     int i, j, tmarg, col1, col2, col3, col4, ch;
1316 
1317     if (!has_colors())
1318         return;
1319 
1320     do
1321     {
1322         tmarg = (LINES - 19) / 2;
1323         col1 = (COLS - 60) / 2;
1324         col2 = col1 + 15;
1325         col3 = col2 + 15;
1326         col4 = col3 + 15;
1327 
1328         attrset(A_BOLD);
1329         mvaddstr(tmarg, (COLS - 22) / 2, "Color Attribute Macros");
1330         attrset(A_NORMAL);
1331 
1332         mvaddstr(tmarg + 3, col2 + 2, "A_NORMAL");
1333         mvaddstr(tmarg + 3, col3 + 3, "A_BOLD");
1334         mvaddstr(tmarg + 3, col4 + 3, "A_BLINK");
1335 
1336         for (i = 0; i < 8; i++)
1337         {
1338             init_pair((short)(i + 4), colors[i], background_index);
1339             mvaddstr(tmarg + i + 5, col1, colornames[i]);
1340 
1341             for (j = 0; j < 12; j++)
1342             {
1343                 mvaddch(tmarg + i + 5, col2 + j, fill | COLOR_PAIR(i + 4));
1344                 mvaddch(tmarg + i + 5, col3 + j, fill | COLOR_PAIR(i + 4) | A_BOLD);
1345                 mvaddch(tmarg + i + 5, col4 + j, fill | COLOR_PAIR(i + 4) | A_BLINK);
1346             }
1347             attrset( COLOR_PAIR( i + 4) | A_BLINK);
1348             mvaddstr( tmarg + i + 5, col4 + 5, "Text");
1349             attrset( COLOR_PAIR( i + 4) | A_BOLD);
1350             mvaddstr( tmarg + i + 5, col3 + 5, "Text");
1351             attroff( A_BOLD);
1352             mvaddstr( tmarg + i + 5, col2 + 5, "Text");
1353             attrset( A_NORMAL);
1354         }
1355 
1356         mvprintw(tmarg + 15, col1, "COLORS = %d", COLORS);
1357         mvprintw(tmarg + 16, col1, "COLOR_PAIRS = %d", COLOR_PAIRS);
1358 
1359 #ifdef CHTYPE_LONG
1360         attrset(A_ITALIC);
1361         mvprintw( tmarg + 15, col3, "Italic");
1362         attrset(A_ITALIC | A_BLINK);
1363         mvprintw( tmarg + 15, col4, "Italic Blink");
1364         attrset(A_BOLD | A_ITALIC);
1365         mvprintw( tmarg + 17, col4, "Italic Bold");
1366         attrset(A_BOLD | A_ITALIC | A_BLINK);
1367         mvprintw( tmarg + 18, col4, "Italic Blink Bold");
1368 #endif
1369         attrset(A_BOLD);
1370         mvprintw( tmarg + 16, col3, "Bold");
1371         attrset(A_BLINK);
1372         mvprintw( tmarg + 17, col3, "Blink");
1373 
1374         attrset(A_BLINK | A_BOLD);
1375         mvprintw( tmarg + 16, col4, "Blink Bold");
1376 /* end BJG addenda */
1377         attrset(A_NORMAL);
1378 
1379         mvaddstr(tmarg + 19, 3, "Press any key to continue");
1380         ch = getch();
1381 # ifdef PDCURSES
1382         if( ch == KEY_RESIZE)
1383         {
1384             erase();
1385             resize_term(0, 0);
1386         }
1387 # endif
1388     }  while( ch == KEY_RESIZE);
1389 
1390     if (can_change_color())
1391     {
1392         struct
1393         {
1394             short red, green, blue;
1395         } orgcolors[16];
1396 
1397         int MAXCOL = (COLORS >= 16) ? 16 : 8;
1398 
1399         if (MAXCOL < 8)
1400             return;
1401 
1402         for (i = 0; i < MAXCOL; i++)
1403             color_content((short)i, &(orgcolors[i].red),
1404                                     &(orgcolors[i].green),
1405                                     &(orgcolors[i].blue));
1406 
1407         attrset(A_BOLD);
1408         mvaddstr(tmarg, (COLS - 22) / 2, " init_color() Example ");
1409         attrset(A_NORMAL);
1410 
1411         refresh();
1412 
1413         for (i = 0; i < 8; i++)
1414         {
1415             init_color(colors[i], (short)(i * 125), 0, (short)(i * 125));
1416 
1417             if (MAXCOL == 16)
1418                 init_color((short)(colors[i] + 8), 0, (short)(i * 125), 0);
1419         }
1420 
1421         mvaddstr(tmarg + 19, 3, "Press any key to continue");
1422         getch();
1423         for (i = 0; i < MAXCOL; i++)
1424             init_color((short)i, orgcolors[i].red,
1425                                  orgcolors[i].green,
1426                                  orgcolors[i].blue);
1427     }
1428 /* BJG additions: */
1429     if( LINES >= 18) do  /* show off all 256 colors */
1430     {
1431        tmarg = LINES / 2 - 8;
1432        erase( );
1433        for( i = 0; i < COLOR_PAIRS; i++)
1434            {
1435            char tbuff[4];
1436            const int col = COLS / 2 - 24;
1437 
1438            if( i >= 16)
1439               init_pair((short)i, (short)i, COLOR_BLACK);
1440            attrset( COLOR_PAIR( i) | A_REVERSE);
1441            sprintf( tbuff, "%02x ", i);
1442            mvaddstr( tmarg + i / 16, col + (i % 16) * 3, tbuff);
1443            }
1444 #ifdef CHTYPE_LONG
1445        attrset( A_LEFTLINE);
1446        mvaddstr( tmarg + 17, col1, "A_LEFTLINE");
1447        attrset( A_UNDERLINE);
1448        mvaddstr( tmarg + 18, col1, "A_UNDERLINE");
1449        attrset( A_RIGHTLINE);
1450        mvaddstr( tmarg + 19, col1, "A_RIGHTLINE");
1451 #endif
1452 #ifdef GOT_OVERLINE
1453        attrset( A_OVERLINE);
1454        mvaddstr( tmarg + 17, col2, "A_OVERLINE");
1455        attrset( A_STRIKEOUT);
1456        mvaddstr( tmarg + 18, col2, "A_STRIKEOUT");
1457        attrset( A_OVERLINE | A_UNDERLINE);
1458        mvaddstr( tmarg + 19, col2, "Over/underlined");
1459 #endif
1460        attrset(A_NORMAL);
1461        refresh( );
1462        ch = getch( );
1463 # ifdef PDCURSES
1464         if( ch == KEY_RESIZE)
1465             resize_term(0, 0);
1466 # endif
1467     } while( ch == KEY_RESIZE);
1468 }
1469 #endif
1470 
1471 #if HAVE_WIDE
wideTest(WINDOW * win)1472 void wideTest(WINDOW *win)
1473 {
1474     wchar_t tmp[513];
1475     size_t i;
1476 
1477     attrset(A_BOLD);
1478     mvaddstr(1, (COLS - 25) / 2, "Wide Character Input Test");
1479     attrset(A_NORMAL);
1480 
1481     mvaddstr(4, 1, "Enter a string: ");
1482 
1483     echo();
1484 
1485     get_wstr((wint_t *)tmp);
1486     addstr("\n\n String:\n\n ");
1487     addwstr(tmp);
1488     addstr("\n\n\n Hex:\n\n ");
1489 
1490     for (i = 0; i < wcslen(tmp); i++)
1491     {
1492         printw("%04x ", tmp[i]);
1493         addnwstr(tmp + i, 1);
1494         addstr("  ");
1495     }
1496 
1497     noecho();
1498 
1499     Continue2();
1500 }
1501 #endif
1502 
display_menu(int old_option,int new_option)1503 void display_menu(int old_option, int new_option)
1504 {
1505     int lmarg = (COLS - 14) / 2,
1506         tmarg = (LINES - (MAX_OPTIONS + 2)) / 2;
1507 
1508     if (old_option == -1)
1509     {
1510         int i;
1511 
1512         attrset(A_BOLD);
1513         mvaddstr(tmarg - 3, lmarg - 5, "PDCurses Test Program");
1514         attrset(A_NORMAL);
1515 
1516         for (i = 0; i < MAX_OPTIONS; i++)
1517             mvaddstr(tmarg + i, lmarg, command[i].text);
1518     }
1519     else
1520         mvaddstr(tmarg + old_option, lmarg, command[old_option].text);
1521 
1522     attrset(A_REVERSE);
1523     mvaddstr(tmarg + new_option, lmarg, command[new_option].text);
1524     attrset(A_NORMAL);
1525 
1526     mvaddstr(tmarg + MAX_OPTIONS + 2, lmarg - 23,
1527              "Use Up and Down Arrows to select - Enter to run - Q to quit");
1528     refresh();
1529 }
1530