drivers/wifi: Remove unnecessary data structure copy
[coreboot2.git] / payloads / libpayload / curses / PDCurses / demos / testcurs.c
blob54d44f42d98391a3a23833cab117256a97d6ad60
1 /*
2 * This is a test program for PDCurses. Originally by
3 * John Burnell <johnb@kea.am.dsir.govt.nz>
5 * wrs(5/28/93) -- modified to be consistent (perform identically)
6 * with either PDCurses or under Unix System V, R4
8 * $Id: testcurs.c,v 1.85 2008/07/14 12:35:23 wmcbrine Exp $
9 */
11 #ifndef _XOPEN_SOURCE_EXTENDED
12 # define _XOPEN_SOURCE_EXTENDED 1
13 #endif
15 #include <stdio.h>
16 #include <ctype.h>
17 #include <string.h>
18 #include <curses.h>
20 #ifdef WACS_S1
21 # define HAVE_WIDE 1
22 #else
23 # define HAVE_WIDE 0
24 #endif
26 #include <locale.h>
28 #if HAVE_WIDE
29 # include <wchar.h>
30 #endif
32 #if defined(PDCURSES) && !defined(XCURSES)
33 # define HAVE_RESIZE 1
34 #else
35 # define HAVE_RESIZE 0
36 #endif
38 #ifdef A_COLOR
39 # define HAVE_COLOR 1
40 #else
41 # define HAVE_COLOR 0
42 #endif
44 /* Set to non-zero if you want to test the PDCurses clipboard */
46 #define HAVE_CLIPBOARD 0
48 void inputTest(WINDOW *);
49 void scrollTest(WINDOW *);
50 void introTest(WINDOW *);
51 int initTest(WINDOW **, int, char **);
52 void outputTest(WINDOW *);
53 void padTest(WINDOW *);
54 void acsTest(WINDOW *);
56 #if HAVE_COLOR
57 void colorTest(WINDOW *);
58 #endif
60 #if HAVE_RESIZE
61 void resizeTest(WINDOW *);
62 #endif
64 #if HAVE_CLIPBOARD
65 void clipboardTest(WINDOW *);
66 #endif
68 #if HAVE_WIDE
69 void wideTest(WINDOW *);
70 #endif
72 void display_menu(int, int);
74 struct commands
76 const char *text;
77 void (*function)(WINDOW *);
80 typedef struct commands COMMAND;
82 #define MAX_OPTIONS (6 + HAVE_COLOR + HAVE_RESIZE + HAVE_CLIPBOARD + HAVE_WIDE)
84 COMMAND command[MAX_OPTIONS] =
86 {"Intro Test", introTest},
87 {"Pad Test", padTest},
88 #if HAVE_RESIZE
89 {"Resize Test", resizeTest},
90 #endif
91 {"Scroll Test", scrollTest},
92 {"Input Test", inputTest},
93 {"Output Test", outputTest},
94 {"ACS Test", acsTest},
95 #if HAVE_COLOR
96 {"Color Test", colorTest},
97 #endif
98 #if HAVE_CLIPBOARD
99 {"Clipboard Test", clipboardTest},
100 #endif
101 #if HAVE_WIDE
102 {"Wide Input", wideTest}
103 #endif
106 int width, height;
108 int main(int argc, char *argv[])
110 WINDOW *win;
111 int key, old_option = -1, new_option = 0;
112 bool quit = FALSE;
114 setlocale(LC_ALL, "");
116 if (initTest(&win, argc, argv))
117 return 1;
119 #ifdef A_COLOR
120 if (has_colors())
122 init_pair(1, COLOR_WHITE, COLOR_BLUE);
123 wbkgd(win, COLOR_PAIR(1));
125 else
126 #endif
127 wbkgd(win, A_REVERSE);
129 erase();
130 display_menu(old_option, new_option);
132 while (1)
134 noecho();
135 keypad(stdscr, TRUE);
136 raw();
138 key = getch();
140 switch(key)
142 case 10:
143 case 13:
144 case KEY_ENTER:
145 old_option = -1;
146 erase();
147 refresh();
148 (*command[new_option].function)(win);
149 erase();
150 display_menu(old_option, new_option);
151 break;
153 case KEY_PPAGE:
154 case KEY_HOME:
155 old_option = new_option;
156 new_option = 0;
157 display_menu(old_option, new_option);
158 break;
160 case KEY_NPAGE:
161 case KEY_END:
162 old_option = new_option;
163 new_option = MAX_OPTIONS - 1;
164 display_menu(old_option, new_option);
165 break;
167 case KEY_UP:
168 old_option = new_option;
169 new_option = (new_option == 0) ?
170 new_option : new_option - 1;
171 display_menu(old_option, new_option);
172 break;
174 case KEY_DOWN:
175 old_option = new_option;
176 new_option = (new_option == MAX_OPTIONS - 1) ?
177 new_option : new_option + 1;
178 display_menu(old_option, new_option);
179 break;
180 #ifdef KEY_RESIZE
181 case KEY_RESIZE:
182 # ifdef PDCURSES
183 resize_term(0, 0);
184 # endif
185 old_option = -1;
186 erase();
187 display_menu(old_option, new_option);
188 break;
189 #endif
190 case 'Q':
191 case 'q':
192 quit = TRUE;
195 if (quit == TRUE)
196 break;
199 delwin(win);
200 endwin();
202 return 0;
205 void Continue(WINDOW *win)
207 mvwaddstr(win, 10, 1, " Press any key to continue");
208 wrefresh(win);
209 raw();
210 wgetch(win);
213 void Continue2(void)
215 move(LINES - 1, 1);
216 clrtoeol();
217 mvaddstr(LINES - 2, 1, " Press any key to continue");
218 refresh();
219 raw();
220 getch();
223 int initTest(WINDOW **win, int argc, char *argv[])
225 #ifdef XCURSES
226 Xinitscr(argc, argv);
227 #else
228 initscr();
229 #endif
230 #ifdef A_COLOR
231 if (has_colors())
232 start_color();
233 #endif
234 /* Create a drawing window */
236 width = 60;
237 height = 13;
239 *win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2);
241 if (*win == NULL)
243 endwin();
244 return 1;
247 return 0;
250 void introTest(WINDOW *win)
252 werase(win);
253 wmove(win, height / 2 - 5, width / 2);
254 wvline(win, ACS_VLINE, 10);
255 wmove(win, height / 2, width / 2 - 10);
256 whline(win, ACS_HLINE, 20);
257 Continue(win);
259 beep();
260 werase(win);
262 box(win, ACS_VLINE, ACS_HLINE);
263 wrefresh(win);
265 cbreak();
266 mvwaddstr(win, 1, 1,
267 "You should have a rectangle in the middle of the screen");
268 mvwaddstr(win, 2, 1, "You should have heard a beep");
269 Continue(win);
271 flash();
272 mvwaddstr(win, 3, 1, "You should have seen a flash");
273 Continue(win);
276 void scrollTest(WINDOW *win)
278 int i, OldY;
279 #ifndef PDCURSES
280 int OldX;
281 #endif
282 werase(win);
283 mvwaddstr(win, height - 2, 1, "The window will now scroll slowly");
284 box(win, ACS_VLINE, ACS_HLINE);
285 wrefresh(win);
286 scrollok(win, TRUE);
287 napms(500);
289 for (i = 1; i <= height; i++)
291 napms(150);
292 scroll(win);
293 wrefresh(win);
296 #ifdef PDCURSES
297 OldY = getmaxy(win);
298 #else
299 getmaxyx(win, OldY, OldX);
300 #endif
301 mvwaddstr(win, 6, 1, "The top of the window will scroll");
302 wmove(win, 1, 1);
303 wsetscrreg(win, 0, 4);
304 box(win, ACS_VLINE, ACS_HLINE);
305 wrefresh(win);
307 for (i = 1; i <= 5; i++)
309 napms(500);
310 scroll(win);
311 wrefresh(win);
314 mvwaddstr(win, 3, 1, "The bottom of the window will scroll");
315 wmove(win, 8, 1);
316 wsetscrreg(win, 5, --OldY);
317 box(win, ACS_VLINE, ACS_HLINE);
318 wrefresh(win);
320 for (i = 5; i <= OldY; i++)
322 napms(300);
323 wscrl(win, -1);
324 wrefresh(win);
327 wsetscrreg(win, 0, OldY);
330 void inputTest(WINDOW *win)
332 int w, h, bx, by, sw, sh, i, c, num = 0;
333 char buffer[80];
334 WINDOW *subWin;
335 static const char spinner[4] = "/-\\|";
336 int spinner_count = 0;
338 wclear(win);
340 getmaxyx(win, h, w);
341 getbegyx(win, by, bx);
343 sw = w / 3;
344 sh = h / 3;
346 if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2))
347 == NULL)
348 return;
350 #ifdef A_COLOR
351 if (has_colors())
353 init_pair(2, COLOR_WHITE, COLOR_RED);
354 wbkgd(subWin, COLOR_PAIR(2) | A_BOLD);
356 else
357 #endif
358 wbkgd(subWin, A_BOLD);
360 box(subWin, ACS_VLINE, ACS_HLINE);
361 wrefresh(win);
363 nocbreak();
365 wclear (win);
366 mvwaddstr(win, 1, 1,
367 "Press keys (or mouse buttons) to show their names");
368 mvwaddstr(win, 2, 1, "Press spacebar to finish");
369 wrefresh(win);
371 keypad(win, TRUE);
372 raw();
373 noecho();
375 wtimeout(win, 200);
377 #ifdef PDCURSES
378 mouse_set(ALL_MOUSE_EVENTS);
379 PDC_save_key_modifiers(TRUE);
380 PDC_return_key_modifiers(TRUE);
381 #endif
382 curs_set(0); /* turn cursor off */
384 while (1)
386 while (1)
388 c = wgetch(win);
390 if (c == ERR)
392 spinner_count++;
393 if (spinner_count == 4)
394 spinner_count = 0;
395 mvwaddch(win, 3, 3, spinner[spinner_count]);
396 wrefresh(win);
398 else
399 break;
401 #ifdef PDCURSES
402 wmove(win, 4, 18);
403 wclrtoeol(win);
404 #endif
405 mvwaddstr(win, 3, 5, "Key Pressed: ");
406 wclrtoeol(win);
408 if (c >= KEY_MIN)
409 wprintw(win, "%s", keyname(c));
410 else if (isprint(c))
411 wprintw(win, "%c", c);
412 else
413 wprintw(win, "%s", unctrl(c));
414 #ifdef PDCURSES
415 if (c == KEY_MOUSE)
417 int button = 0;
418 request_mouse_pos();
420 if (BUTTON_CHANGED(1))
421 button = 1;
422 else if (BUTTON_CHANGED(2))
423 button = 2;
424 else if (BUTTON_CHANGED(3))
425 button = 3;
427 if (button && (BUTTON_STATUS(button) &
428 BUTTON_MODIFIER_MASK))
430 waddstr(win, " Modifier(s):");
432 if (BUTTON_STATUS(button) & BUTTON_SHIFT)
433 waddstr(win, " SHIFT");
435 if (BUTTON_STATUS(button) & BUTTON_CONTROL)
436 waddstr(win, " CONTROL");
438 if (BUTTON_STATUS(button) & BUTTON_ALT)
439 waddstr(win, " ALT");
442 wmove(win, 4, 18);
443 wclrtoeol(win);
444 wprintw(win, "Button %d: ", button);
446 if (MOUSE_MOVED)
447 waddstr(win, "moved: ");
448 else if (MOUSE_WHEEL_UP)
449 waddstr(win, "wheel up: ");
450 else if (MOUSE_WHEEL_DOWN)
451 waddstr(win, "wheel dn: ");
452 else if ((BUTTON_STATUS(button) &
453 BUTTON_ACTION_MASK) == BUTTON_PRESSED)
454 waddstr(win, "pressed: ");
455 else if ((BUTTON_STATUS(button) &
456 BUTTON_ACTION_MASK) == BUTTON_CLICKED)
457 waddstr(win, "clicked: ");
458 else if ((BUTTON_STATUS(button) &
459 BUTTON_ACTION_MASK) == BUTTON_DOUBLE_CLICKED)
460 waddstr(win, "double: ");
461 else
462 waddstr(win, "released: ");
464 wprintw(win, "Position: Y: %d X: %d", MOUSE_Y_POS, MOUSE_X_POS);
466 else if (PDC_get_key_modifiers())
468 waddstr(win, " Modifier(s):");
469 if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_SHIFT)
470 waddstr(win, " SHIFT");
472 if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_CONTROL)
473 waddstr(win, " CONTROL");
475 if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_ALT)
476 waddstr(win, " ALT");
478 if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_NUMLOCK)
479 waddstr(win, " NUMLOCK");
481 #endif
482 wrefresh(win);
484 if (c == ' ')
485 break;
488 wtimeout(win, -1); /* turn off timeout() */
489 curs_set(1); /* turn cursor back on */
491 #ifdef PDCURSES
492 mouse_set(0L);
493 PDC_save_key_modifiers(FALSE);
494 PDC_return_key_modifiers(FALSE);
495 #endif
496 wclear(win);
497 mvwaddstr(win, 2, 1, "Press some keys for 5 seconds");
498 mvwaddstr(win, 1, 1, "Pressing ^C should do nothing");
499 wrefresh(win);
501 werase(subWin);
502 box(subWin, ACS_VLINE, ACS_HLINE);
504 for (i = 0; i < 5; i++)
506 mvwprintw(subWin, 1, 1, "Time = %d", i);
507 wrefresh(subWin);
508 napms(1000);
509 flushinp();
512 delwin(subWin);
513 werase(win);
514 flash();
515 wrefresh(win);
516 napms(500);
517 flushinp();
519 mvwaddstr(win, 2, 1, "Press a key, followed by ENTER");
520 wmove(win, 9, 10);
521 wrefresh(win);
522 echo();
524 keypad(win, TRUE);
525 raw();
526 wgetnstr(win, buffer, 3);
527 flushinp();
529 wmove(win, 9, 10);
530 wdelch(win);
531 mvwaddstr(win, 4, 1, "The character should now have been deleted");
532 Continue(win);
534 refresh();
535 wclear(win);
536 echo();
537 buffer[0] = '\0';
538 mvwaddstr(win, 3, 2, "The window should have moved");
539 mvwaddstr(win, 4, 2,
540 "This text should have appeared without you pressing a key");
541 mvwaddstr(win, 6, 2, "Enter a number then a string seperated by space");
542 mvwin(win, 2, 1);
543 wrefresh(win);
544 mvwscanw(win, 7, 6, "%d %s", &num, buffer);
545 mvwprintw(win, 8, 6, "String: %s Number: %d", buffer, num);
546 Continue(win);
548 refresh();
549 wclear(win);
550 echo();
551 mvwaddstr(win, 3, 2, "Enter a 5 character string: ");
552 wgetnstr(win, buffer, 5);
553 mvwprintw(win, 4, 2, "String: %s", buffer);
554 Continue(win);
557 void outputTest(WINDOW *win)
559 WINDOW *win1;
560 char Buffer[80];
561 chtype ch;
562 int by, bx;
564 nl();
565 wclear(win);
566 mvwaddstr(win, 1, 1, "You should now have a screen in the upper "
567 "left corner, and this text should have wrapped");
568 waddstr(win,"\nThis text should be down\n");
569 waddstr(win, "and broken into two here ^");
570 Continue(win);
572 wclear(win);
573 wattron(win, A_BOLD);
574 mvwaddstr(win, 1, 1, "A new window will appear with this text in it");
575 mvwaddstr(win, 8, 1, "Press any key to continue");
576 wrefresh(win);
577 wgetch(win);
579 getbegyx(win, by, bx);
581 if (LINES < 24 || COLS < 75)
583 mvwaddstr(win, 5, 1, "Some tests have been skipped as they require a");
584 mvwaddstr(win, 6, 1, "display of at least 24 LINES by 75 COLUMNS");
585 Continue(win);
587 else
589 win1 = newwin(10, 50, 14, 25);
591 if (win1 == NULL)
593 endwin();
594 return;
597 #ifdef A_COLOR
598 if (has_colors())
600 init_pair(3, COLOR_BLUE, COLOR_WHITE);
601 wbkgd(win1, COLOR_PAIR(3));
603 else
604 #endif
605 wbkgd(win1, A_NORMAL);
607 wclear(win1);
608 mvwaddstr(win1, 5, 1, "This text should appear; using overlay option");
609 copywin(win, win1, 0, 0, 0, 0, 9, 49, TRUE);
610 box(win1, ACS_VLINE, ACS_HLINE);
611 wmove(win1, 8, 26);
612 wrefresh(win1);
613 wgetch(win1);
615 wclear(win1);
617 wattron(win1, A_BLINK);
618 mvwaddstr(win1, 4, 1,
619 "This blinking text should appear in only the second window");
620 wattroff(win1, A_BLINK);
622 mvwin(win1, by, bx);
623 overlay(win, win1);
624 mvwin(win1, 14, 25);
625 wmove(win1, 8, 26);
626 wrefresh(win1);
627 wgetch(win1);
629 delwin(win1);
632 clear();
633 wclear(win);
634 wrefresh(win);
635 mvwaddstr(win, 6, 2, "This line shouldn't appear");
636 mvwaddstr(win, 4, 2, "Only half of the next line is visible");
637 mvwaddstr(win, 5, 2, "Only half of the next line is visible");
638 wmove(win, 6, 1);
639 wclrtobot(win);
640 wmove(win, 5, 20);
641 wclrtoeol(win);
642 mvwaddstr(win, 8, 2, "This line also shouldn't appear");
643 wmove(win, 8, 1);
644 winsdelln(win, -1);
645 Continue(win);
647 wmove(win, 5, 9);
648 ch = winch(win);
650 wclear(win);
651 wmove(win, 6, 2);
652 waddstr(win, "The next char should be l: ");
653 winsch(win, ch);
654 Continue(win);
656 mvwinsstr(win, 6, 2, "A1B2C3D4E5");
657 Continue(win);
659 wmove(win, 5, 1);
660 winsdelln(win, 1);
661 mvwaddstr(win, 5, 2, "The lines below should have moved down");
662 Continue(win);
664 wclear(win);
665 wmove(win, 2, 2);
666 wprintw(win, "This is a formatted string in a window: %d %s\n",
667 42, "is it");
668 mvwaddstr(win, 10, 1, "Enter a string: ");
669 wrefresh(win);
670 echo();
671 wscanw(win, "%s", Buffer);
673 printw("This is a formatted string in stdscr: %d %s\n", 42, "is it");
674 mvaddstr(10, 1, "Enter a string: ");
675 scanw("%s", Buffer);
677 wclear(win);
678 curs_set(2);
679 mvwaddstr(win, 1, 1, "The cursor should be in high-visibility mode");
680 Continue(win);
682 wclear(win);
683 curs_set(0);
684 mvwaddstr(win, 1, 1, "The cursor should have disappeared");
685 Continue(win);
687 wclear(win);
688 curs_set(1);
689 mvwaddstr(win, 1, 1, "The cursor should be normal");
690 Continue(win);
692 #ifdef A_COLOR
693 if (has_colors())
695 wclear(win);
696 mvwaddstr(win, 1, 1, "Colors should change after you press a key");
697 Continue(win);
699 init_pair(1, COLOR_RED, COLOR_WHITE);
700 wrefresh(win);
702 #endif
703 werase(win);
704 mvwaddstr(win, 1, 1, "Information About Your Terminal");
705 mvwaddstr(win, 3, 1, termname());
706 mvwaddstr(win, 4, 1, longname());
708 if (termattrs() & A_BLINK)
709 mvwaddstr(win, 5, 1, "This terminal claims to support blinking.");
710 else
711 mvwaddstr(win, 5, 1, "This terminal does NOT support blinking.");
713 mvwaddnstr(win, 7, 5, "Have a nice day!ok", 16);
714 wrefresh(win);
716 mvwinnstr(win, 7, 5, Buffer, 18);
717 mvaddstr(LINES - 2, 10, Buffer);
718 refresh();
719 Continue(win);
722 #if HAVE_RESIZE
723 void resizeTest(WINDOW *dummy)
725 WINDOW *win1;
726 int nwidth = 135, nheight = 52;
727 int owidth = COLS, oheight = LINES;
729 savetty();
731 resize_term(nheight, nwidth);
733 clear();
734 refresh();
736 win1 = newwin(10, 50, 14, 25);
738 if (win1 == NULL)
740 endwin();
741 return;
744 #ifdef A_COLOR
745 if (has_colors())
747 init_pair(3, COLOR_BLUE, COLOR_WHITE);
748 wattrset(win1, COLOR_PAIR(3));
751 wclear(win1);
752 #endif
753 mvwaddstr(win1, 0, 0, "The screen may now be resized");
754 mvwprintw(win1, 1, 4, "Given size: %d by %d", nwidth, nheight);
755 mvwprintw(win1, 2, 4, "Actual size: %d by %d", COLS, LINES);
756 Continue(win1);
758 wclear(win1);
759 resetty();
761 mvwaddstr(win1, 0, 0, "The screen should now be reset");
762 mvwprintw(win1, 1, 6, "Old size: %d by %d", owidth, oheight);
763 mvwprintw(win1, 2, 6, "Size now: %d by %d", COLS, LINES);
764 Continue(win1);
766 delwin(win1);
768 clear();
769 refresh();
771 #endif /* HAVE_RESIZE */
773 void padTest(WINDOW *dummy)
775 WINDOW *pad, *spad;
777 pad = newpad(50, 100);
778 wattron(pad, A_REVERSE);
779 mvwaddstr(pad, 5, 2, "This is a new pad");
780 wattrset(pad, 0);
781 mvwaddstr(pad, 8, 0,
782 "The end of this line should be truncated here:except now");
783 mvwaddstr(pad, 11, 1, "This line should not appear.It will now");
784 wmove(pad, 10, 1);
785 wclrtoeol(pad);
786 mvwaddstr(pad, 10, 1, " Press any key to continue");
787 prefresh(pad, 0, 0, 0, 0, 10, 45);
788 keypad(pad, TRUE);
789 raw();
790 wgetch(pad);
792 spad = subpad(pad, 12, 25, 7, 52);
793 mvwaddstr(spad, 2, 2, "This is a new subpad");
794 box(spad, 0, 0);
795 prefresh(pad, 0, 0, 0, 0, 15, 75);
796 keypad(pad, TRUE);
797 raw();
798 wgetch(pad);
800 mvwaddstr(pad, 35, 2, "This is displayed at line 35 in the pad");
801 mvwaddstr(pad, 40, 1, " Press any key to continue");
802 prefresh(pad, 30, 0, 0, 0, 10, 45);
803 keypad(pad, TRUE);
804 raw();
805 wgetch(pad);
807 delwin(pad);
810 #if HAVE_CLIPBOARD
811 void clipboardTest(WINDOW *win)
813 static const char *text =
814 "This string placed in clipboard by PDCurses test program, testcurs.";
815 char *ptr = NULL;
816 long i, length = 0;
818 mvaddstr(1, 1,
819 "This test will display the contents of the system clipboard");
821 Continue2();
823 scrollok(stdscr, TRUE);
824 i = PDC_getclipboard(&ptr, &length);
826 switch(i)
828 case PDC_CLIP_ACCESS_ERROR:
829 mvaddstr(3, 1, "There was an error accessing the clipboard");
830 refresh();
831 break;
833 case PDC_CLIP_MEMORY_ERROR:
834 mvaddstr(3, 1,
835 "Unable to allocate memory for clipboard contents");
836 break;
838 case PDC_CLIP_EMPTY:
839 mvaddstr(3, 1, "There was no text in the clipboard");
840 break;
842 default:
843 wsetscrreg(stdscr, 0, LINES - 1);
844 clear();
845 mvaddstr(1, 1, "Clipboard contents...");
846 mvprintw(2, 1, "%s\n", ptr);
849 Continue2();
851 clear();
852 mvaddstr(1, 1,
853 "This test will place the following string in the system clipboard:");
854 mvaddstr(2, 1, text);
856 i = PDC_setclipboard(text, strlen(text));
858 switch(i)
860 case PDC_CLIP_ACCESS_ERROR:
861 mvaddstr(3, 1, "There was an error accessing the clipboard");
862 break;
864 case PDC_CLIP_MEMORY_ERROR:
865 mvaddstr(3, 1, "Unable to allocate memory for clipboard contents");
866 break;
868 default:
869 mvaddstr(3, 1, "The string was placed in the clipboard successfully");
872 Continue2();
874 #endif /* HAVE_CLIPBOARD */
876 void acsTest(WINDOW *win)
878 #ifdef ACS_S3
879 # define ACSNUM 32
880 #else
881 # define ACSNUM 25
882 #endif
883 static const char *acs_names[] =
885 "ACS_ULCORNER", "ACS_URCORNER", "ACS_LLCORNER", "ACS_LRCORNER",
886 "ACS_LTEE", "ACS_RTEE", "ACS_TTEE", "ACS_BTEE", "ACS_HLINE",
887 "ACS_VLINE", "ACS_PLUS",
889 "ACS_S1", "ACS_S9", "ACS_DIAMOND", "ACS_CKBOARD", "ACS_DEGREE",
890 "ACS_PLMINUS", "ACS_BULLET",
892 "ACS_LARROW", "ACS_RARROW", "ACS_UARROW", "ACS_DARROW",
893 "ACS_BOARD", "ACS_LANTERN", "ACS_BLOCK"
894 #ifdef ACS_S3
895 , "ACS_S3", "ACS_S7", "ACS_LEQUAL", "ACS_GEQUAL",
896 "ACS_PI", "ACS_NEQUAL", "ACS_STERLING"
897 #endif
900 chtype acs_values[ACSNUM];
902 #if HAVE_WIDE
903 cchar_t *wacs_values[] =
905 WACS_ULCORNER, WACS_URCORNER, WACS_LLCORNER, WACS_LRCORNER,
906 WACS_LTEE, WACS_RTEE, WACS_TTEE, WACS_BTEE, WACS_HLINE,
907 WACS_VLINE, WACS_PLUS,
909 WACS_S1, WACS_S9, WACS_DIAMOND, WACS_CKBOARD, WACS_DEGREE,
910 WACS_PLMINUS, WACS_BULLET,
912 WACS_LARROW, WACS_RARROW, WACS_UARROW, WACS_DARROW, WACS_BOARD,
913 WACS_LANTERN, WACS_BLOCK
914 # ifdef WACS_S3
915 , WACS_S3, WACS_S7, WACS_LEQUAL, WACS_GEQUAL, WACS_PI,
916 WACS_NEQUAL, WACS_STERLING
917 # endif
920 static const wchar_t russian[] = {0x0420, 0x0443, 0x0441, 0x0441,
921 0x043a, 0x0438, 0x0439, L' ', 0x044f, 0x0437, 0x044b, 0x043a, 0};
923 static const wchar_t greek[] = {0x0395, 0x03bb, 0x03bb, 0x03b7,
924 0x03bd, 0x03b9, 0x03ba, 0x03ac, 0};
926 static const wchar_t georgian[] = {0x10e5, 0x10d0, 0x10e0, 0x10d7,
927 0x10e3, 0x10da, 0x10d8, L' ', 0x10d4, 0x10dc, 0x10d0, 0};
928 #endif
930 int i, tmarg = (LINES - 22) / 2;
932 attrset(A_BOLD);
933 mvaddstr(tmarg, (COLS - 23) / 2, "Alternate Character Set");
934 attrset(A_NORMAL);
936 tmarg += 3;
938 #define A(b,c) acs_values[b] = ACS_##c
940 A(0,ULCORNER); A(1,URCORNER); A(2,LLCORNER); A(3,LRCORNER);
941 A(4,LTEE); A(5,RTEE); A(6,TTEE); A(7,BTEE);
942 A(8,HLINE); A(9,VLINE); A(10,PLUS); A(11,S1);
943 A(12,S9); A(13,DIAMOND); A(14,CKBOARD); A(15,DEGREE);
945 A(16,PLMINUS); A(17,BULLET); A(18,LARROW); A(19,RARROW);
946 A(20,UARROW); A(21,DARROW); A(22,BOARD); A(23,LANTERN);
947 A(24,BLOCK);
948 #ifdef ACS_S3
949 A(25,S3); A(26,S7); A(27,LEQUAL); A(28,GEQUAL);
950 A(29,PI); A(30,NEQUAL); A(31,STERLING);
951 #endif
953 #undef A
955 for (i = 0; i < ACSNUM; i++)
957 move((i % 8) * 2 + tmarg, (i / 8) * (COLS / 4) + (COLS / 8 - 7));
958 addch(acs_values[i]);
959 printw(" %s", acs_names[i]);
962 mvaddstr(tmarg + 18, 3, "Press any key to continue");
963 getch();
965 #if HAVE_WIDE
966 clear();
968 attrset(A_BOLD);
969 mvaddstr(tmarg - 3, (COLS - 28) / 2, "Wide Alternate Character Set");
970 attrset(A_NORMAL);
972 for (i = 0; i < ACSNUM; i++)
974 move((i % 8) * 2 + tmarg, (i / 8) * (COLS / 4) + (COLS / 8 - 7));
975 add_wch(wacs_values[i]);
976 printw(" W%s", acs_names[i]);
979 /* Spanish, Russian, Greek, Georgian */
981 mvaddwstr(tmarg + 16, COLS / 8 - 5, L"Espa\xf1ol");
982 mvaddwstr(tmarg + 16, 3 * (COLS / 8) - 5, russian);
983 mvaddwstr(tmarg + 16, 5 * (COLS / 8) - 5, greek);
984 mvaddwstr(tmarg + 16, 7 * (COLS / 8) - 5, georgian);
986 mvaddstr(tmarg + 18, 3, "Press any key to continue");
987 getch();
988 #endif
991 #if HAVE_COLOR
992 void colorTest(WINDOW *win)
994 static const short colors[] =
996 COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_BLUE,
997 COLOR_CYAN, COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE
1000 static const char *colornames[] =
1002 "COLOR_BLACK", "COLOR_RED", "COLOR_GREEN", "COLOR_BLUE",
1003 "COLOR_CYAN", "COLOR_MAGENTA", "COLOR_YELLOW", "COLOR_WHITE"
1006 chtype fill = ACS_BLOCK;
1008 int i, j, tmarg, col1, col2, col3;
1010 if (!has_colors())
1011 return;
1013 tmarg = (LINES - 19) / 2;
1014 col1 = (COLS - 60) / 2;
1015 col2 = col1 + 20;
1016 col3 = col2 + 20;
1018 attrset(A_BOLD);
1019 mvaddstr(tmarg, (COLS - 22) / 2, "Color Attribute Macros");
1020 attrset(A_NORMAL);
1022 mvaddstr(tmarg + 3, col2 + 4, "A_NORMAL");
1023 mvaddstr(tmarg + 3, col3 + 5, "A_BOLD");
1025 for (i = 0; i < 8; i++)
1027 init_pair(i + 4, colors[i], COLOR_BLACK);
1029 mvaddstr(tmarg + i + 5, col1, colornames[i]);
1031 for (j = 0; j < 16; j++)
1033 mvaddch(tmarg + i + 5, col2 + j, fill | COLOR_PAIR(i + 4));
1034 mvaddch(tmarg + i + 5, col3 + j, fill | COLOR_PAIR(i + 4) | A_BOLD);
1038 mvprintw(tmarg + 15, col1, "COLORS = %d", COLORS);
1039 mvprintw(tmarg + 16, col1, "COLOR_PAIRS = %d", COLOR_PAIRS);
1041 mvaddstr(tmarg + 19, 3, "Press any key to continue");
1042 getch();
1044 if (can_change_color())
1046 struct
1048 short red, green, blue;
1049 } orgcolors[16];
1051 int MAXCOL = (COLORS >= 16) ? 16 : 8;
1053 if (MAXCOL < 8)
1054 return;
1056 for (i = 0; i < MAXCOL; i++)
1057 color_content(i, &(orgcolors[i].red),
1058 &(orgcolors[i].green),
1059 &(orgcolors[i].blue));
1061 attrset(A_BOLD);
1062 mvaddstr(tmarg, (COLS - 22) / 2, " init_color() Example ");
1063 attrset(A_NORMAL);
1065 refresh();
1067 for (i = 0; i < 8; i++)
1069 init_color(colors[i], i * 125, 0, i * 125);
1071 if (MAXCOL == 16)
1072 init_color(colors[i] + 8, 0, i * 125, 0);
1075 mvaddstr(tmarg + 19, 3, "Press any key to continue");
1076 getch();
1078 for (i = 0; i < MAXCOL; i++)
1079 init_color(i, orgcolors[i].red,
1080 orgcolors[i].green,
1081 orgcolors[i].blue);
1084 #endif
1086 #if HAVE_WIDE
1087 void wideTest(WINDOW *win)
1089 wchar_t tmp[513];
1090 size_t i;
1092 attrset(A_BOLD);
1093 mvaddstr(1, (COLS - 25) / 2, "Wide Character Input Test");
1094 attrset(A_NORMAL);
1096 mvaddstr(4, 1, "Enter a string: ");
1098 echo();
1100 get_wstr((wint_t *)tmp);
1101 addstr("\n\n String:\n\n ");
1102 addwstr(tmp);
1103 addstr("\n\n\n Hex:\n\n ");
1105 for (i = 0; i < wcslen(tmp); i++)
1107 printw("%04x ", tmp[i]);
1108 addnwstr(tmp + i, 1);
1109 addstr(" ");
1112 noecho();
1114 Continue2();
1116 #endif
1118 void display_menu(int old_option, int new_option)
1120 int lmarg = (COLS - 14) / 2,
1121 tmarg = (LINES - (MAX_OPTIONS + 2)) / 2;
1123 if (old_option == -1)
1125 int i;
1127 attrset(A_BOLD);
1128 mvaddstr(tmarg - 3, lmarg - 5, "PDCurses Test Program");
1129 attrset(A_NORMAL);
1131 for (i = 0; i < MAX_OPTIONS; i++)
1132 mvaddstr(tmarg + i, lmarg, command[i].text);
1134 else
1135 mvaddstr(tmarg + old_option, lmarg, command[old_option].text);
1137 attrset(A_REVERSE);
1138 mvaddstr(tmarg + new_option, lmarg, command[new_option].text);
1139 attrset(A_NORMAL);
1141 mvaddstr(tmarg + MAX_OPTIONS + 2, lmarg - 23,
1142 "Use Up and Down Arrows to select - Enter to run - Q to quit");
1143 refresh();