| 1 | /* | 
|---|
| 2 | * | 
|---|
| 3 | * This is a test program for the PDCurses screen package for IBM PC type | 
|---|
| 4 | * machines. | 
|---|
| 5 | * | 
|---|
| 6 | * This program was written by John Burnell (johnb@kea.am.dsir.govt.nz) | 
|---|
| 7 | *  wrs(5/28/93) -- modified to be consistent (perform identically) with either | 
|---|
| 8 | *                  PDCurses or under Unix System V, R4 | 
|---|
| 9 | * | 
|---|
| 10 | * $Id: testcurs.c,v 1.34 2005/04/16 16:19:12 tom Exp $ | 
|---|
| 11 | */ | 
|---|
| 12 |  | 
|---|
| 13 | #include <test.priv.h> | 
|---|
| 14 |  | 
|---|
| 15 | #if defined(XCURSES) | 
|---|
| 16 | char *XCursesProgramName = "testcurs"; | 
|---|
| 17 | #endif | 
|---|
| 18 |  | 
|---|
| 19 | static int initTest(WINDOW **); | 
|---|
| 20 | static void display_menu(int, int); | 
|---|
| 21 | static void inputTest(WINDOW *); | 
|---|
| 22 | static void introTest(WINDOW *); | 
|---|
| 23 | static void outputTest(WINDOW *); | 
|---|
| 24 | static void padTest(WINDOW *); | 
|---|
| 25 | static void scrollTest(WINDOW *); | 
|---|
| 26 | #if defined(PDCURSES) && !defined(XCURSES) | 
|---|
| 27 | static void resizeTest(WINDOW *); | 
|---|
| 28 | #endif | 
|---|
| 29 |  | 
|---|
| 30 | struct commands { | 
|---|
| 31 | NCURSES_CONST char *text; | 
|---|
| 32 | void (*function) (WINDOW *); | 
|---|
| 33 | }; | 
|---|
| 34 | typedef struct commands COMMAND; | 
|---|
| 35 |  | 
|---|
| 36 | static const COMMAND command[] = | 
|---|
| 37 | { | 
|---|
| 38 | {"General Test", introTest}, | 
|---|
| 39 | {"Pad Test", padTest}, | 
|---|
| 40 | #if defined(PDCURSES) && !defined(XCURSES) | 
|---|
| 41 | {"Resize Test", resizeTest}, | 
|---|
| 42 | #endif | 
|---|
| 43 | {"Scroll Test", scrollTest}, | 
|---|
| 44 | {"Input Test", inputTest}, | 
|---|
| 45 | {"Output Test", outputTest} | 
|---|
| 46 | }; | 
|---|
| 47 | #define MAX_OPTIONS SIZEOF(command) | 
|---|
| 48 |  | 
|---|
| 49 | #if !HAVE_STRDUP | 
|---|
| 50 | #define strdup my_strdup | 
|---|
| 51 | static char * | 
|---|
| 52 | strdup(char *s) | 
|---|
| 53 | { | 
|---|
| 54 | char *p = (char *) malloc(strlen(s) + 1); | 
|---|
| 55 | if (p) | 
|---|
| 56 | strcpy(p, s); | 
|---|
| 57 | return (p); | 
|---|
| 58 | } | 
|---|
| 59 | #endif /* not HAVE_STRDUP */ | 
|---|
| 60 |  | 
|---|
| 61 | static int width, height; | 
|---|
| 62 |  | 
|---|
| 63 | int | 
|---|
| 64 | main( | 
|---|
| 65 | int argc GCC_UNUSED, | 
|---|
| 66 | char *argv[]GCC_UNUSED) | 
|---|
| 67 | { | 
|---|
| 68 | WINDOW *win; | 
|---|
| 69 | int key; | 
|---|
| 70 | int old_option = (-1); | 
|---|
| 71 | int new_option = 0; | 
|---|
| 72 | bool quit = FALSE; | 
|---|
| 73 | unsigned n; | 
|---|
| 74 |  | 
|---|
| 75 | setlocale(LC_ALL, ""); | 
|---|
| 76 |  | 
|---|
| 77 | #ifdef PDCDEBUG | 
|---|
| 78 | PDC_debug("testcurs started\n"); | 
|---|
| 79 | #endif | 
|---|
| 80 | if (!initTest(&win)) | 
|---|
| 81 | ExitProgram(EXIT_FAILURE); | 
|---|
| 82 |  | 
|---|
| 83 | erase(); | 
|---|
| 84 | display_menu(old_option, new_option); | 
|---|
| 85 | for (;;) { | 
|---|
| 86 | #ifdef A_COLOR | 
|---|
| 87 | if (has_colors()) { | 
|---|
| 88 | init_pair(1, COLOR_WHITE, COLOR_BLUE); | 
|---|
| 89 | wbkgd(win, COLOR_PAIR(1)); | 
|---|
| 90 | } else | 
|---|
| 91 | wbkgd(win, A_REVERSE); | 
|---|
| 92 | #else | 
|---|
| 93 | wbkgd(win, A_REVERSE); | 
|---|
| 94 | #endif | 
|---|
| 95 | werase(win); | 
|---|
| 96 |  | 
|---|
| 97 | noecho(); | 
|---|
| 98 | keypad(stdscr, TRUE); | 
|---|
| 99 | raw(); | 
|---|
| 100 | key = getch(); | 
|---|
| 101 | if (key < KEY_MIN && key > 0 && isalpha(key)) { | 
|---|
| 102 | if (islower(key)) | 
|---|
| 103 | key = toupper(key); | 
|---|
| 104 | for (n = 0; n < MAX_OPTIONS; ++n) { | 
|---|
| 105 | if (key == command[n].text[0]) { | 
|---|
| 106 | display_menu(old_option, new_option = n); | 
|---|
| 107 | key = ' '; | 
|---|
| 108 | break; | 
|---|
| 109 | } | 
|---|
| 110 | } | 
|---|
| 111 | } | 
|---|
| 112 | switch (key) { | 
|---|
| 113 | case 10: | 
|---|
| 114 | case 13: | 
|---|
| 115 | case KEY_ENTER: | 
|---|
| 116 | erase(); | 
|---|
| 117 | refresh(); | 
|---|
| 118 | (*command[new_option].function) (win); | 
|---|
| 119 | erase(); | 
|---|
| 120 | display_menu(old_option, new_option); | 
|---|
| 121 | break; | 
|---|
| 122 | case KEY_UP: | 
|---|
| 123 | new_option = (new_option == 0) ? new_option : new_option - 1; | 
|---|
| 124 | display_menu(old_option, new_option); | 
|---|
| 125 | break; | 
|---|
| 126 | case KEY_DOWN: | 
|---|
| 127 | new_option = (new_option == MAX_OPTIONS - 1) ? new_option : | 
|---|
| 128 | new_option + 1; | 
|---|
| 129 | display_menu(old_option, new_option); | 
|---|
| 130 | break; | 
|---|
| 131 | case 'Q': | 
|---|
| 132 | case 'q': | 
|---|
| 133 | quit = TRUE; | 
|---|
| 134 | break; | 
|---|
| 135 | default: | 
|---|
| 136 | beep(); | 
|---|
| 137 | break; | 
|---|
| 138 | case ' ': | 
|---|
| 139 | break; | 
|---|
| 140 | } | 
|---|
| 141 | if (quit == TRUE) | 
|---|
| 142 | break; | 
|---|
| 143 | } | 
|---|
| 144 |  | 
|---|
| 145 | delwin(win); | 
|---|
| 146 |  | 
|---|
| 147 | endwin(); | 
|---|
| 148 | #ifdef XCURSES | 
|---|
| 149 | XCursesExit(); | 
|---|
| 150 | #endif | 
|---|
| 151 | ExitProgram(EXIT_SUCCESS); | 
|---|
| 152 | } | 
|---|
| 153 |  | 
|---|
| 154 | static void | 
|---|
| 155 | Continue(WINDOW *win) | 
|---|
| 156 | { | 
|---|
| 157 | int y1 = getmaxy(win); | 
|---|
| 158 | int x1 = getmaxx(win); | 
|---|
| 159 | int y0 = y1 < 10 ? y1 : 10; | 
|---|
| 160 | int x0 = 1; | 
|---|
| 161 | chtype save; | 
|---|
| 162 |  | 
|---|
| 163 | save = mvwinch(win, y0, x1 - 1); | 
|---|
| 164 |  | 
|---|
| 165 | mvwaddstr(win, y0, x0, " Press any key to continue"); | 
|---|
| 166 | wclrtoeol(win); | 
|---|
| 167 | getyx(win, y0, x0); | 
|---|
| 168 |  | 
|---|
| 169 | mvwaddch(win, y0, x1 - 1, save); | 
|---|
| 170 |  | 
|---|
| 171 | wmove(win, y0, x0); | 
|---|
| 172 | raw(); | 
|---|
| 173 | wgetch(win); | 
|---|
| 174 | } | 
|---|
| 175 |  | 
|---|
| 176 | static int | 
|---|
| 177 | initTest(WINDOW **win) | 
|---|
| 178 | { | 
|---|
| 179 | #ifdef PDCDEBUG | 
|---|
| 180 | PDC_debug("initTest called\n"); | 
|---|
| 181 | #endif | 
|---|
| 182 | #ifdef TRACE | 
|---|
| 183 | trace(TRACE_MAXIMUM); | 
|---|
| 184 | #endif | 
|---|
| 185 | initscr(); | 
|---|
| 186 | #ifdef PDCDEBUG | 
|---|
| 187 | PDC_debug("after initscr()\n"); | 
|---|
| 188 | #endif | 
|---|
| 189 | #ifdef A_COLOR | 
|---|
| 190 | if (has_colors()) | 
|---|
| 191 | start_color(); | 
|---|
| 192 | #endif | 
|---|
| 193 | width = 60; | 
|---|
| 194 | height = 13;                /* Create a drawing window */ | 
|---|
| 195 | *win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2); | 
|---|
| 196 | if (*win == NULL) { | 
|---|
| 197 | endwin(); | 
|---|
| 198 | return 0; | 
|---|
| 199 | } | 
|---|
| 200 | return 1; | 
|---|
| 201 | } | 
|---|
| 202 |  | 
|---|
| 203 | static void | 
|---|
| 204 | introTest(WINDOW *win) | 
|---|
| 205 | { | 
|---|
| 206 | wmove(win, height / 2 - 5, width / 2); | 
|---|
| 207 | wvline(win, ACS_VLINE, 10); | 
|---|
| 208 | wmove(win, height / 2, width / 2 - 10); | 
|---|
| 209 | whline(win, ACS_HLINE, 20); | 
|---|
| 210 | Continue(win); | 
|---|
| 211 |  | 
|---|
| 212 | beep(); | 
|---|
| 213 | werase(win); | 
|---|
| 214 |  | 
|---|
| 215 | box(win, ACS_VLINE, ACS_HLINE); | 
|---|
| 216 | wrefresh(win); | 
|---|
| 217 | cbreak(); | 
|---|
| 218 | mvwaddstr(win, 1, 1, | 
|---|
| 219 | "You should have rectangle in the middle of the screen"); | 
|---|
| 220 | mvwaddstr(win, 2, 1, "You should have heard a beep"); | 
|---|
| 221 | Continue(win); | 
|---|
| 222 | return; | 
|---|
| 223 | } | 
|---|
| 224 |  | 
|---|
| 225 | static void | 
|---|
| 226 | scrollTest(WINDOW *win) | 
|---|
| 227 | { | 
|---|
| 228 | int i; | 
|---|
| 229 | int half; | 
|---|
| 230 | int OldY; | 
|---|
| 231 | NCURSES_CONST char *Message = "The window will now scroll slowly"; | 
|---|
| 232 |  | 
|---|
| 233 | wclear(win); | 
|---|
| 234 | OldY = getmaxy(win); | 
|---|
| 235 | half = OldY / 2; | 
|---|
| 236 | mvwprintw(win, OldY - 2, 1, Message); | 
|---|
| 237 | wrefresh(win); | 
|---|
| 238 | scrollok(win, TRUE); | 
|---|
| 239 | for (i = 1; i <= OldY; i++) { | 
|---|
| 240 | napms(600); | 
|---|
| 241 | scroll(win); | 
|---|
| 242 | wrefresh(win); | 
|---|
| 243 | } | 
|---|
| 244 |  | 
|---|
| 245 | werase(win); | 
|---|
| 246 | for (i = 1; i < OldY; i++) { | 
|---|
| 247 | mvwprintw(win, i, 1, "Line %d", i); | 
|---|
| 248 | } | 
|---|
| 249 | mvwprintw(win, OldY - 2, 1, "The top of the window will scroll"); | 
|---|
| 250 | wmove(win, 1, 1); | 
|---|
| 251 | wsetscrreg(win, 0, half - 1); | 
|---|
| 252 | box(win, ACS_VLINE, ACS_HLINE); | 
|---|
| 253 | wrefresh(win); | 
|---|
| 254 | for (i = 1; i <= half; i++) { | 
|---|
| 255 | napms(600); | 
|---|
| 256 | scroll(win); | 
|---|
| 257 | box(win, ACS_VLINE, ACS_HLINE); | 
|---|
| 258 | wrefresh(win); | 
|---|
| 259 | } | 
|---|
| 260 |  | 
|---|
| 261 | werase(win); | 
|---|
| 262 | for (i = 1; i < OldY; i++) { | 
|---|
| 263 | mvwprintw(win, i, 1, "Line %d", i); | 
|---|
| 264 | } | 
|---|
| 265 | mvwprintw(win, 1, 1, "The bottom of the window will scroll"); | 
|---|
| 266 | wmove(win, OldY - 2, 1); | 
|---|
| 267 | wsetscrreg(win, half, --OldY); | 
|---|
| 268 | box(win, ACS_VLINE, ACS_HLINE); | 
|---|
| 269 | wrefresh(win); | 
|---|
| 270 | for (i = half; i <= OldY; i++) { | 
|---|
| 271 | napms(600); | 
|---|
| 272 | wscrl(win, -1); | 
|---|
| 273 | box(win, ACS_VLINE, ACS_HLINE); | 
|---|
| 274 | wrefresh(win); | 
|---|
| 275 | } | 
|---|
| 276 | wsetscrreg(win, 0, OldY); | 
|---|
| 277 | } | 
|---|
| 278 |  | 
|---|
| 279 | static void | 
|---|
| 280 | inputTest(WINDOW *win) | 
|---|
| 281 | { | 
|---|
| 282 | int answered; | 
|---|
| 283 | int repeat; | 
|---|
| 284 | int w, h, bx, by, sw, sh, i, c, num; | 
|---|
| 285 | char buffer[80]; | 
|---|
| 286 | WINDOW *subWin; | 
|---|
| 287 | wclear(win); | 
|---|
| 288 |  | 
|---|
| 289 | getmaxyx(win, h, w); | 
|---|
| 290 | getbegyx(win, by, bx); | 
|---|
| 291 | sw = w / 3; | 
|---|
| 292 | sh = h / 3; | 
|---|
| 293 | if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == NULL) | 
|---|
| 294 | return; | 
|---|
| 295 |  | 
|---|
| 296 | #ifdef A_COLOR | 
|---|
| 297 | if (has_colors()) { | 
|---|
| 298 | init_pair(2, COLOR_WHITE, COLOR_RED); | 
|---|
| 299 | wbkgd(subWin, COLOR_PAIR(2) | A_BOLD); | 
|---|
| 300 | } else | 
|---|
| 301 | wbkgd(subWin, A_BOLD); | 
|---|
| 302 | #else | 
|---|
| 303 | wbkgd(subWin, A_BOLD); | 
|---|
| 304 | #endif | 
|---|
| 305 | box(subWin, ACS_VLINE, ACS_HLINE); | 
|---|
| 306 | wrefresh(win); | 
|---|
| 307 |  | 
|---|
| 308 | nocbreak(); | 
|---|
| 309 | mvwaddstr(win, 2, 1, "Press some keys for 5 seconds"); | 
|---|
| 310 | mvwaddstr(win, 1, 1, "Pressing ^C should do nothing"); | 
|---|
| 311 | wrefresh(win); | 
|---|
| 312 |  | 
|---|
| 313 | werase(subWin); | 
|---|
| 314 | box(subWin, ACS_VLINE, ACS_HLINE); | 
|---|
| 315 | for (i = 0; i < 5; i++) { | 
|---|
| 316 | mvwprintw(subWin, 1, 1, "Time = %d", i); | 
|---|
| 317 | wrefresh(subWin); | 
|---|
| 318 | napms(1000); | 
|---|
| 319 | flushinp(); | 
|---|
| 320 | } | 
|---|
| 321 |  | 
|---|
| 322 | delwin(subWin); | 
|---|
| 323 | werase(win); | 
|---|
| 324 | flash(); | 
|---|
| 325 | wrefresh(win); | 
|---|
| 326 | napms(500); | 
|---|
| 327 |  | 
|---|
| 328 | mvwaddstr(win, 2, 1, "Press a key, followed by ENTER"); | 
|---|
| 329 | wmove(win, 9, 10); | 
|---|
| 330 | wrefresh(win); | 
|---|
| 331 | echo(); | 
|---|
| 332 | noraw(); | 
|---|
| 333 | wgetch(win); | 
|---|
| 334 | flushinp(); | 
|---|
| 335 |  | 
|---|
| 336 | wmove(win, 9, 10); | 
|---|
| 337 | wdelch(win); | 
|---|
| 338 | mvwaddstr(win, 4, 1, "The character should now have been deleted"); | 
|---|
| 339 | Continue(win); | 
|---|
| 340 |  | 
|---|
| 341 | wclear(win); | 
|---|
| 342 | mvwaddstr(win, 1, 1, "Press keys (or mouse buttons) to show their names"); | 
|---|
| 343 | mvwaddstr(win, 2, 1, "Press spacebar to finish"); | 
|---|
| 344 | wrefresh(win); | 
|---|
| 345 | keypad(win, TRUE); | 
|---|
| 346 | raw(); | 
|---|
| 347 | noecho(); | 
|---|
| 348 | typeahead(-1); | 
|---|
| 349 | #if defined(PDCURSES) | 
|---|
| 350 | mouse_set(ALL_MOUSE_EVENTS); | 
|---|
| 351 | #endif | 
|---|
| 352 | for (;;) { | 
|---|
| 353 | wmove(win, 3, 5); | 
|---|
| 354 | c = wgetch(win); | 
|---|
| 355 | wclrtobot(win); | 
|---|
| 356 | if (c >= KEY_MIN) | 
|---|
| 357 | wprintw(win, "Key Pressed: %s", keyname(c)); | 
|---|
| 358 | else if (isprint(c)) | 
|---|
| 359 | wprintw(win, "Key Pressed: %c", c); | 
|---|
| 360 | else | 
|---|
| 361 | wprintw(win, "Key Pressed: %s", unctrl(UChar(c))); | 
|---|
| 362 | #if defined(PDCURSES) | 
|---|
| 363 | if (c == KEY_MOUSE) { | 
|---|
| 364 | int button = 0; | 
|---|
| 365 | request_mouse_pos(); | 
|---|
| 366 | if (BUTTON_CHANGED(1)) | 
|---|
| 367 | button = 1; | 
|---|
| 368 | else if (BUTTON_CHANGED(2)) | 
|---|
| 369 | button = 2; | 
|---|
| 370 | else if (BUTTON_CHANGED(3)) | 
|---|
| 371 | button = 3; | 
|---|
| 372 | else | 
|---|
| 373 | button = 0; | 
|---|
| 374 | wmove(win, 4, 18); | 
|---|
| 375 | wprintw(win, "Button %d: ", button); | 
|---|
| 376 | if (MOUSE_MOVED) | 
|---|
| 377 | wprintw(win, "moved: "); | 
|---|
| 378 | else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_PRESSED) | 
|---|
| 379 | wprintw(win, "pressed: "); | 
|---|
| 380 | else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_DOUBLE_CLICKED) | 
|---|
| 381 | wprintw(win, "double: "); | 
|---|
| 382 | else | 
|---|
| 383 | wprintw(win, "released: "); | 
|---|
| 384 | wprintw(win, " Position: Y: %d X: %d", MOUSE_Y_POS, MOUSE_X_POS); | 
|---|
| 385 | } | 
|---|
| 386 | #endif | 
|---|
| 387 | wrefresh(win); | 
|---|
| 388 | if (c == ' ') | 
|---|
| 389 | break; | 
|---|
| 390 | } | 
|---|
| 391 | #if 0 | 
|---|
| 392 | nodelay(win, TRUE); | 
|---|
| 393 | wgetch(win); | 
|---|
| 394 | nodelay(win, FALSE); | 
|---|
| 395 | #endif | 
|---|
| 396 | #if defined(PDCURSES) | 
|---|
| 397 | mouse_set(0L); | 
|---|
| 398 | #endif | 
|---|
| 399 | refresh(); | 
|---|
| 400 |  | 
|---|
| 401 | repeat = 0; | 
|---|
| 402 | do { | 
|---|
| 403 | static const char *fmt[] = | 
|---|
| 404 | { | 
|---|
| 405 | "%d %10s", | 
|---|
| 406 | "%d %[a-zA-Z]s", | 
|---|
| 407 | "%d %[][a-zA-Z]s", | 
|---|
| 408 | "%d %[^0-9]" | 
|---|
| 409 | }; | 
|---|
| 410 | const char *format = fmt[repeat % SIZEOF(fmt)]; | 
|---|
| 411 |  | 
|---|
| 412 | wclear(win); | 
|---|
| 413 | mvwaddstr(win, 3, 2, "The window should have moved"); | 
|---|
| 414 | mvwaddstr(win, 4, 2, | 
|---|
| 415 | "This text should have appeared without you pressing a key"); | 
|---|
| 416 | mvwprintw(win, 6, 2, | 
|---|
| 417 | "Scanning with format \"%s\"", format); | 
|---|
| 418 | mvwin(win, 2 + 2 * (repeat % 4), 1 + 2 * (repeat % 4)); | 
|---|
| 419 | erase(); | 
|---|
| 420 | refresh(); | 
|---|
| 421 | wrefresh(win); | 
|---|
| 422 | echo(); | 
|---|
| 423 | noraw(); | 
|---|
| 424 | num = 0; | 
|---|
| 425 | *buffer = 0; | 
|---|
| 426 | answered = mvwscanw(win, 7, 6, strdup(format), &num, buffer); | 
|---|
| 427 | mvwprintw(win, 8, 6, | 
|---|
| 428 | "String: %s Number: %d (%d values read)", | 
|---|
| 429 | buffer, num, answered); | 
|---|
| 430 | Continue(win); | 
|---|
| 431 | ++repeat; | 
|---|
| 432 | } while (answered > 0); | 
|---|
| 433 | } | 
|---|
| 434 |  | 
|---|
| 435 | static void | 
|---|
| 436 | outputTest(WINDOW *win) | 
|---|
| 437 | { | 
|---|
| 438 | WINDOW *win1; | 
|---|
| 439 | char Buffer[80]; | 
|---|
| 440 | chtype ch; | 
|---|
| 441 | int by, bx; | 
|---|
| 442 |  | 
|---|
| 443 | nl(); | 
|---|
| 444 | wclear(win); | 
|---|
| 445 | mvwaddstr(win, 1, 1, | 
|---|
| 446 | "You should now have a screen in the upper left corner, and this text should have wrapped"); | 
|---|
| 447 | mvwin(win, 2, 1); | 
|---|
| 448 | waddstr(win, "\nThis text should be down\n"); | 
|---|
| 449 | waddstr(win, "and broken into two here ^"); | 
|---|
| 450 | Continue(win); | 
|---|
| 451 |  | 
|---|
| 452 | wclear(win); | 
|---|
| 453 | wattron(win, A_BOLD); | 
|---|
| 454 | mvwaddstr(win, 1, 1, "A new window will appear with this text in it"); | 
|---|
| 455 | mvwaddstr(win, 8, 1, "Press any key to continue"); | 
|---|
| 456 | wrefresh(win); | 
|---|
| 457 | wgetch(win); | 
|---|
| 458 |  | 
|---|
| 459 | getbegyx(win, by, bx); | 
|---|
| 460 |  | 
|---|
| 461 | if (LINES < 24 || COLS < 75) { | 
|---|
| 462 | mvwaddstr(win, 5, 1, | 
|---|
| 463 | "Some tests have been skipped as they require a"); | 
|---|
| 464 | mvwaddstr(win, 6, 1, "display of at least 24 LINES by 75 COLUMNS"); | 
|---|
| 465 | Continue(win); | 
|---|
| 466 | } else { | 
|---|
| 467 | win1 = newwin(10, 50, 14, 25); | 
|---|
| 468 | if (win1 == NULL) { | 
|---|
| 469 | endwin(); | 
|---|
| 470 | return; | 
|---|
| 471 | } | 
|---|
| 472 | #ifdef A_COLOR | 
|---|
| 473 | if (has_colors()) { | 
|---|
| 474 | init_pair(3, COLOR_BLUE, COLOR_WHITE); | 
|---|
| 475 | wbkgd(win1, COLOR_PAIR(3)); | 
|---|
| 476 | } else | 
|---|
| 477 | wbkgd(win1, A_NORMAL); | 
|---|
| 478 | #else | 
|---|
| 479 | wbkgd(win1, A_NORMAL); | 
|---|
| 480 | #endif | 
|---|
| 481 | wclear(win1); | 
|---|
| 482 | mvwaddstr(win1, 5, 1, | 
|---|
| 483 | "This text should appear; using overlay option"); | 
|---|
| 484 | copywin(win, win1, 0, 0, 0, 0, 9, 49, TRUE); | 
|---|
| 485 |  | 
|---|
| 486 | #if defined(PDCURSES) && !defined(XCURSES) | 
|---|
| 487 | box(win1, 0xb3, 0xc4); | 
|---|
| 488 | #else | 
|---|
| 489 | box(win1, ACS_VLINE, ACS_HLINE); | 
|---|
| 490 | #endif | 
|---|
| 491 | wmove(win1, 8, 26); | 
|---|
| 492 | wrefresh(win1); | 
|---|
| 493 | wgetch(win1); | 
|---|
| 494 |  | 
|---|
| 495 | wclear(win1); | 
|---|
| 496 | wattron(win1, A_BLINK); | 
|---|
| 497 | mvwaddstr(win1, 4, 1, | 
|---|
| 498 | "This blinking text should appear in only the second window"); | 
|---|
| 499 | wattroff(win1, A_BLINK); | 
|---|
| 500 | mvwin(win1, by, bx); | 
|---|
| 501 | overlay(win, win1); | 
|---|
| 502 | mvwin(win1, 14, 25); | 
|---|
| 503 | wmove(win1, 8, 26); | 
|---|
| 504 | wrefresh(win1); | 
|---|
| 505 | wgetch(win1); | 
|---|
| 506 | delwin(win1); | 
|---|
| 507 | } | 
|---|
| 508 |  | 
|---|
| 509 | clear(); | 
|---|
| 510 | wclear(win); | 
|---|
| 511 | wrefresh(win); | 
|---|
| 512 | mvwaddstr(win, 6, 2, "This line shouldn't appear"); | 
|---|
| 513 | mvwaddstr(win, 4, 2, "Only half of the next line is visible"); | 
|---|
| 514 | mvwaddstr(win, 5, 2, "Only half of the next line is visible"); | 
|---|
| 515 | wmove(win, 6, 1); | 
|---|
| 516 | wclrtobot(win); | 
|---|
| 517 | wmove(win, 5, 20); | 
|---|
| 518 | wclrtoeol(win); | 
|---|
| 519 | mvwaddstr(win, 8, 2, "This line also shouldn't appear"); | 
|---|
| 520 | wmove(win, 8, 1); | 
|---|
| 521 | wdeleteln(win); | 
|---|
| 522 | Continue(win); | 
|---|
| 523 |  | 
|---|
| 524 | wmove(win, 5, 9); | 
|---|
| 525 | ch = winch(win); | 
|---|
| 526 |  | 
|---|
| 527 | wclear(win); | 
|---|
| 528 | wmove(win, 6, 2); | 
|---|
| 529 | waddstr(win, "The next char should be l:  "); | 
|---|
| 530 | winsch(win, ch); | 
|---|
| 531 | Continue(win); | 
|---|
| 532 |  | 
|---|
| 533 | mvwinsstr(win, 6, 2, "A1B2C3D4E5"); | 
|---|
| 534 | Continue(win); | 
|---|
| 535 |  | 
|---|
| 536 | wmove(win, 5, 1); | 
|---|
| 537 | winsertln(win); | 
|---|
| 538 | mvwaddstr(win, 5, 2, "The lines below should have moved down"); | 
|---|
| 539 | Continue(win); | 
|---|
| 540 |  | 
|---|
| 541 | wclear(win); | 
|---|
| 542 | wmove(win, 2, 2); | 
|---|
| 543 | wprintw(win, "This is a formatted string in a window: %d %s\n", 42, | 
|---|
| 544 | "is it"); | 
|---|
| 545 | mvwaddstr(win, 10, 1, "Enter a string: "); | 
|---|
| 546 | wrefresh(win); | 
|---|
| 547 | noraw(); | 
|---|
| 548 | echo(); | 
|---|
| 549 | *Buffer = 0; | 
|---|
| 550 | wscanw(win, "%s", Buffer); | 
|---|
| 551 |  | 
|---|
| 552 | printw("This is a formatted string in stdscr: %d %s\n", 42, "is it"); | 
|---|
| 553 | mvaddstr(10, 1, "Enter a string: "); | 
|---|
| 554 | *Buffer = 0; | 
|---|
| 555 | scanw("%s", Buffer); | 
|---|
| 556 |  | 
|---|
| 557 | if (tigetstr("cvvis") != 0) { | 
|---|
| 558 | wclear(win); | 
|---|
| 559 | curs_set(2); | 
|---|
| 560 | mvwaddstr(win, 1, 1, "The cursor should appear as a block (visible)"); | 
|---|
| 561 | Continue(win); | 
|---|
| 562 | } | 
|---|
| 563 |  | 
|---|
| 564 | if (tigetstr("civis") != 0) { | 
|---|
| 565 | wclear(win); | 
|---|
| 566 | curs_set(0); | 
|---|
| 567 | mvwaddstr(win, 1, 1, | 
|---|
| 568 | "The cursor should have disappeared (invisible)"); | 
|---|
| 569 | Continue(win); | 
|---|
| 570 | } | 
|---|
| 571 |  | 
|---|
| 572 | if (tigetstr("cnorm") != 0) { | 
|---|
| 573 | wclear(win); | 
|---|
| 574 | curs_set(1); | 
|---|
| 575 | mvwaddstr(win, 1, 1, "The cursor should be an underline (normal)"); | 
|---|
| 576 | Continue(win); | 
|---|
| 577 | } | 
|---|
| 578 | #ifdef A_COLOR | 
|---|
| 579 | if (has_colors()) { | 
|---|
| 580 | wclear(win); | 
|---|
| 581 | mvwaddstr(win, 1, 1, "Colors should change after you press a key"); | 
|---|
| 582 | Continue(win); | 
|---|
| 583 | init_pair(1, COLOR_RED, COLOR_WHITE); | 
|---|
| 584 | wrefresh(win); | 
|---|
| 585 | } | 
|---|
| 586 | #endif | 
|---|
| 587 |  | 
|---|
| 588 | werase(win); | 
|---|
| 589 | mvwaddstr(win, 1, 1, "Information About Your Terminal"); | 
|---|
| 590 | mvwaddstr(win, 3, 1, termname()); | 
|---|
| 591 | mvwaddstr(win, 4, 1, longname()); | 
|---|
| 592 | if (termattrs() & A_BLINK) | 
|---|
| 593 | mvwaddstr(win, 5, 1, "This terminal supports blinking."); | 
|---|
| 594 | else | 
|---|
| 595 | mvwaddstr(win, 5, 1, "This terminal does NOT support blinking."); | 
|---|
| 596 |  | 
|---|
| 597 | mvwaddnstr(win, 7, 5, "Have a nice day!ok", 16); | 
|---|
| 598 | wrefresh(win); | 
|---|
| 599 |  | 
|---|
| 600 | mvwinnstr(win, 7, 5, Buffer, 18); | 
|---|
| 601 | mvaddstr(LINES - 2, 10, Buffer); | 
|---|
| 602 | refresh(); | 
|---|
| 603 | Continue(win); | 
|---|
| 604 | } | 
|---|
| 605 |  | 
|---|
| 606 | #if defined(PDCURSES) && !defined(XCURSES) | 
|---|
| 607 | static void | 
|---|
| 608 | resizeTest(WINDOW *dummy GCC_UNUSED) | 
|---|
| 609 | { | 
|---|
| 610 | WINDOW *win1; | 
|---|
| 611 |  | 
|---|
| 612 | savetty(); | 
|---|
| 613 |  | 
|---|
| 614 | clear(); | 
|---|
| 615 | refresh(); | 
|---|
| 616 | #  if defined(OS2) | 
|---|
| 617 | resize_term(50, 120); | 
|---|
| 618 | #  else | 
|---|
| 619 | resize_term(50, 80); | 
|---|
| 620 | #  endif | 
|---|
| 621 |  | 
|---|
| 622 | win1 = newwin(10, 50, 14, 25); | 
|---|
| 623 | if (win1 == NULL) { | 
|---|
| 624 | endwin(); | 
|---|
| 625 | return; | 
|---|
| 626 | } | 
|---|
| 627 | #ifdef A_COLOR | 
|---|
| 628 | if (has_colors()) { | 
|---|
| 629 | init_pair(3, COLOR_BLUE, COLOR_WHITE); | 
|---|
| 630 | wattrset(win1, COLOR_PAIR(3)); | 
|---|
| 631 | } | 
|---|
| 632 | #endif | 
|---|
| 633 | wclear(win1); | 
|---|
| 634 |  | 
|---|
| 635 | mvwaddstr(win1, 1, 1, "The screen may now have 50 lines"); | 
|---|
| 636 | Continue(win1); | 
|---|
| 637 |  | 
|---|
| 638 | wclear(win1); | 
|---|
| 639 | resetty(); | 
|---|
| 640 |  | 
|---|
| 641 | mvwaddstr(win1, 1, 1, "The screen should now be reset"); | 
|---|
| 642 | Continue(win1); | 
|---|
| 643 |  | 
|---|
| 644 | delwin(win1); | 
|---|
| 645 |  | 
|---|
| 646 | clear(); | 
|---|
| 647 | refresh(); | 
|---|
| 648 |  | 
|---|
| 649 | } | 
|---|
| 650 | #endif | 
|---|
| 651 |  | 
|---|
| 652 | static void | 
|---|
| 653 | padTest(WINDOW *dummy GCC_UNUSED) | 
|---|
| 654 | { | 
|---|
| 655 | WINDOW *pad, *spad; | 
|---|
| 656 |  | 
|---|
| 657 | pad = newpad(50, 100); | 
|---|
| 658 | wattron(pad, A_REVERSE); | 
|---|
| 659 | mvwaddstr(pad, 5, 2, "This is a new pad"); | 
|---|
| 660 | wattrset(pad, A_NORMAL); | 
|---|
| 661 | mvwaddstr(pad, 8, 0, | 
|---|
| 662 | "The end of this line should be truncated here:except  now"); | 
|---|
| 663 | mvwaddstr(pad, 11, 1, "This line should not appear.It will now"); | 
|---|
| 664 | wmove(pad, 10, 1); | 
|---|
| 665 | wclrtoeol(pad); | 
|---|
| 666 | mvwaddstr(pad, 10, 1, " Press any key to continue"); | 
|---|
| 667 | prefresh(pad, 0, 0, 0, 0, 10, 45); | 
|---|
| 668 | keypad(pad, TRUE); | 
|---|
| 669 | raw(); | 
|---|
| 670 | wgetch(pad); | 
|---|
| 671 |  | 
|---|
| 672 | spad = subpad(pad, 12, 25, 6, 52); | 
|---|
| 673 | mvwaddstr(spad, 2, 2, "This is a new subpad"); | 
|---|
| 674 | box(spad, 0, 0); | 
|---|
| 675 | prefresh(pad, 0, 0, 0, 0, 15, 75); | 
|---|
| 676 | keypad(pad, TRUE); | 
|---|
| 677 | raw(); | 
|---|
| 678 | wgetch(pad); | 
|---|
| 679 |  | 
|---|
| 680 | mvwaddstr(pad, 35, 2, "This is displayed at line 35 in the pad"); | 
|---|
| 681 | mvwaddstr(pad, 40, 1, " Press any key to continue"); | 
|---|
| 682 | prefresh(pad, 30, 0, 0, 0, 10, 45); | 
|---|
| 683 | keypad(pad, TRUE); | 
|---|
| 684 | raw(); | 
|---|
| 685 | wgetch(pad); | 
|---|
| 686 |  | 
|---|
| 687 | delwin(pad); | 
|---|
| 688 | } | 
|---|
| 689 |  | 
|---|
| 690 | static void | 
|---|
| 691 | display_menu(int old_option, int new_option) | 
|---|
| 692 | { | 
|---|
| 693 | int i; | 
|---|
| 694 |  | 
|---|
| 695 | attrset(A_NORMAL); | 
|---|
| 696 | mvaddstr(3, 20, "PDCurses Test Program"); | 
|---|
| 697 |  | 
|---|
| 698 | for (i = 0; i < (int) MAX_OPTIONS; i++) | 
|---|
| 699 | mvaddstr(5 + i, 25, command[i].text); | 
|---|
| 700 | if (old_option != (-1)) | 
|---|
| 701 | mvaddstr(5 + old_option, 25, command[old_option].text); | 
|---|
| 702 | attrset(A_REVERSE); | 
|---|
| 703 | mvaddstr(5 + new_option, 25, command[new_option].text); | 
|---|
| 704 | attrset(A_NORMAL); | 
|---|
| 705 | mvaddstr(13, 3, | 
|---|
| 706 | "Use Up and Down Arrows to select - Enter to run - Q to quit"); | 
|---|
| 707 | refresh(); | 
|---|
| 708 | } | 
|---|