OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [services/] [curses/] [pdcurses/] [current/] [tests/] [testcurs.c] - Blame information for rev 819

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
/*
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
 *  $Id: testcurs.c,v 1.1 2009/05/10 08:29:53 jld Exp $
9
 */
10
 
11
#ifndef _XOPEN_SOURCE_EXTENDED
12
# define _XOPEN_SOURCE_EXTENDED 1
13
#endif
14
 
15
#include <stdio.h>
16
#include <ctype.h>
17
#include <string.h>
18
#include <curses.h>
19
 
20
#ifdef WACS_S1
21
# define HAVE_WIDE 1
22
#else
23
# define HAVE_WIDE 0
24
#endif
25
 
26
#include <locale.h>
27
 
28
#if HAVE_WIDE
29
# include <wchar.h>
30
#endif
31
 
32
#if defined(PDCURSES) && !defined(XCURSES)
33
# define HAVE_RESIZE 1
34
#else
35
# define HAVE_RESIZE 0
36
#endif
37
 
38
#ifdef A_COLOR
39
# define HAVE_COLOR 1
40
#else
41
# define HAVE_COLOR 0
42
#endif
43
 
44
/* Set to non-zero if you want to test the PDCurses clipboard */
45
 
46
#define HAVE_CLIPBOARD 0
47
 
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 *);
55
 
56
#if HAVE_COLOR
57
void colorTest(WINDOW *);
58
#endif
59
 
60
#if HAVE_RESIZE
61
void resizeTest(WINDOW *);
62
#endif
63
 
64
#if HAVE_CLIPBOARD
65
void clipboardTest(WINDOW *);
66
#endif
67
 
68
#if HAVE_WIDE
69
void wideTest(WINDOW *);
70
#endif
71
 
72
void display_menu(int, int);
73
 
74
struct commands
75
{
76
    const char *text;
77
    void (*function)(WINDOW *);
78
};
79
 
80
typedef struct commands COMMAND;
81
 
82
#define MAX_OPTIONS (6 + HAVE_COLOR + HAVE_RESIZE + HAVE_CLIPBOARD + HAVE_WIDE)
83
 
84
COMMAND command[MAX_OPTIONS] =
85
{
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
104
};
105
 
106
int width, height;
107
 
108
int main(int argc, char *argv[])
109
{
110
    WINDOW *win;
111
    int key, old_option = -1, new_option = 0;
112
    bool quit = FALSE;
113
 
114
    setlocale(LC_ALL, "");
115
 
116
    if (initTest(&win, argc, argv))
117
        return 1;
118
 
119
#ifdef A_COLOR
120
    if (has_colors())
121
    {
122
        init_pair(1, COLOR_WHITE, COLOR_BLUE);
123
        wbkgd(win, COLOR_PAIR(1));
124
    }
125
    else
126
#endif
127
        wbkgd(win, A_REVERSE);
128
 
129
    erase();
130
    display_menu(old_option, new_option);
131
 
132
    while (1)
133
    {
134
        noecho();
135
        keypad(stdscr, TRUE);
136
        raw();
137
 
138
        key = getch();
139
 
140
        switch(key)
141
        {
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;
152
 
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;
159
 
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;
166
 
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;
173
 
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;
193
        }
194
 
195
        if (quit == TRUE)
196
            break;
197
    }
198
 
199
    delwin(win);
200
    endwin();
201
 
202
    return 0;
203
}
204
 
205
void Continue(WINDOW *win)
206
{
207
    mvwaddstr(win, 10, 1, " Press any key to continue");
208
    wrefresh(win);
209
    raw();
210
    wgetch(win);
211
}
212
 
213
void Continue2(void)
214
{
215
    move(LINES - 1, 1);
216
    clrtoeol();
217
    mvaddstr(LINES - 2, 1, " Press any key to continue");
218
    refresh();
219
    raw();
220
    getch();
221
}
222
 
223
int initTest(WINDOW **win, int argc, char *argv[])
224
{
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 */
235
 
236
    width  = 60;
237
    height = 13;
238
 
239
    *win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2);
240
 
241
    if (*win == NULL)
242
    {
243
        endwin();
244
        return 1;
245
    }
246
 
247
    return 0;
248
}
249
 
250
void introTest(WINDOW *win)
251
{
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);
258
 
259
    beep();
260
    werase(win);
261
 
262
    box(win, ACS_VLINE, ACS_HLINE);
263
    wrefresh(win);
264
 
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);
270
 
271
    flash();
272
    mvwaddstr(win, 3, 1, "You should have seen a flash");
273
    Continue(win);
274
}
275
 
276
void scrollTest(WINDOW *win)
277
{
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);
288
 
289
    for (i = 1; i <= height; i++)
290
    {
291
        napms(150);
292
        scroll(win);
293
        wrefresh(win);
294
    };
295
 
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);
306
 
307
    for (i = 1; i <= 5; i++)
308
    {
309
        napms(500);
310
        scroll(win);
311
        wrefresh(win);
312
    }
313
 
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);
319
 
320
    for (i = 5; i <= OldY; i++)
321
    {
322
        napms(300);
323
        wscrl(win, -1);
324
        wrefresh(win);
325
    }
326
 
327
    wsetscrreg(win, 0, OldY);
328
}
329
 
330
void inputTest(WINDOW *win)
331
{
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;
337
 
338
    wclear(win);
339
 
340
    getmaxyx(win, h, w);
341
    getbegyx(win, by, bx);
342
 
343
    sw = w / 3;
344
    sh = h / 3;
345
 
346
    if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2))
347
        == NULL)
348
        return;
349
 
350
#ifdef A_COLOR
351
    if (has_colors())
352
    {
353
        init_pair(2, COLOR_WHITE, COLOR_RED);
354
        wbkgd(subWin, COLOR_PAIR(2) | A_BOLD);
355
    }
356
    else
357
#endif
358
        wbkgd(subWin, A_BOLD);
359
 
360
    box(subWin, ACS_VLINE, ACS_HLINE);
361
    wrefresh(win);
362
 
363
    nocbreak();
364
 
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);
370
 
371
    keypad(win, TRUE);
372
    raw();
373
    noecho();
374
 
375
    wtimeout(win, 200);
376
 
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 */
383
 
384
    while (1)
385
    {
386
        while (1)
387
        {
388
            c = wgetch(win);
389
 
390
            if (c == ERR)
391
            {
392
                spinner_count++;
393
                if (spinner_count == 4)
394
                    spinner_count = 0;
395
                mvwaddch(win, 3, 3, spinner[spinner_count]);
396
                wrefresh(win);
397
            }
398
            else
399
                break;
400
        }
401
#ifdef PDCURSES
402
        wmove(win, 4, 18);
403
        wclrtoeol(win);
404
#endif
405
        mvwaddstr(win, 3, 5, "Key Pressed: ");
406
        wclrtoeol(win);
407
 
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)
416
        {
417
            int button = 0;
418
            request_mouse_pos();
419
 
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;
426
 
427
            if (button && (BUTTON_STATUS(button) &
428
                BUTTON_MODIFIER_MASK))
429
            {
430
                waddstr(win, " Modifier(s):");
431
 
432
                if (BUTTON_STATUS(button) & BUTTON_SHIFT)
433
                    waddstr(win, " SHIFT");
434
 
435
                if (BUTTON_STATUS(button) & BUTTON_CONTROL)
436
                    waddstr(win, " CONTROL");
437
 
438
                if (BUTTON_STATUS(button) & BUTTON_ALT)
439
                    waddstr(win, " ALT");
440
            }
441
 
442
            wmove(win, 4, 18);
443
            wclrtoeol(win);
444
            wprintw(win, "Button %d: ", button);
445
 
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: ");
463
 
464
            wprintw(win, "Position: Y: %d X: %d", MOUSE_Y_POS, MOUSE_X_POS);
465
        }
466
        else if (PDC_get_key_modifiers())
467
        {
468
            waddstr(win, " Modifier(s):");
469
            if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_SHIFT)
470
                waddstr(win, " SHIFT");
471
 
472
            if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_CONTROL)
473
                waddstr(win, " CONTROL");
474
 
475
            if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_ALT)
476
                waddstr(win, " ALT");
477
 
478
            if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_NUMLOCK)
479
                waddstr(win, " NUMLOCK");
480
        }
481
#endif
482
        wrefresh(win);
483
 
484
        if (c == ' ')
485
            break;
486
    }
487
 
488
    wtimeout(win, -1);  /* turn off timeout() */
489
    curs_set(1);        /* turn cursor back on */
490
 
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);
500
 
501
    werase(subWin);
502
    box(subWin, ACS_VLINE, ACS_HLINE);
503
 
504
    for (i = 0; i < 5; i++)
505
    {
506
        mvwprintw(subWin, 1, 1, "Time = %d", i);
507
        wrefresh(subWin);
508
        napms(1000);
509
        flushinp();
510
    }
511
 
512
    delwin(subWin);
513
    werase(win);
514
    flash();
515
    wrefresh(win);
516
    napms(500);
517
    flushinp();
518
 
519
    mvwaddstr(win, 2, 1, "Press a key, followed by ENTER");
520
    wmove(win, 9, 10);
521
    wrefresh(win);
522
    echo();
523
 
524
    keypad(win, TRUE);
525
    raw();
526
    wgetnstr(win, buffer, 3);
527
    flushinp();
528
 
529
    wmove(win, 9, 10);
530
    wdelch(win);
531
    mvwaddstr(win, 4, 1, "The character should now have been deleted");
532
    Continue(win);
533
 
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);
547
 
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);
555
}
556
 
557
void outputTest(WINDOW *win)
558
{
559
    WINDOW *win1;
560
    char Buffer[80];
561
    chtype ch;
562
    int by, bx;
563
 
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);
571
 
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);
578
 
579
    getbegyx(win, by, bx);
580
 
581
    if (LINES < 24 || COLS < 75)
582
    {
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);
586
    }
587
    else
588
    {
589
        win1 = newwin(10, 50, 14, 25);
590
 
591
        if (win1 == NULL)
592
        {
593
            endwin();
594
            return;
595
        }
596
 
597
#ifdef A_COLOR
598
        if (has_colors())
599
        {
600
            init_pair(3, COLOR_BLUE, COLOR_WHITE);
601
            wbkgd(win1, COLOR_PAIR(3));
602
        }
603
        else
604
#endif
605
            wbkgd(win1, A_NORMAL);
606
 
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);
614
 
615
        wclear(win1);
616
 
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);
621
 
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);
628
 
629
        delwin(win1);
630
    }
631
 
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);
646
 
647
    wmove(win, 5, 9);
648
    ch = winch(win);
649
 
650
    wclear(win);
651
    wmove(win, 6, 2);
652
    waddstr(win, "The next char should be l:  ");
653
    winsch(win, ch);
654
    Continue(win);
655
 
656
    mvwinsstr(win, 6, 2, "A1B2C3D4E5");
657
    Continue(win);
658
 
659
    wmove(win, 5, 1);
660
    winsdelln(win, 1);
661
    mvwaddstr(win, 5, 2, "The lines below should have moved down");
662
    Continue(win);
663
 
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);
672
 
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);
676
 
677
    wclear(win);
678
    curs_set(2);
679
    mvwaddstr(win, 1, 1, "The cursor should be in high-visibility mode");
680
    Continue(win);
681
 
682
    wclear(win);
683
    curs_set(0);
684
    mvwaddstr(win, 1, 1, "The cursor should have disappeared");
685
    Continue(win);
686
 
687
    wclear(win);
688
    curs_set(1);
689
    mvwaddstr(win, 1, 1, "The cursor should be normal");
690
    Continue(win);
691
 
692
#ifdef A_COLOR
693
    if (has_colors())
694
    {
695
        wclear(win);
696
        mvwaddstr(win, 1, 1, "Colors should change after you press a key");
697
        Continue(win);
698
 
699
        init_pair(1, COLOR_RED, COLOR_WHITE);
700
        wrefresh(win);
701
    }
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());
707
 
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.");
712
 
713
    mvwaddnstr(win, 7, 5, "Have a nice day!ok", 16);
714
    wrefresh(win);
715
 
716
    mvwinnstr(win, 7, 5, Buffer, 18);
717
    mvaddstr(LINES - 2, 10, Buffer);
718
    refresh();
719
    Continue(win);
720
}
721
 
722
#if HAVE_RESIZE
723
void resizeTest(WINDOW *dummy)
724
{
725
    WINDOW *win1;
726
    int nwidth = 135, nheight = 52;
727
    int owidth = COLS, oheight = LINES;
728
 
729
    savetty();
730
 
731
    resize_term(nheight, nwidth);
732
 
733
    clear();
734
    refresh();
735
 
736
    win1 = newwin(10, 50, 14, 25);
737
 
738
    if (win1 == NULL)
739
    {
740
        endwin();
741
        return;
742
    }
743
 
744
#ifdef A_COLOR
745
    if (has_colors())
746
    {
747
        init_pair(3, COLOR_BLUE, COLOR_WHITE);
748
        wattrset(win1, COLOR_PAIR(3));
749
    }
750
 
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);
757
 
758
    wclear(win1);
759
    resetty();
760
 
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);
765
 
766
    delwin(win1);
767
 
768
    clear();
769
    refresh();
770
}
771
#endif /* HAVE_RESIZE */
772
 
773
void padTest(WINDOW *dummy)
774
{
775
    WINDOW *pad, *spad;
776
 
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);
791
 
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);
799
 
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);
806
 
807
    delwin(pad);
808
}
809
 
810
#if HAVE_CLIPBOARD
811
void clipboardTest(WINDOW *win)
812
{
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;
817
 
818
    mvaddstr(1, 1,
819
             "This test will display the contents of the system clipboard");
820
 
821
    Continue2();
822
 
823
    scrollok(stdscr, TRUE);
824
    i = PDC_getclipboard(&ptr, &length);
825
 
826
    switch(i)
827
    {
828
    case PDC_CLIP_ACCESS_ERROR:
829
        mvaddstr(3, 1, "There was an error accessing the clipboard");
830
        refresh();
831
        break;
832
 
833
    case PDC_CLIP_MEMORY_ERROR:
834
        mvaddstr(3, 1,
835
            "Unable to allocate memory for clipboard contents");
836
        break;
837
 
838
    case PDC_CLIP_EMPTY:
839
        mvaddstr(3, 1, "There was no text in the clipboard");
840
        break;
841
 
842
    default:
843
        wsetscrreg(stdscr, 0, LINES - 1);
844
        clear();
845
        mvaddstr(1, 1, "Clipboard contents...");
846
        mvprintw(2, 1, "%s\n", ptr);
847
    }
848
 
849
    Continue2();
850
 
851
    clear();
852
    mvaddstr(1, 1,
853
        "This test will place the following string in the system clipboard:");
854
    mvaddstr(2, 1, text);
855
 
856
    i = PDC_setclipboard(text, strlen(text));
857
 
858
    switch(i)
859
    {
860
    case PDC_CLIP_ACCESS_ERROR:
861
        mvaddstr(3, 1, "There was an error accessing the clipboard");
862
        break;
863
 
864
    case PDC_CLIP_MEMORY_ERROR:
865
        mvaddstr(3, 1, "Unable to allocate memory for clipboard contents");
866
        break;
867
 
868
    default:
869
        mvaddstr(3, 1, "The string was placed in the clipboard successfully");
870
    }
871
 
872
    Continue2();
873
}
874
#endif /* HAVE_CLIPBOARD */
875
 
876
void acsTest(WINDOW *win)
877
{
878
#ifdef ACS_S3
879
# define ACSNUM 32
880
#else
881
# define ACSNUM 25
882
#endif
883
    static const char *acs_names[] =
884
    {
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",
888
 
889
        "ACS_S1", "ACS_S9", "ACS_DIAMOND", "ACS_CKBOARD", "ACS_DEGREE",
890
        "ACS_PLMINUS", "ACS_BULLET",
891
 
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
898
    };
899
 
900
    chtype acs_values[ACSNUM];
901
 
902
#if HAVE_WIDE
903
    cchar_t *wacs_values[] =
904
    {
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,
908
 
909
        WACS_S1, WACS_S9, WACS_DIAMOND, WACS_CKBOARD, WACS_DEGREE,
910
        WACS_PLMINUS, WACS_BULLET,
911
 
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
918
    };
919
 
920
    static const wchar_t russian[] = {0x0420, 0x0443, 0x0441, 0x0441,
921
        0x043a, 0x0438, 0x0439, L' ', 0x044f, 0x0437, 0x044b, 0x043a, 0};
922
 
923
    static const wchar_t greek[] = {0x0395, 0x03bb, 0x03bb, 0x03b7,
924
        0x03bd, 0x03b9, 0x03ba, 0x03ac, 0};
925
 
926
    static const wchar_t georgian[] = {0x10e5, 0x10d0, 0x10e0, 0x10d7,
927
        0x10e3, 0x10da, 0x10d8, L' ', 0x10d4, 0x10dc, 0x10d0, 0};
928
#endif
929
 
930
    int i, tmarg = (LINES - 22) / 2;
931
 
932
    attrset(A_BOLD);
933
    mvaddstr(tmarg, (COLS - 23) / 2, "Alternate Character Set");
934
    attrset(A_NORMAL);
935
 
936
    tmarg += 3;
937
 
938
#define A(b,c) acs_values[b] = ACS_##c
939
 
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);
944
 
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
952
 
953
#undef A
954
 
955
    for (i = 0; i < ACSNUM; i++)
956
    {
957
        move((i % 8) * 2 + tmarg, (i / 8) * (COLS / 4) + (COLS / 8 - 7));
958
        addch(acs_values[i]);
959
        printw(" %s", acs_names[i]);
960
    }
961
 
962
    mvaddstr(tmarg + 18, 3, "Press any key to continue");
963
    getch();
964
 
965
#if HAVE_WIDE
966
    clear();
967
 
968
    attrset(A_BOLD);
969
    mvaddstr(tmarg - 3, (COLS - 28) / 2, "Wide Alternate Character Set");
970
    attrset(A_NORMAL);
971
 
972
    for (i = 0; i < ACSNUM; i++)
973
    {
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]);
977
    }
978
 
979
    /* Spanish, Russian, Greek, Georgian */
980
 
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);
985
 
986
    mvaddstr(tmarg + 18, 3, "Press any key to continue");
987
    getch();
988
#endif
989
}
990
 
991
#if HAVE_COLOR
992
void colorTest(WINDOW *win)
993
{
994
    static const short colors[] =
995
    {
996
        COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_BLUE,
997
        COLOR_CYAN, COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE
998
    };
999
 
1000
    static const char *colornames[] =
1001
    {
1002
        "COLOR_BLACK", "COLOR_RED", "COLOR_GREEN", "COLOR_BLUE",
1003
        "COLOR_CYAN", "COLOR_MAGENTA", "COLOR_YELLOW", "COLOR_WHITE"
1004
    };
1005
 
1006
    chtype fill = ACS_BLOCK;
1007
 
1008
    int i, j, tmarg, col1, col2, col3;
1009
 
1010
    if (!has_colors())
1011
        return;
1012
 
1013
    tmarg = (LINES - 19) / 2;
1014
    col1 = (COLS - 60) / 2;
1015
    col2 = col1 + 20;
1016
    col3 = col2 + 20;
1017
 
1018
    attrset(A_BOLD);
1019
    mvaddstr(tmarg, (COLS - 22) / 2, "Color Attribute Macros");
1020
    attrset(A_NORMAL);
1021
 
1022
    mvaddstr(tmarg + 3, col2 + 4, "A_NORMAL");
1023
    mvaddstr(tmarg + 3, col3 + 5, "A_BOLD");
1024
 
1025
    for (i = 0; i < 8; i++)
1026
    {
1027
        init_pair(i + 4, colors[i], COLOR_BLACK);
1028
 
1029
        mvaddstr(tmarg + i + 5, col1, colornames[i]);
1030
 
1031
        for (j = 0; j < 16; j++)
1032
        {
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);
1035
        }
1036
    }
1037
 
1038
    mvprintw(tmarg + 15, col1, "COLORS = %d", COLORS);
1039
    mvprintw(tmarg + 16, col1, "COLOR_PAIRS = %d", COLOR_PAIRS);
1040
 
1041
    mvaddstr(tmarg + 19, 3, "Press any key to continue");
1042
    getch();
1043
 
1044
    if (can_change_color())
1045
    {
1046
        struct
1047
        {
1048
            short red, green, blue;
1049
        } orgcolors[16];
1050
 
1051
        int MAXCOL = (COLORS >= 16) ? 16 : 8;
1052
 
1053
        if (MAXCOL < 8)
1054
            return;
1055
 
1056
        for (i = 0; i < MAXCOL; i++)
1057
            color_content(i, &(orgcolors[i].red),
1058
                             &(orgcolors[i].green),
1059
                             &(orgcolors[i].blue));
1060
 
1061
        attrset(A_BOLD);
1062
        mvaddstr(tmarg, (COLS - 22) / 2, " init_color() Example ");
1063
        attrset(A_NORMAL);
1064
 
1065
        refresh();
1066
 
1067
        for (i = 0; i < 8; i++)
1068
        {
1069
            init_color(colors[i], i * 125, 0, i * 125);
1070
 
1071
            if (MAXCOL == 16)
1072
                init_color(colors[i] + 8, 0, i * 125, 0);
1073
        }
1074
 
1075
        mvaddstr(tmarg + 19, 3, "Press any key to continue");
1076
        getch();
1077
 
1078
        for (i = 0; i < MAXCOL; i++)
1079
            init_color(i, orgcolors[i].red,
1080
                          orgcolors[i].green,
1081
                          orgcolors[i].blue);
1082
    }
1083
}
1084
#endif
1085
 
1086
#if HAVE_WIDE
1087
void wideTest(WINDOW *win)
1088
{
1089
    wchar_t tmp[513];
1090
    size_t i;
1091
 
1092
    attrset(A_BOLD);
1093
    mvaddstr(1, (COLS - 25) / 2, "Wide Character Input Test");
1094
    attrset(A_NORMAL);
1095
 
1096
    mvaddstr(4, 1, "Enter a string: ");
1097
 
1098
    echo();
1099
 
1100
    get_wstr((wint_t *)tmp);
1101
    addstr("\n\n String:\n\n ");
1102
    addwstr(tmp);
1103
    addstr("\n\n\n Hex:\n\n ");
1104
 
1105
    for (i = 0; i < wcslen(tmp); i++)
1106
    {
1107
        printw("%04x ", tmp[i]);
1108
        addnwstr(tmp + i, 1);
1109
        addstr("  ");
1110
    }
1111
 
1112
    noecho();
1113
 
1114
    Continue2();
1115
}
1116
#endif
1117
 
1118
void display_menu(int old_option, int new_option)
1119
{
1120
    int lmarg = (COLS - 14) / 2,
1121
        tmarg = (LINES - (MAX_OPTIONS + 2)) / 2;
1122
 
1123
    if (old_option == -1)
1124
    {
1125
        int i;
1126
 
1127
        attrset(A_BOLD);
1128
        mvaddstr(tmarg - 3, lmarg - 5, "PDCurses Test Program");
1129
        attrset(A_NORMAL);
1130
 
1131
        for (i = 0; i < MAX_OPTIONS; i++)
1132
            mvaddstr(tmarg + i, lmarg, command[i].text);
1133
    }
1134
    else
1135
        mvaddstr(tmarg + old_option, lmarg, command[old_option].text);
1136
 
1137
    attrset(A_REVERSE);
1138
    mvaddstr(tmarg + new_option, lmarg, command[new_option].text);
1139
    attrset(A_NORMAL);
1140
 
1141
    mvaddstr(tmarg + MAX_OPTIONS + 2, lmarg - 23,
1142
             "Use Up and Down Arrows to select - Enter to run - Q to quit");
1143
    refresh();
1144
}

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.