* authorization. *
****************************************************************************/
/*
- * $Id: savescreen.c,v 1.21 2015/03/07 21:55:35 tom Exp $
+ * $Id: savescreen.c,v 1.28 2015/08/22 22:40:22 tom Exp $
*
* Demonstrate save/restore functions from the curses library.
* Thomas Dickey - 2007/7/14
#endif
static bool use_init = FALSE;
+static bool keep_dumps = FALSE;
static int
fexists(const char *name)
{
int n;
- for (n = 0; files[n] != 0; ++n) {
- unlink(files[n]);
+ if (!keep_dumps) {
+ for (n = 0; files[n] != 0; ++n) {
+ unlink(files[n]);
+ }
}
}
"Usage: savescreen [-r] files",
"",
"Options:",
- " -i use scr_init/scr_restore rather than scr_set",
- " -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) {
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, "ir")) != -1) {
+ while ((ch = getopt(argc, argv, "f:ikr")) != -1) {
switch (ch) {
+ case 'f':
+ fill_by = optarg;
+ break;
case 'i':
use_init = TRUE;
break;
+ case 'k':
+ keep_dumps = TRUE;
+ break;
case 'r':
replaying = TRUE;
break;
*/
for (pair = 0; pair < COLOR_PAIRS; ++pair) {
color = (short) (pair % (COLORS - 1));
- init_pair(pair, COLOR_WHITE - color, color);
+ init_pair(pair, (short) (COLOR_WHITE - color), color);
+ }
+ }
+
+ 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);
}
}
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
}
}
}
continue;
}
if (!done) {
- attr_t attr = (A_REVERSE | COLOR_PAIR(color * COLORS));
+ attr_t attr = (A_REVERSE | (attr_t) COLOR_PAIR(color * COLORS));
chtype ch2 = (altchars ? ACS_DIAMOND : '#');
move(y, x);
addch(ch2 | attr);