X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fdots_curses.c;fp=test%2Fdots_curses.c;h=b0adfe186e9e3b92cfc92dfb27f5ba43149e85b4;hp=477c4a14ef116b60854324901ce83b86c725d7be;hb=58369d647d003dd9d9e1ecfc5ab07982db28f3da;hpb=7fa7badf32c514211478cf9f79c70f20d435c2f2 diff --git a/test/dots_curses.c b/test/dots_curses.c index 477c4a14..b0adfe18 100644 --- a/test/dots_curses.c +++ b/test/dots_curses.c @@ -29,7 +29,7 @@ /* * Author: Thomas E. Dickey * - * $Id: dots_curses.c,v 1.7 2017/10/11 08:16:33 tom Exp $ + * $Id: dots_curses.c,v 1.9 2017/10/22 00:44:39 tom Exp $ * * A simple demo of the curses interface used for comparison with termcap. */ @@ -84,20 +84,77 @@ set_colors(int fg, int bg) } } +static void +usage(void) +{ + static const char *msg[] = + { + "Usage: dots_curses [options]" + ,"" + ,"Options:" + ," -T TERM override $TERM" +#if HAVE_USE_DEFAULT_COLORS + ," -d invoke use_default_colors()" +#endif + ," -e allow environment $LINES / $COLUMNS" + ," -m SIZE set margin (default: 2)" + ," -s MSECS delay 1% of the time (default: 1 msecs)" + }; + size_t n; + + for (n = 0; n < SIZEOF(msg); n++) + fprintf(stderr, "%s\n", msg[n]); + + ExitProgram(EXIT_FAILURE); +} + int -main(int argc GCC_UNUSED, - char *argv[]GCC_UNUSED) +main(int argc, char *argv[]) { int x, y, z, p; int fg, bg; double r; double c; +#if HAVE_USE_DEFAULT_COLORS + bool d_option = FALSE; +#endif + int m_option = 2; + int s_option = 1; + + while ((x = getopt(argc, argv, "T:dem:s:")) != -1) { + switch (x) { + case 'T': + putenv(strcat(strcpy(malloc(6 + strlen(optarg)), "TERM="), optarg)); + break; +#if HAVE_USE_DEFAULT_COLORS + case 'd': + d_option = TRUE; + break; +#endif + case 'e': + use_env(TRUE); + break; + case 'm': + m_option = atoi(optarg); + break; + case 's': + s_option = atoi(optarg); + break; + default: + usage(); + break; + } + } srand((unsigned) time(0)); InitAndCatch(initscr(), onsig); if (has_colors()) { start_color(); +#if HAVE_USE_DEFAULT_COLORS + if (d_option) + use_default_colors(); +#endif for (fg = 0; fg < COLORS; fg++) { for (bg = 0; bg < COLORS; bg++) { int pair = mypair(fg, bg); @@ -107,15 +164,15 @@ main(int argc GCC_UNUSED, } } - r = (double) (LINES - 4); - c = (double) (COLS - 4); + r = (double) (LINES - (m_option * 2)); + c = (double) (COLS - (m_option * 2)); started = time((time_t *) 0); fg = COLOR_WHITE; bg = COLOR_BLACK; while (!interrupted) { - x = (int) (c * ranf()) + 2; - y = (int) (r * ranf()) + 2; + x = (int) (c * ranf()) + m_option; + y = (int) (r * ranf()) + m_option; p = (ranf() > 0.9) ? '*' : ' '; move(y, x); @@ -126,7 +183,7 @@ main(int argc GCC_UNUSED, attron(COLOR_PAIR(mypair(fg, bg))); } else { set_colors(fg, bg = z); - napms(1); + napms(s_option); } } else { if (ranf() <= 0.01) { @@ -135,7 +192,7 @@ main(int argc GCC_UNUSED, } else { attroff(A_REVERSE); } - napms(1); + napms(s_option); } } AddCh(p);