X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fsavescreen.c;h=01bfe06b687752012c833a521b5ce24dba723f4b;hp=3bdf87108567fca3f617b9115fc960dad1464a6d;hb=fe6abf09238512f5a902bc1aeab2263d1e997396;hpb=87f20fc6e737084b06b6343c8c7206404daec4a2 diff --git a/test/savescreen.c b/test/savescreen.c index 3bdf8710..01bfe06b 100644 --- a/test/savescreen.c +++ b/test/savescreen.c @@ -26,7 +26,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: savescreen.c,v 1.23 2015/03/21 21:35:00 tom Exp $ + * $Id: savescreen.c,v 1.27 2015/03/28 23:21:28 tom Exp $ * * Demonstrate save/restore functions from the curses library. * Thomas Dickey - 2007/7/14 @@ -211,9 +211,10 @@ usage(void) "Usage: savescreen [-r] files", "", "Options:", - " -i use scr_init/scr_restore rather than scr_set", - " -k keep the restored dump-files rather than removing them", - " -r replay the screen-dump files" + " -f file fill/initialize screen using text from this file", + " -i use scr_init/scr_restore rather than scr_set", + " -k keep the restored dump-files rather than removing them", + " -r replay the screen-dump files" }; unsigned n; for (n = 0; n < SIZEOF(msg); ++n) { @@ -231,11 +232,19 @@ main(int argc, char *argv[]) bool replaying = FALSE; bool done = FALSE; char **files; + char *fill_by = 0; +#if USE_WIDEC_SUPPORT + cchar_t mycc; + int myxx; +#endif setlocale(LC_ALL, ""); - while ((ch = getopt(argc, argv, "ikr")) != -1) { + while ((ch = getopt(argc, argv, "f:ikr")) != -1) { switch (ch) { + case 'f': + fill_by = optarg; + break; case 'i': use_init = TRUE; break; @@ -281,6 +290,31 @@ main(int argc, char *argv[]) } } + if (fill_by != 0) { + FILE *fp = fopen(fill_by, "r"); + if (fp != 0) { + bool filled = FALSE; + move(1, 0); + while ((ch = fgetc(fp)) != EOF) { + if (addch(UChar(ch)) == ERR) { + filled = TRUE; + break; + } + } + fclose(fp); + if (!filled) { + while (addch(' ') != ERR) { + ; + } + } + move(0, 0); + } else { + endwin(); + fprintf(stderr, "Cannot open \"%s\"\n", fill_by); + ExitProgram(EXIT_FAILURE); + } + } + if (replaying) { /* @@ -385,7 +419,17 @@ main(int argc, char *argv[]) for (cx = 0; cx < COLS; ++cx) { wmove(curscr, cy, cx); wmove(stdscr, cy, cx); +#if USE_WIDEC_SUPPORT + if (win_wch(curscr, &mycc) != ERR) { + myxx = wcwidth(mycc.chars[0]); + if (myxx > 0) { + wadd_wchnstr(stdscr, &mycc, 1); + cx += (myxx - 1); + } + } +#else waddch(stdscr, winch(curscr)); +#endif } } }