]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/ncurses.c
ncurses 5.7 - patch 20090801
[ncurses.git] / test / ncurses.c
index c879d2c826ce8d5425009a80ce20c01a708aac91..70b0d86af28395b382730b42b89d7cd9fb146571 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -40,7 +40,7 @@ AUTHOR
    Author: Eric S. Raymond <esr@snark.thyrsus.com> 1993
            Thomas E. Dickey (beginning revision 1.27 in 1996).
 
-$Id: ncurses.c,v 1.334 2008/12/20 17:13:27 tom Exp $
+$Id: ncurses.c,v 1.343 2009/07/30 09:13:37 tom Exp $
 
 ***************************************************************************/
 
@@ -318,6 +318,7 @@ make_narrow_text(wchar_t *target, const char *source)
     *target = 0;
 }
 
+#if USE_LIBPANEL
 static void
 make_fullwidth_digit(cchar_t *target, int digit)
 {
@@ -327,6 +328,7 @@ make_fullwidth_digit(cchar_t *target, int digit)
     source[1] = 0;
     setcchar(target, source, A_NORMAL, 0, 0);
 }
+#endif
 
 static int
 wGet_wchar(WINDOW *win, wint_t *result)
@@ -483,7 +485,11 @@ ShellOut(bool message)
        addstr("Shelling out...");
     def_prog_mode();
     endwin();
+#ifdef __MINGW32__
+    system("cmd.exe");
+#else
     system("sh");
+#endif
     if (message)
        addstr("returned from shellout.\n");
     refresh();
@@ -670,7 +676,7 @@ remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
 {
     unsigned need = (level + 1) * 2;
 
-    assert(level < COLS);
+    assert(level < (unsigned) COLS);
 
     if (winstack == 0) {
        len_winstack = 20;
@@ -924,6 +930,7 @@ getch_test(void)
     wgetch_test(0, stdscr, delay);
     forget_boxes();
     finish_getch_test();
+    slk_clear();
 }
 
 #if USE_WIDEC_SUPPORT
@@ -1141,6 +1148,7 @@ get_wch_test(void)
     wget_wch_test(0, stdscr, delay);
     forget_boxes();
     finish_getch_test();
+    slk_clear();
 }
 #endif
 
@@ -1859,6 +1867,8 @@ show_color_name(int y, int x, int color, bool wide)
            width = 4;
        } else if (color >= 8) {
            sprintf(temp, "[%02d]", color);
+       } else if (color < 0) {
+           strcpy(temp, "default");
        } else {
            strcpy(temp, the_color_names[color]);
        }
@@ -1892,6 +1902,8 @@ color_legend(WINDOW *helpwin, bool wide)
              "  b/B     toggle bold off/on");
     mvwprintw(helpwin, row++, col,
              "  n/N     toggle text/number on/off");
+    mvwprintw(helpwin, row++, col,
+             "  r/R     toggle reverse on/off");
     mvwprintw(helpwin, row++, col,
              "  w/W     toggle width between 8/16 colors");
 #if USE_WIDEC_SUPPORT
@@ -1925,12 +1937,19 @@ color_test(void)
     bool done = FALSE;
     bool opt_acsc = FALSE;
     bool opt_bold = FALSE;
-    bool opt_wide = FALSE;
+    bool opt_revs = FALSE;
     bool opt_nums = FALSE;
+    bool opt_wide = FALSE;
     WINDOW *helpwin;
 
-    if (pairs_max > COLOR_PAIRS)
-       pairs_max = COLOR_PAIRS;
+    if (COLORS * COLORS == COLOR_PAIRS) {
+       int limit = (COLORS - min_colors) * (COLORS - min_colors);
+       if (pairs_max > limit)
+           pairs_max = limit;
+    } else {
+       if (pairs_max > COLOR_PAIRS)
+           pairs_max = COLOR_PAIRS;
+    }
 
     while (!done) {
        int shown = 0;
@@ -1945,12 +1964,14 @@ color_test(void)
            hello = "Hello";
            per_row = 8;
        }
+       per_row -= min_colors;
 
        row_limit = (pairs_max + per_row - 1) / per_row;
 
        move(0, 0);
-       (void) printw("There are %d color pairs and %d colors\n",
-                     pairs_max, COLORS);
+       (void) printw("There are %d color pairs and %d colors%s\n",
+                     pairs_max, COLORS,
+                     min_colors ? " besides 'default'" : "");
 
        clrtobot();
        (void) mvprintw(top + 1, 0,
@@ -1961,7 +1982,7 @@ color_test(void)
 
        /* show color names/numbers across the top */
        for (i = 0; i < per_row; i++)
-           show_color_name(top + 2, (i + 1) * width, i, opt_wide);
+           show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
 
        /* show a grid of colors, with color names/ numbers on the left */
        for (i = (short) (base_row * per_row); i < pairs_max; i++) {
@@ -1969,9 +1990,11 @@ color_test(void)
            int col = (i % per_row + 1) * width;
            short pair = i;
 
+#define InxToFG(i) (short) ((i % (COLORS - min_colors)) + min_colors)
+#define InxToBG(i) (short) ((i / (COLORS - min_colors)) + min_colors)
            if (row >= 0 && move(row, col) != ERR) {
-               short fg = (short) (i % COLORS);
-               short bg = (short) (i / COLORS);
+               short fg = InxToFG(i);
+               short bg = InxToBG(i);
 
                init_pair(pair, fg, bg);
                attron((attr_t) COLOR_PAIR(pair));
@@ -1979,6 +2002,8 @@ color_test(void)
                    attron((attr_t) A_ALTCHARSET);
                if (opt_bold)
                    attron((attr_t) A_BOLD);
+               if (opt_revs)
+                   attron((attr_t) A_REVERSE);
 
                if (opt_nums) {
                    sprintf(numbered, "{%02X}", i);
@@ -1987,8 +2012,8 @@ color_test(void)
                printw("%-*.*s", width, width, hello);
                attrset(A_NORMAL);
 
-               if ((i % per_row) == 0 && (i % COLORS) == 0) {
-                   show_color_name(row, 0, i / COLORS, opt_wide);
+               if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
+                   show_color_name(row, 0, InxToBG(i), opt_wide);
                }
                ++shown;
            } else if (shown) {
@@ -2015,6 +2040,12 @@ color_test(void)
        case 'N':
            opt_nums = TRUE;
            break;
+       case 'r':
+           opt_revs = FALSE;
+           break;
+       case 'R':
+           opt_revs = TRUE;
+           break;
        case case_QUIT:
            done = TRUE;
            continue;
@@ -2092,7 +2123,7 @@ wide_color_test(void)
     int base_row = 0;
     int grid_top = top + 3;
     int page_size = (LINES - grid_top);
-    int pairs_max = COLOR_PAIRS;
+    int pairs_max = (unsigned short) (-1);
     int row_limit;
     int per_row;
     char numbered[80];
@@ -2100,12 +2131,22 @@ wide_color_test(void)
     bool done = FALSE;
     bool opt_acsc = FALSE;
     bool opt_bold = FALSE;
+    bool opt_revs = FALSE;
     bool opt_wide = FALSE;
     bool opt_nums = FALSE;
     bool opt_xchr = FALSE;
     wchar_t buffer[10];
     WINDOW *helpwin;
 
+    if (COLORS * COLORS == COLOR_PAIRS) {
+       int limit = (COLORS - min_colors) * (COLORS - min_colors);
+       if (pairs_max > limit)
+           pairs_max = limit;
+    } else {
+       if (pairs_max > COLOR_PAIRS)
+           pairs_max = COLOR_PAIRS;
+    }
+
     while (!done) {
        int shown = 0;
 
@@ -2119,6 +2160,8 @@ wide_color_test(void)
            hello = "Hello";
            per_row = 8;
        }
+       per_row -= min_colors;
+
        if (opt_xchr) {
            make_fullwidth_text(buffer, hello);
            width *= 2;
@@ -2130,8 +2173,9 @@ wide_color_test(void)
        row_limit = (pairs_max + per_row - 1) / per_row;
 
        move(0, 0);
-       (void) printw("There are %d color pairs and %d colors\n",
-                     pairs_max, COLORS);
+       (void) printw("There are %d color pairs and %d colors%s\n",
+                     pairs_max, COLORS,
+                     min_colors ? " besides 'default'" : "");
 
        clrtobot();
        (void) mvprintw(top + 1, 0,
@@ -2142,7 +2186,7 @@ wide_color_test(void)
 
        /* show color names/numbers across the top */
        for (i = 0; i < per_row; i++)
-           show_color_name(top + 2, (i + 1) * width, i, opt_wide);
+           show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
 
        /* show a grid of colors, with color names/ numbers on the left */
        for (i = (base_row * per_row); i < pairs_max; i++) {
@@ -2151,12 +2195,14 @@ wide_color_test(void)
            short pair = (short) i;
 
            if (row >= 0 && move(row, col) != ERR) {
-               init_pair(pair, (short) (i % COLORS), (short) (i / COLORS));
+               init_pair(pair, InxToFG(i), InxToBG(i));
                color_set(pair, NULL);
                if (opt_acsc)
                    attr_on((attr_t) A_ALTCHARSET, NULL);
                if (opt_bold)
                    attr_on((attr_t) A_BOLD, NULL);
+               if (opt_revs)
+                   attr_on((attr_t) A_REVERSE, NULL);
 
                if (opt_nums) {
                    sprintf(numbered, "{%02X}", i);
@@ -2169,8 +2215,8 @@ wide_color_test(void)
                addnwstr(buffer, width);
                attr_set(A_NORMAL, 0, NULL);
 
-               if ((i % per_row) == 0 && (i % COLORS) == 0) {
-                   show_color_name(row, 0, i / COLORS, opt_wide);
+               if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
+                   show_color_name(row, 0, InxToBG(i), opt_wide);
                }
                ++shown;
            } else if (shown) {
@@ -2197,6 +2243,12 @@ wide_color_test(void)
        case 'N':
            opt_nums = TRUE;
            break;
+       case 'r':
+           opt_revs = FALSE;
+           break;
+       case 'R':
+           opt_revs = TRUE;
+           break;
        case case_QUIT:
            done = TRUE;
            continue;
@@ -2838,7 +2890,7 @@ cycle_attr(int ch, unsigned *at_code, chtype *attr)
            *at_code = 0;
        break;
     case 'V':
-       if (*at_code == 1)
+       if (*at_code == 0)
            *at_code = SIZEOF(attrs_to_cycle) - 1;
        else
            *at_code -= 1;
@@ -3189,21 +3241,18 @@ acs_display(void)
 static cchar_t *
 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, short pair)
 {
-    int count = getcchar(src, NULL, NULL, NULL, 0);
-    wchar_t *wch = 0;
-    attr_t ignore_attr;
-    short ignore_pair;
+    int count;
 
     *dst = *src;
-    if (count > 0) {
-       if ((wch = typeMalloc(wchar_t, (unsigned) count + 1)) != 0) {
-           if (getcchar(src, wch, &ignore_attr, &ignore_pair, 0) != ERR) {
-               attr |= (ignore_attr & A_ALTCHARSET);
-               setcchar(dst, wch, attr, pair, 0);
-           }
-           free(wch);
+    do {
+       TEST_CCHAR(src, count, {
+           attr |= (test_attrs & A_ALTCHARSET);
+           setcchar(dst, test_wch, attr, pair, NULL);
        }
-    }
+       , {
+           ;
+       });
+    } while (0);
     return dst;
 }
 
@@ -3240,7 +3289,7 @@ show_upper_widechars(int first, int repeat, int space, attr_t attr, short pair)
             * the display.
             */
            if (wcwidth(code) == 0)
-               addch(space | A_REVERSE);
+               addch(space | (A_REVERSE ^ attr) | COLOR_PAIR(pair));
            /*
             * This could use add_wch(), but is done for comparison with the
             * normal 'f' test (and to make a test-case for echo_wchar()).